Subversion Repositories DevTools

Rev

Rev 2071 | Rev 2319 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : cc2svn_importpackage.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Get package information for a package name specified on the
10
#                 command line.
11
#
12
#                 Determine the package id
13
#                 Locate all packages that have the same package name
14
#                 Determine essential packages
15
#                 Prune uneeded packages
16
#
17
#                 Pump it into SVN
18
#
19
#                 Project Based Pumping, creating branches as needed
20
#
21
#......................................................................#
22
 
23
require 5.006_001;
24
use strict;
25
use warnings;
26
use JatsError;
27
use JatsRmApi;
28
use FileUtils;
29
use JatsSystem;
30
use HTTP::Date;
31
use JatsProperties;
32
use JatsEnv;
33
use ConfigurationFile;
34
use JatsSvn qw(:All);
1197 dpurdie 35
use JatsLocateFiles;
392 dpurdie 36
 
37
 
38
#use Data::Dumper;
39
use Fcntl ':flock'; # import LOCK_* constants
40
use Cwd;
41
use DBI;
42
use Getopt::Long;
43
use Pod::Usage;                             # required for help support
1342 dpurdie 44
use Encode;
392 dpurdie 45
 
46
#
47
#   Options
48
#
49
my $opt_help = 0;
50
my $opt_manual = 0;
51
my $opt_verbose = 0;
52
my $opt_repo_base = 'AUPERASVN01/';
53
my $opt_repo = '';
54
my $opt_flat;
55
my $opt_test;
56
my $opt_reuse;
57
my $opt_age;
58
my $opt_dump = 0;
59
my $opt_images = 0;
60
my $opt_retaincount = 2;
61
my $opt_pruneModeString;
62
my $opt_listTags;
63
my $opt_name;
64
my $opt_log = 0;
65
my @opt_tip;
66
my $opt_postimage = 1;
67
my $opt_workDir = '/work';
68
my $opt_vobMap;
1197 dpurdie 69
my $opt_preserveProjectBase;
70
my $opt_ignoreProjectBaseErrors;
1270 dpurdie 71
my $opt_delete;
1272 dpurdie 72
my $opt_recentAge = 14;             # Days
392 dpurdie 73
 
74
################################################################################
75
#   List of Projects Suffixes and Branch Names to be used within SVN
76
#
77
#       Name        - Name of branch for the project
78
#       Trunk       - Can be a trunk project
79
#                     First one seen will be placed on the trunk
80
#                     Others will create project branches
81
#
82
my $ProjectTrunk;
83
my %ProjectsBaseCreated;
84
my %Projects = (
85
    '.sea'      => { Name => 'Seattle' },
86
    '.coct'     => { Name => 'CapeTown' },
87
    '.sls'      => { Name => 'Stockholm' },
88
    '.syd'      => { Name => 'Sydney' },
89
    '.vtk'      => { Name => 'Vasttrafik' },
90
    '.bei'      => { Name => 'Beijing' },
91
    '.bkk'      => { Name => 'Bangkok' },
92
    '.ndl'      => { Name => 'NewDelhi' },
93
    '.nzs'      => { Name => 'NewZealandStageCoach' },
94
    '.wdc'      => { Name => 'Washington' },
95
    '.oso'      => { Name => 'Oslo' },
96
    '.lvs'      => { Name => 'LasVegas' },
97
    '.mlc'      => { Name => 'BeijingMlc' },
98
    '.sfo'      => { Name => 'SanFrancisco' },
99
    '.sg'       => { Name => 'Singapore' },
100
    '.gmp'      => { Name => 'GmpteProject' },
101
    '.ssw'      => { Name => 'UkStageCoach' },
102
    '.uk'       => { Name => 'UkProject' },
103
    '.pmb'      => { Name => 'Pietermaritzburg' },
104
    '.vps'      => { Name => 'VixPayments' },
105
    '.ncc'      => { Name => 'NSWClubCard' },
106
    '.rm'       => { Name => 'Rome' },
107
    'unknown'   => { Name => 'UnknownProject' },
108
 
109
    '.ebr'      => { Name => 'eBrio' , Trunk => 1 },
110
    '.mas'      => { Name => 'Mass'  , Trunk => 1 },
111
    '.cr'       => { Name => 'Core'  , Trunk => 1 },
112
    '.cots'     => { Name => 'Cots'  , Trunk => 1 },
113
    '.tool'     => { Name => 'Tools' , Trunk => 1 },
114
);
115
 
116
my %suffixFixup = (
117
    '.sf'           => '.sfo',
118
    '.vt'           => '.vtk',
119
    '.lv'           => '.lvs',
120
    '.was'          => '.wdc',
121
    '.uk.1'         => '.uk',
122
    '.ssts.demo'    => '.ssts',
123
    '.u244.syd'     => '.syd',
124
    '.pxxx.sea'     => '.sea',
125
    '.pxxx.syd'     => '.syd',
126
    '.pxxx.sydddd'  => '.syd',
127
    '.oslo'         => '.oso',
1272 dpurdie 128
    '.osl'          => '.oso',
392 dpurdie 129
);
130
 
131
my %specialPackages = (
404 dpurdie 132
    'core_devl' =>  ',all,protected,',
1197 dpurdie 133
#    'core_devl' =>  ',all,',
392 dpurdie 134
    'daf_utils_mos' => ',flat,',
135
    'mos_packager'  => ',all,',
395 dpurdie 136
 
137
    # Need to be handled in a special manner
138
    # Not done by this utility
139
    #
140
    'linux_drivers_eb5600'  => ',protected,',
141
    'linux_drivers_viper'   => ',protected,',
142
    'linux_drivers_cobra'   => ',protected,',
143
    'linux_drivers_bcp4600' => ',protected,',
144
    'linux_drivers_etx86'   => ',protected,',
145
    'linux_drivers_tp5600'  => ',protected,',
146
 
2016 dpurdie 147
# Not in the ukHops migration at the moment
148
    'cs'                        => ',protected,',
1453 dpurdie 149
 
2016 dpurdie 150
    'DBA-Common'                => ',protected,',
151
    'DBA-DatabaseInstall'       => ',protected,',
152
    'DBA-ExternalPerlModules'   => ',protected,',
153
    'DBA-OraUserBuild'          => ',protected,',
154
    'DBA-OST'                   => ',protected,',
155
    'orahops-install'           => ',protected,',
156
    'orahops-patch'             => ',protected,',
157
    'orahops-ssw-install'       => ',protected,',
158
    'orahops-ssw-patch'         => ',protected,',
159
# End of ukHops migration exclussion
160
 
1197 dpurdie 161
    'ftp'                   => 'SetProjectBase,',
162
 
163
    'icl'                   => 'IgnoreProjectBase,',
164
    'itso'                  => 'IgnoreProjectBase,',
165
    'daf_osa_mos'           => 'IgnoreProjectBase,',
166
    'daf_utils_mos'         => 'IgnoreProjectBase,',
167
    'itso_ud'               => 'IgnoreProjectBase,',
168
#    'mos_api'               => 'IgnoreProjectBase,',
169
#    'mos_fonts'             => 'IgnoreProjectBase,',
170
#    'sntp'                  => 'IgnoreProjectBase,',
171
#    'time_it'               => 'IgnoreProjectBase,',
392 dpurdie 172
);
173
 
174
my %notCots = (
175
    'isl'       => 1,
176
);
177
 
1451 dpurdie 178
my $ukHopsMode = 0;
179
my %ukHopsReleases = (
180
    '6222'      => { name => 'MainLine', 'trunk' => 1 },
1453 dpurdie 181
    '14503'     => { name => 'Hops3' },
182
    '21864'     => { name => 'Hops3.6' },
183
    '22303'     => { name => 'Hops3.7' },
1451 dpurdie 184
    '17223'     => { name => 'Hops4' },
185
);
186
 
2016 dpurdie 187
# The following packages will have the version in the specified release forced to be on the trunk
188
# A trunk will be forced and the version will be on it.
189
#   May only work if the version in the release is also a TIP
190
my %ukHopsTip = (
191
    'ItsoMessaging'         => '6222',
192
    'MessageProcessor'      => '6222',
193
    'StrongNameKey'         => '6222',
194
);
195
 
392 dpurdie 196
################################################################################
197
#   Global data
198
#
199
my $VERSION = "1.0.0";
200
my $RM_DB;
201
my $last_pv_id;
202
my %pkg_ids;
203
my $first_pkg_id;
204
my %versions;
205
my %suffixes;
206
my @processOrder;
207
my @startPoints;
208
my @allStartPoints;
209
my @endPoints;
210
my $now = time();
211
my $logSummary;
212
my $firstVersionCreated;
213
my @EssentialPackages;
214
my $createBranch;
215
my $createSuffix;
216
my $currentBranchName;
217
my $singleProject;
218
my $pruneCount = 0;
219
my $trimCount = 0;
220
my $badVcsCount = 0;
221
my $ProjectCount = 0;
222
my $totalVersions = 0;
223
my $initialTrees = 0;
224
my $globalError;
225
my @unknownProjects;
226
my %knownProjects;
227
my $badSingletonCount = 0;
228
my @flatOrder;
229
my $pruneMode;
230
my $pruneModeString;
231
my $threadId = 0;
232
my $threadCount;
233
my %tipVersions;
234
my $allSvn;
235
my @multiplePaths;
236
my @badEssentials;
237
my %svnData;
238
my $cwd;
239
 
240
my $packageNames;
241
my @packageNames;
242
my $multiPackages = -1;
243
my $visitId = 0;
244
my $noTransfer;
245
my $rippleCount = 0;
246
my $svnRepo;
1270 dpurdie 247
my $processCount = 0;
248
my $processTotal = 0;
1272 dpurdie 249
my $recentCount = 0;
392 dpurdie 250
 
251
our $GBE_RM_URL;
252
my $UNIX = $ENV{'GBE_UNIX'};
253
 
254
my $result = GetOptions (
255
                "help+"         => \$opt_help,          # flag, multiple use allowed
256
                "manual:3"      => \$opt_help,
257
                "verbose:+"     => \$opt_verbose,       # Versose
258
                "repository:s"  => \$opt_repo,          # Name of repository
1272 dpurdie 259
                'rbase:s'       => \$opt_repo_base,     # Base of the repo
392 dpurdie 260
                "flat!"         => \$opt_flat,          # Flat structure
261
                "test!"         => \$opt_test,          # Test operations
262
                "reuse!"        => \$opt_reuse,         # Reuse ClearCase views
263
                "age:i"         => \$opt_age,           # Only recent versions
264
                "dump:1"        => \$opt_dump,          # Dump Data
265
                "images:1"      => \$opt_images,        # Create DOT images
266
                "retain:i"      => \$opt_retaincount,   # Retain N packages
267
                "pruneMode:s"   => \$opt_pruneModeString,
268
                "listtags:i"    => \$opt_listTags,
269
                "name:s"        => \$opt_name,          # Alternate output
270
                "tip:s"         => \@opt_tip,           # Force tip version(s)
271
                "log!"          => \$opt_log,
1270 dpurdie 272
                "delete!"       => \$opt_delete,
392 dpurdie 273
                "postimage!"    => \$opt_postimage,
274
                'workdir:s'     => \$opt_workDir,
275
                );
276
 
277
#
278
#   Process help and manual options
279
#
280
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
281
pod2usage(-verbose => 1)  if ($opt_help == 2 );
282
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
283
 
284
#
285
#   Configure the error reporting process now that we have the user options
286
#
287
SystemConfig ('ExitOnError' => 1);
288
ErrorConfig( 'name'    =>'CC2SVN_IMPORT',
289
             'verbose' => $opt_verbose,
290
              );
291
 
292
Error("Workdir does not exist" ) unless ( -d $opt_workDir );
293
Error("Specify a package as 'name'" ) unless ( defined $ARGV[0] );
294
EnvImport('GBE_RM_URL');
295
$cwd = Getcwd();
296
 
297
#
298
#   Init the pruning mode
299
#
300
setPruneMode( $opt_pruneModeString || 'ripple');
301
 
302
#
303
#   Get data for all packages
304
#
305
foreach my $packageName ( @ARGV )
306
{
307
    next unless ( $packageName );
308
    Verbose( "Base Package: $packageName");
309
 
310
    my $pkg_id = GetPkgIdByName ( $packageName );
311
    GetData_by_pkg_id ( $pkg_id, $packageName  );
312
    $pkg_ids{$pkg_id} = 1;
313
    $first_pkg_id = $pkg_id unless ( $first_pkg_id );
314
    push @packageNames, $packageName;
315
    $multiPackages++;
316
}
317
 
318
{
319
    #
320
    #   Delete entries that have been created as we read in
321
    #   data, but don't exist in RM. They will not have a pvid.
322
    #
323
    foreach my $entry ( keys(%versions) )
324
    {
325
        delete $versions{$entry}
326
            unless ( exists $versions{$entry}{pvid} );
327
    }
328
}
329
 
330
$totalVersions = scalar keys %versions;
331
Error ("No packages specified") unless ( $multiPackages >= 0 );
332
Warning ("Multiple Packages being processed") if ( $multiPackages > 1 );
333
$packageNames = join ('_', @packageNames );
334
$packageNames = $opt_name if ( defined $opt_name );
335
Message ("PackageName: $packageNames" );
336
 
337
#
338
#   Save logging data
339
#
340
if ( $opt_log )
341
{
342
    my $opt_logfile = $packageNames . '.import';
343
    Message ("Logging outout: $opt_logfile" );
344
    open STDOUT, '>', $opt_logfile  or die "Can't redirect STDOUT: $!";
345
    open STDERR, ">&STDOUT"         or die "Can't dup STDOUT: $!";
346
}
347
 
348
#
349
#   Prepare tip version hash
350
#
351
$tipVersions{$_} = 1 foreach ( @opt_tip );
352
 
353
#
354
#   Read in external data and massage it all
355
#
356
getEssenialPackageVersions();
357
getVobMapping();
358
smartPackageType();                 # Determine special prune mode
359
ReportPathVariance();
360
massageData();
361
getSvnData();
362
smartPackageType();                 # Have another go
363
 
364
my @missedTips = keys %tipVersions;
365
Error ("Specified tip version not found: @missedTips") if ( @missedTips );
366
 
367
if ( $opt_flat )
368
{
369
#    @flatOrder = sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions);
370
#    @flatOrder = sort {$versions{$a}{created} cmp $versions{$b}{created}} keys(%versions);
371
    @flatOrder = sort {$a <=> $b} keys(%versions);
372
    my $tip = $flatOrder[-1];
373
    $versions{$tip}{Tip} = 1 if $tip;
374
}
375
 
376
#
377
#   Generate dumps and images
378
#
379
if ( $opt_images )
380
{
381
    createImages();
382
}
383
 
384
if ( $opt_dump )
385
{
386
    DebugDumpData ("Versions", \%versions );
387
    DebugDumpData ("Starts", \@startPoints );
388
    DebugDumpData ("Ends", \@endPoints );
389
    DebugDumpData ("Suffixes", \%suffixes );
390
}
391
 
392
 
393
#   Display VCS tags
394
#
395
if ( $opt_listTags )
396
{
397
    foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions) )
398
    {
399
        print $versions{$entry}{vcsTag} || '-' ,"\n";
400
    }
401
}
402
exit if ( ($opt_dump > 1) || ($opt_images > 1) );
403
 
404
transferPackageToSvn();
405
 
406
if ( $opt_postimage )
407
{
408
    getSvnData();
409
    createImages();
410
}
411
 
412
exit 0;
413
 
414
#-------------------------------------------------------------------------------
415
# Function        : transferPackageToSvn
416
#
417
# Description     : Transfer the package to SVN
418
#
419
# Inputs          : 
420
#
421
# Returns         : 
422
#
423
sub transferPackageToSvn
424
{
425
    Error ("Repository Path not setup")
426
        unless ( $svnRepo );
427
 
428
    #
429
    #   Going to do serious work
430
    #   Need to ensure we have more arguments
431
    #
432
    if ( $noTransfer )
433
    {
434
        Warning("Protected Package not transferred: $packageNames[0]");
435
        exit 0;
436
    }
437
 
438
    #
439
    #   Perform all the work in a package specific subdirectory
440
    #
441
    my $workDir = $opt_workDir . '/' . $packageNames;
442
    mkdir $workDir unless ( -d $workDir );
443
    chdir $workDir || Error ("Cannot cd to $workDir");
444
 
445
    #
446
    #   Process all packages
447
    #       Going to create versions based on RM structure
448
    #       May have several starting points: Process each
449
    #
450
    newPackage();
451
    if ( $opt_flat )
452
    {
453
        newProject();
454
        foreach my $entry (@flatOrder )
455
        {
456
            newPackageVersion( $entry, $versions{$entry}{suffix} );
457
        }
458
    }
459
    else
460
    {
461
        processBranch(@allStartPoints);
462
    }
463
    endPackage();
464
 
465
    chdir $cwd || Error ("Cannot cd back to $cwd");
466
    rmdir $workDir;
467
    Warning ("Work Directory still exists: $workDir");
468
    saveData();
469
}
470
 
471
#-------------------------------------------------------------------------------
472
# Function        : setPruneMode
473
#
474
# Description     : Set the pruning mode
475
#
476
# Inputs          : mode                    - Text mode value
477
#
478
# Returns         : Nothing
479
#
480
sub setPruneMode
481
{
482
    my ($mode) = @_;
483
    my $value;
484
    if ( $mode )
485
    {
486
        if ( $mode =~ m/none/i) {
487
            $value = 0;
488
        } elsif ( $mode =~ m/ripple/i) {
489
            $value = 1;
490
        } elsif ( $mode =~ m/retain/i) {
491
            $value = 2;
492
        } elsif ( $mode =~ m/severe/i) {
493
            $value = 3;
494
        } else {
495
            Error ("Unknown pruning mode", "Use: none, ripple, retain or severe");
496
        }
497
 
498
        $pruneModeString = $mode;
499
        $pruneMode = $value;
500
    }
501
}
502
 
503
#-------------------------------------------------------------------------------
504
# Function        : smartPackageType
505
#
506
# Description     : Have a look at the projects in the package set and
507
#                   attempt to determine what sort of mechanism to use
508
#
509
# Inputs          : Uses %suffixes data
510
#
511
# Returns         : 
512
#
513
my $packageType = 'UNKNOWN';
514
sub smartPackageType
515
{
516
    #
517
    #   Rebuild suffixes hash based on  post massaged versions
518
    #
519
    my %suffixes;
520
    my @unknown;
521
    foreach my $entry ( keys %versions )
522
    {
523
        my $suffix = $versions{$entry}{suffix} || '';
524
        push (@unknown, $entry) if ($suffix eq 'unknown');
525
 
526
        next if ( exists $suffixes{$suffix} );
527
        next if ( $versions{$entry}{badSingleton} );
528
        next if ( $versions{$entry}{locked} eq 'N' || $versions{$entry}{isaWip} );
529
        $suffixes{$suffix} = 1;
530
        $knownProjects{$suffix}{seen} = 1;
531
 
532
    }
533
 
534
    #
535
    #   The 'unknown' suffix is really an 'empty' suffix
536
    #   Try to be clever
537
    #       Map unknown to 'cr' or 'mas' if present
538
    #
539
    #
540
    if ( exists $suffixes{'unknown'}  )
541
    {
542
        my $new_suffix;
543
        if ( exists $suffixes{'.cr'} ) {
544
            $new_suffix = '.cr';
545
        } elsif ( exists $suffixes{'.mas'} ) {
546
            $new_suffix = '.mas';
547
        }
548
 
549
        if ( $new_suffix )
550
        {
551
            foreach my $entry ( @unknown )
552
            {
553
                $versions{$entry}{suffix} = $new_suffix;
554
            }
555
            delete $suffixes{'unknown'};
556
            delete $knownProjects{'unknown'}{seen};
557
        }
558
    }
559
 
560
    if ( exists $suffixes{'.cots'} && !exists ($notCots{$packageNames}) ) {
561
        $packageType = 'COTS';
562
        $Projects{'.cots'}{Trunk} = 1;
563
        $singleProject = 1;
564
        $opt_flat = 1 unless defined $opt_flat;
565
        setPruneMode('none') unless (defined $opt_pruneModeString);
566
 
567
    } elsif ( exists $suffixes{'.tool'} ) {
568
        $packageType = 'TOOL';
2016 dpurdie 569
        $Projects{'.tool'}{Trunk} = 1;
392 dpurdie 570
        $singleProject = 1;
571
        setPruneMode('none') unless (defined $opt_pruneModeString);
572
#        $opt_flat = 1;
573
 
574
    } elsif ( scalar (keys %suffixes ) == 1 ) {
575
        $packageType = 'SINGLE_PROJECT';
576
        $singleProject = 1;
577
 
578
    } else {
579
        $packageType = 'MULTIPLE_PROJECT';
580
    }
581
 
582
    #
583
    #   Some packages are special
584
    #
585
 
586
    if ( $packageNames[0] =~ m'^br_applet_' )
587
    {
588
        $opt_flat = 1 unless defined $opt_flat;
589
    }
590
 
591
    if ( exists $specialPackages{$packageNames[0]} )
592
    {
593
        my $data = $specialPackages{$packageNames[0]};
594
        if ( index( $data, ',all' ) >= 0) {
595
            setPruneMode('none') unless (defined $opt_pruneModeString);
596
        }
597
 
598
        if ( index( $data, 'protected,' ) >= 0) {
599
            $noTransfer = 1;
600
        }
601
 
602
        if ( index( $data, 'flat,' ) >= 0) {
603
            $opt_flat = 1;
604
        }
1197 dpurdie 605
 
606
        if ( index( $data, 'SetProjectBase,' ) >= 0) {
607
            $opt_preserveProjectBase = 1;
608
            $opt_ignoreProjectBaseErrors = 1;
609
            Message ("Preserving ProjectBase");
610
        }
611
 
612
        if ( index( $data, 'IgnoreProjectBase,' ) >= 0) {
613
            $opt_ignoreProjectBaseErrors = 1;
614
            Message ("Ignore ProjectBase Errors");
615
        }
616
 
392 dpurdie 617
    }
618
 
619
    Message("Package Type: $packageType, $pruneModeString");
620
}
621
 
622
 
623
#-------------------------------------------------------------------------------
624
# Function        : massageData
625
#
626
# Description     : Massage all the data to create a tree of package versions
627
#                   that can be used to create images as well as an import order
628
#
629
# Inputs          : 
630
#
631
# Returns         : 
632
#
633
my $reprocess=0;
634
sub calcLinks
635
{
636
    #
637
    #   Process the 'versions' hash and:
638
    #   Add back references
639
    #   Find starts and ends
640
    #       Entry with no previous
641
    #       Entry with no next
642
    #
643
    $reprocess = 0;
644
    foreach my $entry ( keys(%versions) )
645
    {
646
        foreach ( @{ $versions{$entry}{next}} )
647
        {
648
            $versions{$_}{last} = $entry;
649
        }
650
    }
651
    @allStartPoints = ();
652
    @startPoints = ();
653
    @endPoints = ();
654
    foreach my $entry ( keys(%versions) )
655
    {
656
        push @startPoints, $entry
657
            unless ( exists $versions{$entry}{last} || $versions{$entry}{badSingleton} );
658
 
659
        push @allStartPoints, $entry
660
            unless ( exists $versions{$entry}{last} );
661
 
662
        push @endPoints, $entry
663
            unless ( @{$versions{$entry}{next}} > 0  )
664
    }
665
}
666
 
667
sub massageData
668
{
669
    #
670
    #   Report unknown suffixes
671
    #   Handle bad, or little known project suffixes by creating them
672
    #
673
    foreach my $suffix ( keys %suffixes )
674
    {
675
        if ( exists $Projects{$suffix} )
676
        {
677
            next;
678
        }
679
        Message ("Unknown project suffix: '$suffix'");
680
        push @unknownProjects, $suffix;
681
        my $cleanSuffix = ucfirst(lc(substr( $suffix, 1)));
682
        $Projects{$suffix}{Name} = 'Project_' . $cleanSuffix;
683
    }
684
 
685
    calcLinks();
686
 
687
    $initialTrees = scalar @allStartPoints;
688
    Message ('Total RM versions: ' . $totalVersions );
689
    Message ('Initial trees: ' . $initialTrees );
690
    #
691
    #   Attempt to glue all the start points into one chain.
692
    #   This should allow us to track projects that branch from each other
693
    #   in cases where the RM data is incorrect/incomplete
694
    #       Strays are those that have no next or last
695
    #
696
    #   Glue based on Name, then PVID (Creation Order)
697
    #
698
    {
699
        #
700
        #   Examine threads. If it is a single entry thats bad then drop it
701
        #   This is simple to do. Should examine all entries, but thats a
702
        #   bit harder. Perhaps later.
703
        #
704
        if (1) {
705
            Message ("Dropping Bad Singletons");
706
            my $badSingletons;
707
            foreach my $entry ( sort {$a <=> $b} @startPoints )
708
            {
709
                my $ep = $versions{$entry};
710
                unless ( $ep->{last} || $ep->{next}[0] )
711
                {
712
#                    if (  $ep->{isaWip}  )
713
                    if ( (exists $ep->{badVcsTag} && $ep->{badVcsTag}) || $ep->{isaWip}  )
714
                    {
715
                        $ep->{badSingleton} = 1;
716
                        $reprocess = 1;
717
                        $badSingletonCount++;
718
 
719
                        # Add to a list of its own.
720
                        if ( $badSingletons )
721
                        {
722
                            push @{$versions{$badSingletons}{next}}, $entry;
723
                        }
724
                        $badSingletons = $entry;
725
                    }
726
                }
727
            }
728
            calcLinks()
729
                if ( $reprocess );
730
        }
731
 
732
        #
733
        #   Create simple trees out of the chains
734
        #   Tree is based on suffix (project) and version
735
        #
736
        {
737
            my %trees;
738
            Message ("Entries into trees");
739
            foreach my $single ( @startPoints )
740
            {
741
                my $suffix = $versions{$single}{suffix} || '';
742
                push @{$trees{$suffix}}, $single;
743
            }
744
 
745
            foreach  ( keys %trees )
746
            {
747
                my $last;
748
                foreach my $entry ( sort { $versions{$a}{version} cmp $versions{$b}{version}  } @{$trees{$_}} )
749
                {
750
                    if ( $last )
751
                    {
752
                        $versions{$last}{MakeTree} = 1;
753
                        push @{$versions{$last}{next}}, $entry;
754
                        $reprocess = 1;
755
                    }
756
                    $last = $entry;
757
                }
758
            }
759
            calcLinks()
760
                if ( $reprocess );
761
        }
762
 
763
        #
764
        #   Have a number of trees that are project related
765
        #   Attempt to create a single tree by inserting
766
        #   Secondary trees into the main line at suitable points
767
        #
768
        my @AllVersions = sort { $a <=> $b } @startPoints;
769
        my $lastEntry = shift @AllVersions;
770
        Error ("Oldest entry has a previous version") if ( $versions{$lastEntry}{last}  );
771
#print "Oldest: $lastEntry\n";
772
        #
773
        #   Insert remaining entries into out list, which is now sorted
774
        #
775
        my @completeList;
776
        foreach my $base ( @AllVersions  )
777
        {
778
            push @completeList, recurseList($lastEntry);
779
            @completeList = sort {$a <=> $b} @completeList;
780
#            Message("Complete List: ", @completeList);
781
#            Message("Complete List($completeList[0]) Length: " . scalar @completeList);
782
            $lastEntry = $base;
783
 
784
            my $last;
785
            foreach my $entry ( @completeList )
786
            {
787
                if ( $entry > $base )
788
                {
789
                    Error ("Not expecting last to be empty. $base, $entry") unless ( $last );
790
                    last;
791
                }
792
                $last = $entry;
793
            }
794
 
795
            #
796
            #   Insert at end if point not yet found
797
            #
798
#print "Inserting $base at $last\n";
799
            push @{$versions{$last}{next}}, $base;
800
            $versions{$base}{GluedIn} = 1;
801
            $reprocess = 1;
802
        }
803
 
804
        #
805
        #   Recalc basic links if any processing done
806
        #
807
        calcLinks()
808
            if ( $reprocess );
809
 
810
    }
811
 
812
 
813
    #
814
    #   Remove Dead Ends
815
    #   Packages that were never released
816
    #       Not locked, unless essential or a branchpoint
817
    #   Won't consider these to be mainline path.
818
    #
819
    {
820
        Message ("Remove Dead Ends");
821
        foreach my $entry ( @endPoints )
822
        {
823
            my $deadWood;
824
            while ( $entry )
825
            {
826
                last if ( $versions{$entry}{Essential} );
827
 
828
                my @next = @{$versions{$entry}{next}};
829
                my $count = @next;
830
                last if ( $count > 1 );
831
 
832
                last unless ( $versions{$entry}{locked} eq 'N' || $versions{$entry}{isaWip} );
833
 
834
                $versions{$entry}{DeadWood} = 1;
835
                $trimCount++;
836
            } continue {
837
                $entry = $versions{$entry}{last};
838
            }
839
        }
840
    }
841
 
842
    #
843
    #   Walk each starting point list and determine new Projects
844
    #   branchpoints.
845
    #
846
    Message ("Locate Projects branch points");
847
    foreach my $bentry ( keys(%versions) )
848
    {
849
        my $baseSuffix = $versions{$bentry}{suffix};
850
        foreach my $entry ( @{$versions{$bentry}{next}} )
851
        {
852
            if ( $baseSuffix ne $versions{$entry}{suffix})
853
            {
854
                unless ( exists $versions{$entry}{DeadWood} || $versions{$entry}{badSingleton} )
855
                {
856
#print "--- Project Branch $versions{$entry}{vname}\n";
857
                    $versions{$entry}{branchPoint} = 1;
858
                    $versions{$entry}{newSuffix} = 1;
859
                }
860
            }
861
        }
862
    }
1451 dpurdie 863
 
864
    #
865
    #   Mark UkHops special points
866
    #
867
    foreach my $entry ( keys(%versions) ) {
868
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
869
            next unless ( exists $ukHopsReleases{$rtag_id} );
870
            next unless ( $svnRepo =~ m~/ITSO_TRACS$~ );
871
 
872
            #
873
            #   This package is current in a special ukHops release
874
            #   Need to handle the differently
875
            #
876
            my $ukData =  $ukHopsReleases{$rtag_id};
877
 
878
            # Mark version we want on the trunk
879
            # Will calculate tip later
880
            if ( $ukData->{trunk} )
881
            {
882
                #
883
                #   Can only place on trunk IFF its a tip
884
                #   May have a WIP.
885
                #   Solution. Walk to the tip, but only if there is one
886
                #             path.
887
                #
888
                my $end = $entry;
889
                my $last;
890
                while ( $end )
891
                {
892
                    $last = $end;
893
                    if ( @{$versions{$end}{next}} > 1)
894
                    {
895
                        Warning ("Uk Release. Preferred trunk is not a tip: $versions{$entry}{vname}");
896
                        last;
897
                    }
898
 
899
                    $end = @{$versions{$end}{next}}[0];
900
                }
901
                $versions{$last}{ukTrunk} = 1 ;
902
            }
903
 
904
            #
905
            #   What to do if the version is in more than one release
906
            #
907
            $versions{$entry}{ukBranch}++;
908
            if ( $versions{$entry}{ukBranch} > 1 )
909
            {
910
                Warning ("Version found in multiple Uk Releases - don't know what to do");
911
            }
912
 
913
            #
914
            #   What to do if the package has multiple version in a release
915
            #
916
            $ukData->{count}++;
917
            if ( $ukData->{count} > 1 )
918
            {
919
                Warning ("Package has multiple versions in the one Uk Release: $versions{$entry}{Releases}{$rtag_id}{rname}");
920
            }
921
        }
922
    }
392 dpurdie 923
 
924
    #
925
    #   Prune
926
    #   Marks paths to root for all essential packages
927
    #   Marks the last-N from all essential packages
928
    #
929
    if ( $pruneMode )
930
    {
931
        Message ("Prune Tree: $pruneModeString");
932
        foreach ( @EssentialPackages )
933
        {
934
            #next unless ( exists $versions{$_} );      # Aleady deleted
935
 
936
            # Mark previous-N to be retained as well
937
            my $entry = $_;
938
            my $count = 0;
939
            while ( $entry )
940
            {
941
                last if ( $versions{$entry}{KeepMe} );
1453 dpurdie 942
#                unless ( $versions{$entry}{isaRipple} )
392 dpurdie 943
                {
944
                    my $keepFlag = ($count++ < $opt_retaincount);
945
                    last unless ( $keepFlag );
946
                    $versions{$entry}{KeepMe} = $keepFlag;
947
                }
948
                $entry = $versions{$entry}{last}
949
            }
950
        }
951
 
952
        #
1272 dpurdie 953
        #   Keep recent versions
954
        #       Keep versions created in the last N days
955
        #       Will keep recent ripples too
956
        #
957
        if ( $pruneMode == 1 )
958
        {
959
            foreach my $entry ( keys(%versions) )
960
            {
961
                next unless ( $versions{$entry}{Age} <= $opt_recentAge  );
962
                $versions{$entry}{keepRecent} = 1;
963
                $recentCount++;
964
#print "--- Recent version $versions{$entry}{vname}, $versions{$entry}{Age} <= $opt_recentAge\n";
965
            }
966
 
967
#            #
968
#            #   Keep the tip of each branch
969
#            #
970
#            foreach my $entry ( @endPoints )
971
#            {
972
#                next if exists $versions{$entry}{keepRecent};
973
#                $versions{$entry}{keepRecent} = 1;
974
##print "--- Tip version $versions{$entry}{vname}\n";
975
#            }
976
        }
977
 
978
        #
392 dpurdie 979
        #   Keep versions that are common parents to Essential Versions
980
        #       Mark paths through the tree to essential versions
981
        #       Mark nodes with the number of essential versions that they sprout
982
        #   Don't do it if we are ripple pruning
983
        #
984
        Message ("Prune Tree keep common parents");
985
        if ( $pruneMode != 1 )
986
        {
987
            foreach my $entry ( @endPoints )
988
            {
989
                my $hasEssential = 0;
990
                $visitId++;
991
                while ( $entry )
992
                {
993
                    $hasEssential = 1 if ( exists ($versions{$entry}{Essential}) && $versions{$entry}{Essential} );
994
                    if ( $hasEssential )
995
                    {
996
                        if ( @{$versions{$entry}{next}} > 1 )
997
                        {
998
                            $versions{$entry}{EssentialSplitPoint}++;
999
                        }
1000
                        last if ( exists $versions{$entry}{EssentialPath} );
1001
                        $versions{$entry}{EssentialPath} = 1;
1002
                    }
1003
 
1004
                    if ( ($versions{$entry}{visitId} || 0) == $visitId )
1005
                    {
1006
                        DebugDumpData ("Versions", \%versions );
1007
                        Warning ("Circular dependency");
1008
                        last;
1009
                    }
1010
                    $versions{$entry}{visitId} = $visitId;
1011
 
1012
                    $entry = $versions{$entry}{last};
1013
                }
1014
            }
1015
        }
1016
 
1017
        #
1018
        #   Keep first version of each ripple. Must keep first
1019
        #   Group ripples together so that they can be proccessed at the same time
1020
        #
1021
        calcRippleGroups()
1022
            if ( $pruneMode == 1);
1023
 
1024
        #
1025
        #   Delete all nodes that are not marked for retention
1026
        #   This is rough on the tree
1027
        #
1028
        Message ("Prune Tree Deleting");
1029
 
1030
        # 0 - Keep me
1031
        # 1 - Prune me
1032
        sub pruneMe
1033
        {
1034
            my ($entry) = @_;
1035
 
1036
            return 0 unless ( exists $versions{$entry} );
1037
            return 0 unless ( $versions{$entry}{last} );
1454 dpurdie 1038
#            return 0 if ( ($pruneMode == 2) && exists $versions{$entry}{KeepMe} );
1039
            return 0 if ( exists $versions{$entry}{KeepMe} );
392 dpurdie 1040
            return 0 if ( exists $versions{$entry}{Essential} );
1041
            return 0 if ( $versions{$entry}{newSuffix} );
1042
            return 0 if ( $versions{$entry}{newSuffix} && (exists $versions{$entry}{EssentialPath}) );
1043
#            return 1 if ( exists $versions{$entry}{DeadWood} );
1044
            return 0 if ( exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
1045
            return 0 if ( exists $versions{$entry}{keepLowestRipple} &&  $versions{$entry}{keepLowestRipple} );
1046
            return 0 if ( ($pruneMode == 1) && ! $versions{$entry}{isaRipple} );
1272 dpurdie 1047
            return 0 if ( exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 1048
            return 1;
1049
        }
1050
 
1051
        foreach my $entry ( keys(%versions) )
1052
        {
1053
#last;
1054
            next unless ( pruneMe($entry) );
1055
#print "--- Prune: $versions{$entry}{vname}\n";
1056
 
1057
            # Delete the current node
1058
            #
1059
            my @newNext;
1060
            $pruneCount++;
1061
            my $last = $versions{$entry}{last};
1062
            foreach ( @{$versions{$last}{next}} )
1063
            {
1064
                next if ( $_ == $entry );
1065
                push @newNext, $_;
1066
            }
1067
            foreach ( @{$versions{$entry}{next}} )
1068
            {
1069
                push @newNext, $_;
1070
                $versions{$_}{last} = $last;
1071
            }
1072
 
1073
            @{$versions{$last}{next}} = @newNext;
1074
            delete $versions{$entry};
1075
        }
1076
 
1077
        # Recalculate endpoints
1078
        calcLinks();
1079
    }
1080
    else
1081
    {
1082
        #   No rippling happening
1083
        #   Some process still need to happen
1084
        #
1085
        calcRippleGroups();
1086
    }
1087
 
1088
    #
2016 dpurdie 1089
    #   Want some versions to be forced to tip trunk
1090
    #
1091
    foreach my $name ( keys %ukHopsTip )
1092
    {
1093
        foreach my $entry ( keys(%versions) )
1094
        {
1095
            next unless ( $versions{$entry}{name} eq $name  );
1096
            next unless ( exists $versions{$entry}{Releases}{$ukHopsTip{$name}} );
1097
 
1098
            #
1099
            #   Force this suffix to be the trunk
1100
            #   Remove all others
1101
            #
1102
            foreach my $suffix ( keys %Projects )
1103
            {
1104
                delete $Projects{$suffix}{Trunk};
1105
            }
1106
            my $suffix = $versions{$entry}{suffix};
1107
            $Projects{$suffix}{Trunk} = 1;
1108
        }
1109
    }
1110
 
1111
    #
392 dpurdie 1112
    #   Calculate best through-path for branches in the tree
1113
    #   Attempt to keep that 'max' version on the mainline
1114
    #   May be modified by -tip=nnnn
1115
    #
1116
    #   For each leaf (end point), walk backwards and mark each node with the
1117
    #   max version see. If we get to a node which already has been marked then
1118
    #   stop if our version is greater. We want the value to be the max version
1119
    #   to a leaf
1120
    #
1121
    #   Account for 'suffix'. When suffix changes, then the 'max' version must
1122
    #   be recalculated
1123
    #
1124
 
1125
    Message ("Calculate Max Version");
1126
    my $maxVersion;
1127
    foreach my $entry ( @endPoints )
1128
    {
1129
        my $lastSuffix;
1130
        my $forceTip;
1131
        while ( $entry )
1132
        {
1133
            if (!defined($lastSuffix) || ($versions{$entry}{suffix} ne $lastSuffix) )
1134
            {
1135
                $maxVersion = '0';
1136
                $visitId++;
1137
                $forceTip = ( exists $tipVersions{$versions{$entry}{vname}} );
1451 dpurdie 1138
                $forceTip = 1 if $versions{$entry}{ukTrunk};
392 dpurdie 1139
                delete $tipVersions{$versions{$entry}{vname}};
1140
                $maxVersion = '999.999.999.999.zzz' if ( $forceTip );
1141
                $lastSuffix = $versions{$entry}{suffix};
1142
#print "---Tip Found\n" if $forceTip;
1143
            }
1144
 
1145
            # Detect circular dependencies
1146
            if ( ($versions{$entry}{visitId} || 0) == $visitId )
1147
            {
1148
                DebugDumpData ("Circular dependency: Versions", \%versions );
1149
                Warning ("Circular dependency");
1150
                last;
1151
            }
1152
            $versions{$entry}{visitId} = $visitId;
1153
 
1154
            my $thisVersion = $versions{$entry}{version} || '';
1155
            if ( $thisVersion gt $maxVersion )
1156
            {
1157
                $maxVersion = $thisVersion;
1158
            }
1159
 
1160
            if ( exists $versions{$entry}{maxVersion} )
1161
            {
1162
                if ( $versions{$entry}{maxVersion} gt $maxVersion )
1163
                {
1164
                    last;
1165
                }
1166
            }
1167
 
1168
            $versions{$entry}{maxVersion} = $maxVersion;
1169
            $entry = $versions{$entry}{last};
1170
        }
1171
    }
1172
 
1173
 
1174
    #
1175
    #   Locate all instances where a package-version branches
1176
    #   Determine the version that should be on the non-branching path
1177
    #
1178
    #   Reorder the 'next' list so that the first item is the non-branching
1179
    #   path. This will be used in the data-insertion phase to simplify the
1180
    #   processing.
1181
    #
1182
    Message ("Calculate package version branches");
1183
    foreach my $entry ( sort {$a <=> $b} keys(%versions) )
1184
    {
1185
        calculateWalkOrder($entry);
1186
    }
1187
 
1188
    #
1189
    #   Mark Project Branch Tips as they will be in the Repository
1190
    #   Find each project head and walk primary entry to the end.
1191
    #
1192
    foreach my $entry ( keys(%versions) )
1193
    {
1194
        #
1195
        #   Root of each tree is 'new'
1196
        #
1197
        unless ( defined $versions{$entry}{last})
1198
        {
1199
            unless ( $versions{$entry}{badSingleton} )
1200
            {
1201
                $versions{$entry}{newSuffix} = 1;
1202
            }
1203
        }
1204
 
1205
        #
1206
        #   Update stats
1207
        #
1208
        $badVcsCount++ if ( $versions{$entry}{badVcsTag} );
1209
        $ProjectCount++ if ( $versions{$entry}{newSuffix} );
1210
        next if ( $opt_flat );
1211
 
1212
        next unless ($versions{$entry}{newSuffix} );
1213
#print "--- Project new Suffix $versions{$entry}{vname}\n";
1214
 
1215
 
1216
        my $suffix = $versions{$entry}{suffix};
1217
        $knownProjects{$suffix}{count}++;
1218
 
1219
        my $next = $versions{$entry}{next}[0];
1220
        my $tip;
1221
        while ( $next )
1222
        {
1223
            last if ( $suffix ne $versions{$next}{suffix} );
1224
            $tip = $next unless (exists ($versions{$next}{DeadWood}) || $versions{$next}{badSingleton});
1225
            $next = $versions{$next}{next}[0];
1226
        }
1227
 
1228
        $versions{$tip}{Tip} = 1 if $tip;
1229
    }
1230
 
1231
    unless ( $opt_flat )
1232
    {
1233
        my $finalTrees = scalar @startPoints;
1234
        Warning ("Still have multiple trees: $finalTrees") unless ( $finalTrees == 1 );
1235
    }
1236
 
1237
    #
1238
    #   Display warnings about multiple
1239
    #
1240
    foreach ( sort keys %knownProjects )
1241
    {
1242
        my $count = $knownProjects{$_}{count} || 0;
1243
        Warning ("Multiple Project Roots: $_ ($count)" )
1244
            if ( $count > 1 );
1245
    }
1246
 
1247
    #
1248
    #   Display warnings about Bad Essential Packages
1249
    #
1250
    $allSvn = 1;
1251
    foreach my $entry ( keys(%versions) )
1252
    {
1253
        $rippleCount++ if ( exists($versions{$entry}{isaRipple}) && $versions{$entry}{isaRipple} );
1254
        $allSvn = 0 unless ( $versions{$entry}{isSvn} );
1255
        next unless ( exists $versions{$entry}{Essential}  );
1256
        next unless ( $versions{$entry}{badVcsTag}  );
1257
        push @badEssentials, $entry;
1258
        Warning ("BadVCS Essential: " . GetVname($entry))
1259
    }
1260
 
1261
    #
1262
    #   All done
1263
    #
1270 dpurdie 1264
    $processTotal = scalar keys %versions;
1265
    Message("Retained entries: $processTotal" );
392 dpurdie 1266
    Message("Pruned entries: $pruneCount");
1267
    Message("Deadwood entries: $trimCount");
1268
    Message("Bad Singletons: $badSingletonCount");
1269
    Message("Ripples: $rippleCount");
1272 dpurdie 1270
    Message("Recent entries: $recentCount");
392 dpurdie 1271
}
1272
 
1273
sub calculateWalkOrder
1274
{
1275
    my ($entry) = @_;
1276
    my @next = @{$versions{$entry}{next}};
1277
    my $count = @next;
1278
    my @ordered;
1279
    my $main;
1280
 
1281
    if ( $count > 1 )
1282
    {
1283
        # Array to hash to simplify removal
1284
        my %nexts = map { $_ => 1 } @next;
1285
        foreach my $e ( @next )
1286
        {
1287
 
1288
            #
1289
            #   Locate branch points that are not a part of a new project
1290
            #   These will not be preferred paths for walking
1291
            #
1292
            if ( !defined($versions{$e}{branchPoint}) && $versions{$entry}{suffix} ne $versions{$e}{suffix} )
1293
            {
1294
                unless ( exists $versions{$e}{DeadWood} || $versions{$e}{badSingleton}  )
1295
                {
1296
#print "--- Project Branch (1) $versions{$e}{vname}\n";
1297
                    $versions{$e}{branchPoint} = 1;
1298
                    $versions{$e}{newSuffix} = 1;
1299
                }
1300
            }
1301
 
1302
            #
1303
            #   Remove those that already have a branch,
1304
            #
1305
            if ( $versions{$e}{branchPoint} || $versions{$e}{newSuffix} || $versions{$e}{DeadWood}  )
1306
            {
1307
                push @ordered, $e;
1308
                delete $nexts{$e};
1309
            }
1310
        }
1311
        #
1312
        #   Select longest arm as the non-branching path
1313
        #   Note: Reverse sort order
1314
        #         Done so that 'newest' item is given preference
1315
        #         to the main trunk in cases where all subtrees are
1316
        #         the same length
1317
        #
1318
        my $maxData = '';
1319
        my $countEntry;
1320
        foreach my $e ( sort {$b <=> $a} keys %nexts )
1321
        {
1322
            if ( $versions{$e}{maxVersion} gt $maxData )
1323
            {
1324
                $maxData = $versions{$e}{maxVersion};
1325
                $countEntry = $e;
1326
            }
1327
        }
1328
        if ($countEntry)
1329
        {
1330
            $main = $countEntry;
1331
            delete $nexts{$countEntry};
1332
        }
1333
 
1334
        #
1335
        #   Append the remaining
1336
        #
1337
        push @ordered, keys %nexts;
1338
 
1339
        #
1340
        #   Re-order 'next' so that the main path is first
1341
        #   Sort (non main) by number
1342
        #
1343
        @ordered = sort {$a <=> $b} @ordered;
1344
        unshift @ordered, $main if ( $main );
1345
        @{$versions{$entry}{next}} = @ordered;
1346
 
1347
        #
1348
        #   Ensure all except the first are a branch point
1349
        #   First may still be a branch point
1350
        #
1351
        shift @ordered;
1352
        foreach my $e ( @ordered )
1353
        {
1354
            $versions{$e}{branchPoint} = 1;
1355
        }
1356
    }
1357
}
1358
 
1359
#-------------------------------------------------------------------------------
1360
# Function        : calcRippleGroups
1361
#
1362
# Description     : Locate and mark ripple groups
1272 dpurdie 1363
#                   packages that are ripples of each other
392 dpurdie 1364
#                       Keep first version of each ripple. Must keep first
1365
#                       Group ripples together so that they can be
1366
#                       proccessed at the same time
1367
#
1368
# Inputs          : 
1369
#
1370
# Returns         : 
1371
#
1372
sub calcRippleGroups
1373
{
1374
    my %rippleVersions;
1375
    foreach my $entry ( keys(%versions) )
1376
    {
1377
        my $ep = $versions{$entry};
1378
        if ( defined $ep->{buildVersion} )
1379
        {
1380
            my $suffix = $ep->{suffix};
1381
            my ($major, $minor, $patch, $build) = @{$ep->{buildVersion}};
1382
#print "--- $major, $minor, $patch, $build, $suffix\n";
1383
            $rippleVersions{$suffix}{"$major.$minor.$patch"}{count}++;
1384
            my $rp = $rippleVersions{$suffix}{"$major.$minor.$patch"};
1385
            $rp->{list}{$entry} = 1;
1386
 
1387
            next if ( $ep->{badVcsTag} );
1388
            next if ( $ep->{locked} eq 'N');
1389
            if (!defined ($rp->{min}) || $rp->{min} > $build )
1390
            {
1391
                $rp->{pvid} = $entry;
1392
                $rp->{min} = $build;
1393
            }
1394
        }
1395
    }
1396
#            DebugDumpData("rippleVersions", \%rippleVersions );
1397
 
1398
    while ( my($suffix, $e1) = each %rippleVersions )
1399
    {
1400
        while ( my( $mmp, $e2) = each %{$e1} )
1401
        {
1402
            next unless ( exists  $e2->{pvid} );
1403
            my $entry = $e2->{pvid};
1404
            if ( !exists $versions{$entry} )
1405
            {
1406
                Error ("Internal: Expected entry not found: $entry, $mmp");
1407
            }
1408
 
1409
            $versions{$entry}{keepLowestRipple} = 1;
1410
#print "--- Keep Riple $versions{$entry}{vname}\n";
1411
 
1412
            #
1413
            #   Update entry with list of associated ripples, removing lowest
1414
            #
1415
            delete $e2->{list}{$entry};
1416
            my @rippleList = sort keys %{$e2->{list}};
1417
            if ( @rippleList)
1418
            {
1419
#DebugDumpData("LIST: $entry", $e2->{list}, \@rippleList  );
1420
                @{$versions{$entry}{rippleList}} = @rippleList;
1421
            }
1422
        }
1423
    }
1424
}
1425
 
1426
#-------------------------------------------------------------------------------
1427
# Function        : processBranch
1428
#
1429
# Description     : Process one complete branch within the tree of versions
1430
#                   May be called recursivly to walk the tree
1431
#
1432
# Inputs          : Array of package-version ID to process
1433
#
1434
# Returns         : Nothing
1435
#
1436
 
1437
sub processBranch
1438
{
1439
    foreach my $entry ( @_ )
1440
    {
1441
        #
1442
        #   Do we need to create a branch before we can process this package
1443
        #
1444
        if ( $versions{$entry}{newSuffix} || $versions{$entry}{branchPoint} )
1445
        {
1446
            newProject();
1447
            $createBranch = 1;
1448
            $createSuffix = 1 if $versions{$entry}{newSuffix};
1449
        }
1450
 
1451
        newPackageVersion( $entry );
1452
no warnings "recursion";
1453
        processBranch (@{$versions{$entry}{next}});
1454
    }
1455
}
1456
 
1457
#-------------------------------------------------------------------------------
1458
# Function        : newPackageVersion
1459
#
1460
# Description     : Create a package version
1461
#
1462
# Inputs          : $entry              - Ref to entry being proccessed
1463
#
1464
# Returns         :
1465
#
1466
sub newPackageVersion
1467
{
1468
    my ($entry) = @_;
1469
    my %data;
1470
    my $flags = 'e';
1471
    my $rv = 1;
1472
    my $startTime = time();
1473
    my $timestamp = localtime;
1474
 
1475
    $data{rmRef} = 'ERROR';
1476
    $data{tag} = 'ERROR';
1477
 
1478
    #
1479
    #   If its been processed then fake that its been done
1480
    #   May have been a ripple that we processed
1481
    #
1270 dpurdie 1482
    return if ($versions{$entry}{Processed});
1483
    $processCount++;
392 dpurdie 1484
    Message ("------------------------------------------------------------------" );
1270 dpurdie 1485
    Message ("Package $processCount of $processTotal");
1486
 
392 dpurdie 1487
    Message ("New package-version: " . GetVname($entry) . " Tag: " . $versions{$entry}{vcsTag} );
1488
 
1328 dpurdie 1489
    #
1490
    #   Detect user abort
1491
    #
1492
    if ( -f $cwd . '/stopfile' )
1493
    {
1494
        $globalError = 1;
1495
        Message ("Stop file located");
1496
    }
392 dpurdie 1497
 
1498
    #
1499
    #   If we have a global error,then we pretend to process, but we
1500
    #   report errors for the logging system
1501
    #
1342 dpurdie 1502
    if ( $globalError )
392 dpurdie 1503
    {
1342 dpurdie 1504
        Message ("Global error prevents futher importation");
1505
    }
1506
    else
1507
    {
392 dpurdie 1508
        #
1509
        #   Call worker function
1510
        #   It will exist on any error so that it can be logged
1511
        #
1512
        $rv = newPackageVersionBody( \%data, @_ );
1513
        $globalError = 1 if ( $rv >= 10 );
1514
    }
1515
 
1516
    #
1517
    #   Highlight essential packages that failed to transfer
1518
    #
1519
    if ( $globalError ) {
1520
        $flags = 'e';
1521
    } elsif ( $rv && ( exists $versions{$entry}{Essential} ) ) {
1522
        $flags = 'X';
1523
    } elsif ( $rv ) {
1524
        $flags = 'E';
1525
    } else {
1526
        $flags = 'G';
1527
    }
1528
 
1529
    #
1530
    #   Always log results to a file
1531
    #   Flags:
1532
    #       e - Error: Global Fatal causes other versions to be ignored
1533
    #       X - Essential Package NOT proccessed
1534
    #       E - Error processing package
1535
    #       G - Good
1536
    #
1537
    my $duration = time() - $startTime;
1538
    my $line = join(';',
1539
            $flags,
1540
            $entry,
1541
            $packageNames,
1542
            $versions{$entry}{vname},
1543
            $data{rmRef},
1544
            $data{tag},
1545
            $timestamp,
1546
            $duration,
1547
            $data{errStr} || ''
1548
            );
1549
    logToFile( $cwd . '/importsummary.txt', ";$line;");
1550
    #
1551
    #   Sava data
1552
    #
1270 dpurdie 1553
    $data{errFlags} = $flags;
1554
    $data{duration} = $duration;
392 dpurdie 1555
    $versions{$entry}{rmRef} = $data{rmRef};
1270 dpurdie 1556
    delete $data{rmRef};
1557
    delete $data{tag};
1340 dpurdie 1558
    ##delete $data{ViewRoot};
1270 dpurdie 1559
    $versions{$entry}{data} = \%data;
1560
 
392 dpurdie 1561
    #
1562
    #   Delete the created view
1563
    #   Its just a directory, so delete it
1564
    #
1565
    if ( $data{ViewRoot} && -d $data{ViewRoot})
1566
    {
1340 dpurdie 1567
        if ( !$opt_reuse || $rv )
1568
        {
1569
            Message ("Delete View: $data{ViewRoot}");
1570
            RmDirTree ($data{ViewRoot} );
1571
        }
1572
        else
1573
        {
1574
            Message ("Retaining View: $data{ViewRoot}");
1575
        }
1576
 
392 dpurdie 1577
    }
1340 dpurdie 1578
    else
1579
    {
1580
        Message ("No view to delete");
1581
    }
392 dpurdie 1582
 
1583
 
1584
    #
1585
    #   If this version has any 'ripples' then process them while we have the
1586
    #   main view. Note the ripple list may contain entries that do not
1587
    #   exist - they will have been pruned.
1588
    #
2029 dpurdie 1589
if(0) {
392 dpurdie 1590
    foreach my $rentry ( @{$versions{$entry}{rippleList}} )
1591
    {
1592
        next unless( exists $versions{$rentry} );
1593
 
1594
        if ($versions{$rentry}{Processed})
1595
        {
1596
            Warning ("Ripple Processed before main entry");
1597
            $versions{$rentry}{rippleProcessed} = 1;
1598
        }
1599
 
1600
        Message ("Proccessing associated Ripple: " . GetVname($rentry));
1601
        newPackageVersion($rentry);
1602
    }
1603
}
2029 dpurdie 1604
}
392 dpurdie 1605
 
1606
#-------------------------------------------------------------------------------
1607
# Function        : newPackageVersionBody
1608
#
1609
# Description     : Perform the bulk of the work in creating a new PackageVersion
1610
#                   Designed to return on error and have error processing
1611
#                   performed by caller
1612
#
1613
# Inputs          : $data               - Shared data
1614
#                   $entry              - Package entry to process
1615
#
1616
# Returns         : Error Code
1617
#                         0 - All is well
1272 dpurdie 1618
#                       <10 - Recoverable error
392 dpurdie 1619
#                       >10 - Fatal error
1620
#
1621
sub newPackageVersionBody
1622
{
1623
    my ($data, $entry) = @_;
1624
    my $rv;
1625
    my $cc_label;
1626
    my $cc_path;
1627
 
1628
    #
1629
    #   Init Data
1630
    #
1631
    $data->{rmRef} = 'ERROR';
1632
    $data->{tag} = '';
1633
    $data->{ViewRoot} = undef;
1634
    $data->{ViewPath} = undef;
1635
    $data->{errStr} = '';
1636
    $versions{$entry}{Processed} = 1;
1637
 
1638
 
1639
    SystemConfig ('ExitOnError' => 0);
1640
 
1641
    push @processOrder, $entry;
1642
    return 0 if ( $opt_test );
1643
 
1644
#   Keep DeadWood. May be a WIP
1645
#    if ( exists $versions{$entry}{DeadWood} && $versions{$entry}{DeadWood} )
1646
#    {
1647
#        $data->{errStr} = 'Package is DeadWood';
1648
#        return 3;
1649
#    }
1650
 
1651
    #
1652
    #   Determine version information
1653
    #
1654
    $data->{tag} = $versions{$entry}{vcsTag} || '';
1655
    if ( $versions{$entry}{badVcsTag} )
1656
    {
1657
        Warning ("Error: Bad VcsTag for: " . GetVname($entry),
1658
                 "Tag: $data->{tag}" );
1659
        $data->{errStr} = 'VCS Tag Marked as Bad';
1660
        return 1;
1661
    }
1662
 
1663
 
1664
    $data->{tag} =~ m~^(.+?)::(.*?)(::(.+))?$~;
1665
    $cc_label = $4;
1666
    $cc_path = $2;
1667
    $cc_path = '/' . $cc_path;
1668
    $cc_path =~ tr~\\/~/~s;
1669
 
1670
    #
1671
    #   Correct well known path mistakes
1672
    #
2312 dpurdie 1673
    $cc_path =~ s~/build.pl$~~i;
1674
    $cc_path =~ s~/src$~~i;
2071 dpurdie 1675
    $cc_path =~ s~/MASS_Dev/Infra/~/MASS_Dev_Infra/~i;
1676
    $cc_path =~ s~/MASS_Dev/Tools/~/MASS_Dev_Tools/~i;
394 dpurdie 1677
    $cc_path =~ s~/MASS_Dev/Bus/~/MASS_Dev_Bus/~i;
392 dpurdie 1678
    $cc_path =~ s~/MASS_Dev_Bus/Cbp/~/MASS_Dev_Bus/CBP/~i;
1679
    $cc_path =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
1197 dpurdie 1680
    $cc_path =~ s~/MREF_21/MREF_Package/~/MREF_Package/~i;
392 dpurdie 1681
 
1197 dpurdie 1682
 
392 dpurdie 1683
#print "--- Path: $cc_path, Label: $cc_label\n";
1684
 
1685
    #
1686
    #   Create CC view
1687
    #   Import into Subversion View
1688
    #
1689
    $data->{ViewRoot} = $opt_name ? $opt_name : "$cc_label";
1197 dpurdie 1690
    $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
1691
 
1692
    if ( $opt_preserveProjectBase )
1693
    {
1694
        my $cc_vob = $cc_path;
1695
        $cc_vob =~ s~^/~~;
1696
        $cc_vob =~ s~/.*~~;
1697
        $data->{ViewPath} =  $data->{ViewRoot} . '/' . $cc_vob;
1698
        Message ("Preserving Project Base");
1699
    }
392 dpurdie 1700
    $data->{ViewPath} =~  tr~/~/~s;
1701
 
1702
    if ( $opt_reuse && -d $data->{ViewPath}  )
1703
    {
1704
        Message ("Reusing view: $cc_label");
1705
    }
1706
    else
1707
    {
1708
        my @args;
1709
        push (@args, '-view', $opt_name ) if ( defined $opt_name );
1710
        $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
1711
                    "-label=$cc_label" ,
1712
                    "-path=$cc_path",
1713
                    @args
1714
                    );
1715
 
1716
        unless ( -d $data->{ViewPath}  )
1717
        {
1718
            $data->{errStr} = 'Failed to extract files from CC';
1719
            return 2;
1720
        }
1721
    }
1722
 
1197 dpurdie 1723
 
392 dpurdie 1724
    #
1197 dpurdie 1725
    #   Some really ugly packages make use of a Jats feature called 'SetProjectBase'
1726
    #   Detect such packages as we will need to handle them differently
1727
    #   Can't really handle it on the fly
1453 dpurdie 1728
    #   All we can do is detect it and report it - at the moment
1197 dpurdie 1729
    #
1730
    if (detectProjectBaseUsage($data, $cc_path) )
1731
    {
1732
        unless ( $opt_ignoreProjectBaseErrors )
1733
        {
1734
            $data->{BadProjectBase}++;
1735
            $data->{errStr} = 'Bad usage of ProjectBase detected';
1736
            return 14;
1737
        }
1738
    }
1739
 
1270 dpurdie 1740
 
1197 dpurdie 1741
    #
1270 dpurdie 1742
    #   Developers have been slack
1743
    #       Sometime the mark the source path as 'GMTPE2005'
1744
    #       Sometimes as 'GMTPE2005/Package/Fred/Jill/Harry'
1745
    #
1746
    #   Attempt to suck up empty directories below the specified
1747
    #   source path
1748
    #
1749
    unless ( $opt_preserveProjectBase )
1750
    {
1751
        #
1752
        #   Look in ViewPath
1753
        #   If it contains only ONE directory then we can suck it up
1754
        #
1755
        my $testDir = findDirWithStuff( $data->{ViewPath} );
1328 dpurdie 1756
 
1270 dpurdie 1757
        unless ( $data->{ViewPath} eq $testDir  )
1758
        {
1759
            Message ("Adjust Base Dir: $testDir");
1760
            $data->{adjustedPath} = $data->{ViewPath};
1761
            $data->{ViewPath} = $testDir;
1762
        }
1763
    }
1764
 
1765
 
1766
    #
392 dpurdie 1767
    #   Have a CC view
1768
    #   Now we can create the SVN package and branching point before we
1769
    #   import the CC data into SVN
1770
    #
1771
    my @args;
1772
 
1773
    #
1774
    #   Calculate args for functions
1775
    #
1776
    my $author = $versions{$entry}{created_id};
1777
    if ( $author )
1778
    {
1779
        push @args, '-author', $author;
1780
    }
1781
    my $created = $versions{$entry}{created};
1782
    if ( $created )
1783
    {
1784
        $created =~ s~ ~T~;
1785
        $created .= '00000Z';
1786
        push @args, '-date', $created;
1787
    }
1788
 
1789
    my $log = $versions{$entry}{comment};
1790
    if ( $log )
1791
    {
1792
        push @args, '-log', $log;
1793
    }
1794
 
1795
    #
1796
    #   Create package skeleton if needed
1797
    #
1798
    $rv = createPackage( $author, $created);
1799
    if ( $rv )
1800
    {
1801
        $data->{errStr} = 'Failed to create Package';
1802
        return 10;
1803
    }
1804
 
1805
    #
1806
    #   Calculate the label for the target package
1807
    #   Use format <packageName>_<PackageVersion>
1808
    #   Need to handle WIPs too.
1809
    #
1810
    my $import_label = saneLabel($entry);
1811
 
1812
    #
1813
    #   May need to create the branchpoint
1814
    #   The process is delayed until its needed so avoid creating unneeded
1815
    #   branch points
1816
    #
1817
    if ( $createBranch )
1818
    {
1819
        $rv = createBranchPoint ($entry, $author, $created);
1820
        $createBranch = 0;
1821
        $createSuffix = 0;
1822
        if ( $rv )
1823
        {
1824
            $data->{errStr} = 'Failed to create Branch Point';
1825
            return 11;
1826
        }
1827
    }
1828
    push @args, "-branch=$currentBranchName" if ( defined $currentBranchName );
1829
 
1830
    my $datafile = "importdata.$import_label.properties";
1831
    $rv = JatsToolPrint ( 'jats_svn', 'import', '-reuse' ,
1832
                    "-package=$svnRepo/$packageNames",
1833
                    "-dir=$data->{ViewPath}",
1834
                    "-label=$import_label",
1835
                    "-datafile=$datafile",
1836
                    @args,
1837
                     );
1838
 
1839
    if ( $rv )
1840
    {
1841
        $data->{errStr} = 'Failed to import to SVN';
1842
        return 12;
1843
    }
1844
 
1845
    $versions{$entry}{TagCreated} = 1;
1846
    $firstVersionCreated = $entry unless ( $firstVersionCreated );
1847
 
1848
    #
1849
    #   Read in the Rm Reference
1850
    #   Retain entries in a global file
1851
    #
1852
    if ( -f $datafile  )
1853
    {
1854
        my $rmData = JatsProperties::New($datafile);
1855
        $data->{rmRef} = 'SVN::' . $rmData->getProperty('subversion.tag');
1856
    }
1857
 
1858
    unless ( $data->{rmRef}  )
1859
    {
1272 dpurdie 1860
        $data->{errStr} = 'Failed to determine Rm Reference';
392 dpurdie 1861
        return 13;
1862
    }
1863
 
1380 dpurdie 1864
######################## Deleted ###############################################
1865
#
1866
#
1867
#    #
1868
#    #   Add supplemental tags if this version is in a 'Release'
1869
#    #   But only for some packages - else looks like a mess
1870
#    #   Just a solution for the ITSO guys
1871
#    #
1872
#    foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  )
1873
#    {
1874
#        next unless ( $svnRepo =~ m~/ITSO_TRACS(/|$)~);
1875
#
1876
#        my $prog_id = $versions{$entry}{Releases}{$rtag_id}{proj_id};
1877
#        Message ("Adding Release Tag:$prog_id:$rtag_id");
1878
#
1879
#        my $rtext = 'Release_' . saneString($versions{$entry}{Releases}{$rtag_id}{rname});
1880
#        my @comment;
1881
#        push @comment, "Tagged by ClearCase to Subversion import";
1882
#        push @comment, "Project:$prog_id:$versions{$entry}{Releases}{$rtag_id}{pname}";
1883
#        push @comment, "Release:$rtag_id:$versions{$entry}{Releases}{$rtag_id}{rname}";
1884
#
1885
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{name} = $rtext;
1886
#
1887
#        $rv = JatsToolPrint ( 'jats_svnlabel' ,
1888
#                    '-comment', encode('UTF-8', join("\n", @comment), Encode::FB_DEFAULT),
1889
#                    $data->{rmRef},
1890
#                    '-clone',
1891
#                    $rtext,
1892
##                    @args,
1893
#                    '-author=buildadm',
1894
#                     );
1895
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{eState} = $rv;
1896
#        $data->{ReleaseTag}{tCount}++;
1897
#
1898
#        if ( $rv )
1899
#        {
1900
#            $data->{ReleaseTag}{eCount}++;
1901
#            Warning("Failed to add Release Tag: $rtext");
1902
#        }
1903
#    }
1904
#
1905
######################## Deleted ###############################################
1341 dpurdie 1906
 
392 dpurdie 1907
    Message ("RM Ref: $data->{rmRef}");
1908
    unlink $datafile;
1909
 
1910
    #
1911
    #   All is good
1912
    #
1913
    $data->{errStr} = '';
1914
    return 0;
1915
}
1916
 
1917
 
1918
#-------------------------------------------------------------------------------
1919
# Function        : newProject
1920
#
1921
# Description     : Start a new project within a package
1922
#
1923
# Inputs          : 
1924
#
1925
# Returns         : 
1926
#
1927
sub newProject
1928
{
1929
#    Message ("---- New Project");
1930
    $createSuffix = 0;
1931
 
1932
    #
1933
    #   New project
1934
    #   Kill the running import directory
1935
    #
1936
    RmDirTree ('SvnImportDir');
1937
}
1938
 
1939
#-------------------------------------------------------------------------------
1940
# Function        : newPackage
1941
#
1942
# Description     : Start processing a new package
1943
#
1944
# Inputs          : 
1945
#
1946
# Returns         : 
1947
#
1948
my $createPackageDone;
1949
sub newPackage
1950
{
1951
#    Message( "---- New Package");
1952
 
1953
    #
1954
    #   Create a package specific log file
1955
    #
1956
    $logSummary = $packageNames . ".summary.log";
1957
    unlink $logSummary;
1958
    Message( "PackageName: $packageNames");
1959
    $createPackageDone = 1;
1960
    $createBranch = 0;
1961
    $createSuffix = 0;
1962
 
1963
    #
1964
    #   First entry being created
1965
    #   Prime the work area
1966
    #
1967
    RmDirTree ('SvnImportDir');
1968
}
1969
 
1970
#-------------------------------------------------------------------------------
1971
# Function        : createPackage
1972
#
1973
# Description     : Create a new Package in SVN
1974
#                   Called before any serious SVN operation to ensure that the
1975
#                   package has been created. Don't create a package until
1976
#                   we expect to put something into it.
1977
#
1978
#                   Will only create a package once
1979
 
1980
#
1981
# Inputs          : $author         - Who done it
1982
#                   $date           - When
1983
#
1984
# Returns         : 
1985
#
1986
sub createPackage
1987
{
1988
    my ($author, $date) = @_;
1989
    my @opts;
1990
    push (@opts, '-date', $date) if ( $date );
1991
    push (@opts, '-author', $author) if ( $author );
1992
    #
1993
    #   Only do once
1994
    #
1995
    return unless ( $createPackageDone );
1996
    $createPackageDone = 0;
1997
 
1197 dpurdie 1998
    #
1999
    #   Real import
2000
    #       Do not Delete package if it exists
2001
    #       Package must NOT exist
2002
    #
392 dpurdie 2003
    Message ("Creating new SVN package: $packageNames");
1270 dpurdie 2004
    if ( $opt_delete )
2005
    {
2006
        Message ("Delete existing version of package: $packageNames");
2007
        JatsToolPrint ( 'jats_svn', 'delete-package', '-noerror',  "$svnRepo/$packageNames" );
2008
    }
1197 dpurdie 2009
    JatsToolPrint ( 'jats_svn', 'create', "$svnRepo/$packageNames", '-new', @opts );
392 dpurdie 2010
}
2011
 
2012
 
2013
#-------------------------------------------------------------------------------
2014
# Function        : createBranchPoint
2015
#
2016
# Description     : Create a branch point for the current work
2017
#                   Perform the calculation to determine the details of
2018
#                   the branch point. The work will only be done when its
2019
#                   needed. This will avoid the creation of branchpoints
2020
#                   that are not used.
2021
#
2022
# Inputs          : $entry                  Entry being processed
2023
#                   $author         - Who done it
2024
#                   $date           - When
2025
#
2026
# Returns         : 
2027
#
2028
sub createBranchPoint
2029
{
2030
    my ($entry, $author, $date) = @_;
2031
    my $forceNewProject;
2032
 
2033
#    Message ("---- Create Branch Point");
2034
 
2035
    #
2036
    #   Find previous good tag
2037
    #   We are walking a tree so something should have been created, but
2038
    #   the one we want may have had an error
2039
    #
2040
    #   Walk backwards looking for one that has been created
2041
    #
2042
    my $last = $versions{$entry}{last};
2043
    while ( $last )
2044
    {
2045
        unless ( $versions{$last}{TagCreated} )
2046
        {
2047
            $last = $versions{$last}{last};
2048
        }
2049
        else
2050
        {
2051
            last;
2052
        }
2053
    }
2054
 
2055
    #
2056
    #   If we have walked back to the base of the tree
2057
    #   If we transferred any software at all, then use the first
2058
    #   version as the base for this disconnected version
2059
    #
2060
    #   Otherwise we create a new, and empty, view
2061
    #
2062
    unless ( $last )
2063
    {
2064
        if ( $firstVersionCreated )
2065
        {
2066
            Warning ("Cannot find previous version to branch. Use first version");
2067
            $last = $firstVersionCreated;
2068
        }
2069
        else
2070
        {
2071
            Warning ("Forcing First instance of a Project");
2072
            $forceNewProject = 1;
2073
        }
2074
    }
2075
 
2076
    #
2077
    #   Determine source name
2078
    #   This MUST have been created before we can branch
2079
    #
2080
    my $src_label;
2081
    $src_label = saneLabel($last) if $last;
2082
 
2083
    #
2084
    #   Create target name
2085
    #
2086
    my $tgt_label;
2087
    if ( $forceNewProject || $versions{$entry}{newSuffix} || $createSuffix || !defined $src_label )
2088
    {
2089
        #
2090
        #   Create target name based on project
2091
        #
2092
        return if ( $singleProject );
2093
 
2094
        my $suffix = $versions{$entry}{suffix};
2095
        if ( $suffix )
2096
        {
2097
            Error ("Unknown Project: $suffix") unless ( defined $Projects{$suffix} );
2098
 
2099
            #
2100
            #   If this project can be considered to be a truck, then 'claim' the
2101
            #   truck for the first created element.
2102
            #
2103
            if ( $Projects{$suffix}{Trunk} )
2104
            {
2105
                # This project can use the trunk, if it has not been allocated.
2106
                $ProjectTrunk = $suffix unless ( defined $ProjectTrunk );
2107
 
2108
                #
2109
                #   If this package has multiple instances of the potential
2110
                #   trunk, then don't place either of them on the trunk as it
2111
                #   may cause confusion
2112
                #
2113
                if ($knownProjects{$suffix}{count} < 2 )
2114
                {
2115
                    if ( $suffix eq $ProjectTrunk )
2116
                    {
2117
                        return unless $currentBranchName;
2118
                    }
2119
                }
2120
            }
2121
 
2122
            $tgt_label = $Projects{$suffix}{Name};
2123
            $tgt_label = $versions{$entry}{name} . '_' . $tgt_label if ($multiPackages);
2124
            if ( !exists $ProjectsBaseCreated{$tgt_label}  )
2125
            {
2126
                $ProjectsBaseCreated{$tgt_label} = 1;
2127
            }
2128
            else
2129
            {
2130
                #   Project Base Already taken
2131
                #   Have disjoint starting points
2132
                $tgt_label .= '.' . $ProjectsBaseCreated{$tgt_label} ++;
2133
            }
2134
        }
2135
        else
2136
        {
2137
            #
2138
            #   No suffix in use
2139
            #
2140
            #   Currently not handled
2141
            #   May have to force the use of the trunk
2142
            #
2143
            Error ("INTERNAL ERROR: No suffix present");
2144
        }
2145
    }
2146
    else
2147
    {
2148
        $tgt_label = saneLabel($entry, $src_label . '_for_');
2149
    }
2150
 
2151
    #
2152
    #   Save branch name for use when populating sandbox
2153
    #
2154
    $currentBranchName = $tgt_label;
2155
 
2156
    #
2157
    #   Perform the branch
2158
    #
2159
    if ( defined $src_label )
2160
    {
1328 dpurdie 2161
        #
1341 dpurdie 2162
        #   The 'clone' operation will backtrack the branch point
2163
        #   to the source of the label. This will make the output version
2164
        #   tree much prettier
1328 dpurdie 2165
        #
392 dpurdie 2166
        my @opts;
2167
        push (@opts, '-date', $date) if ( $date );
2168
        push (@opts, '-author', $author) if ( $author );
2169
 
2170
        JatsToolPrint ( 'jats_svnlabel',
2171
                        '-packagebase', "$svnRepo/$packageNames",
1341 dpurdie 2172
                        'tags/' . $src_label,
392 dpurdie 2173
                        '-branch',
2174
                        '-clone', $tgt_label,
2175
                        @opts
2176
                      );
2177
    }
2178
}
2179
 
2180
 
2181
#-------------------------------------------------------------------------------
2182
# Function        : endPackage
2183
#
2184
# Description     : End of package processing
2185
#                   Clean up and display problems
2186
#
2187
# Inputs          : 
2188
#
2189
# Returns         : 
2190
#
2191
sub endPackage
2192
{
2193
    RmDirTree ('SvnImportDir');
2194
 
2195
    #
2196
    #   Display versions that did get captured
2197
    #
2198
    foreach my $entry ( @processOrder )
2199
    {
2200
        $versions{$entry}{Scanned} = 1;
2201
        next unless ( $versions{$entry}{TagCreated} );
2202
        Warning ("Processed: " . GetVname($entry) . ' :: ' . $versions{$entry}{rmRef} || $versions{$entry}{errStr} || '???' );
2203
    }
2204
 
2205
    #
2206
    #   Display versions that did not get created
2207
    #
2208
    foreach my $entry ( @processOrder )
2209
    {
2210
        $versions{$entry}{Scanned} = 1;
2211
        next if ( $versions{$entry}{TagCreated} );
2212
        Warning ("Not Processed: " . GetVname($entry) );
2213
    }
2214
 
2215
    foreach my $entry ( keys(%versions) )
2216
    {
2217
        next if ( $versions{$entry}{Scanned} );
2218
        Warning ("(E) INTERNAL ERROR. Package Not Processed: " . GetVname($entry) );
2219
    }
2220
 
2221
    Message ("All Done");
2222
}
2223
 
1197 dpurdie 2224
#-------------------------------------------------------------------------------
2225
# Function        : detectProjectBaseUsage
2226
#
2227
# Description     : Detect and report usage of the SetProjectBase directive
2228
#
2229
# Inputs          : $data               - Ref to a hash of bits
2230
#                   $cc_path            - Packages cc_path
2231
#
2232
# Returns         : true    - Bad usage (Really good usage not detected)
2233
#                   false   - Good usage detected
2234
#
2235
sub detectProjectBaseUsage
2236
{
2237
    my ($data, $cc_path) = @_;
2238
    my $retval = 0;
2239
    my $eSuf = $opt_ignoreProjectBaseErrors ? '' : 'Error';
2240
 
2241
    #
2242
    #   Find makefile.pl
2243
    #
2244
    Message ("Locate JATS makefiles");
2245
    my $usesProjectBase = 0;
2246
    my $definesProjectBase = 0;
2247
    my $definitionError = 0;
2248
 
2249
    my $search = JatsLocateFiles->new("--Recurse=1",
2250
                                       "--FilterIn=makefile.pl",
2251
                                       );
2252
    my @makefiles = $search->search($data->{ViewRoot});
2253
    foreach my $file ( @makefiles )
2254
    {
2255
        if ( open( my $fh, '<', "$data->{ViewRoot}/$file" ) )
2256
        {
2257
            while ( <$fh> )
2258
            {
2259
                s~\s+$~~;
2260
                s~^\s+~~;
2261
                next if ( m~^#~ );
2262
 
2263
                if ( m~\$ProjectBase~ )
2264
                {
2265
                    $usesProjectBase++;
2266
                    Message ("Project Base Use: $_");
2267
                    $data->{UsesProjectBase}++;
2268
                }
2269
 
2270
                if ( m~^SetProjectBase~ )
2271
                {
2272
                    $definesProjectBase++;
2273
                    $data->{DefinesProjectBase}++;
2312 dpurdie 2274
                    Warning ("Package initialises SetProjectBase:",
1197 dpurdie 2275
                             "Line: " . $_,
2276
                             "Root: " . "$data->{ViewRoot}",
2277
                             "File: " . "$data->{ViewRoot}/$file",
2278
                            );
2279
 
2280
                    # The only problem is if the user attempts to escape
2281
                    # from the root of the view.
2282
                    #
2283
                    # Examine the depth of the makefile with the directive
2284
                    # Examine the depth of the view base
2285
                    #
2286
                    #
2287
                    # Locate the build.pl file
2288
                    # This is the basis for for the directive
2289
                    #
2290
                    my $blevel;
2291
                    my @bpaths = split ('/', $file );
2292
                    while ( @bpaths )
2293
                    {
2294
                        $bpaths[-1] = 'build.pl';
2295
                        my $bfile = join '/', @bpaths ;
2296
                        if ( -f "$data->{ViewRoot}/$bfile" )
2297
                        {
2298
                            $blevel = scalar @bpaths;
2299
                            last;
2300
                        }
2301
                        pop @bpaths;
2302
                    }
2303
                    unless (defined $blevel)
2304
                    {
2305
                        Warning ("SetProjectBase$eSuf calculation failed - can't find build.pl");
2312 dpurdie 2306
#                        $retval = 1;
2307
                         $definitionError++;
1197 dpurdie 2308
                    }
2309
                    else
2310
                    {
2311
                        #
2312
                        #   Determine the depth of the view root
2313
                        #   This is given by cc_path, but cc_path has a leading /
2314
                        #
2315
                        my @cpaths = split ('/', $cc_path );
2316
                        my $clevel = (scalar @cpaths) - 1;
2317
                        my $max_up = $blevel - $clevel - 1;
2318
 
2319
                        m~--Up=(\d+)~i;
2320
                        my $ulevel = $1;
2321
                        if ( defined $ulevel )
2322
                        {
2323
                            my @paths = split ('/', $file );
2324
                            my $plevel = scalar @paths;
2325
 
2326
#print "--- blevel: $blevel\n";
2327
#print "--- bpaths: @bpaths\n";
2328
#print "--- ulevel: $ulevel\n";
2329
#print "--- paths: @paths\n";
2330
#print "--- plevel: $plevel\n";
2331
#print "--- cpaths: @cpaths\n";
2332
#print "--- clevel: $clevel\n";
2333
#print "--- max_up: $max_up\n";
2334
 
2335
                            if ( $ulevel > $max_up )
2336
                            {
2337
                                Warning ("SetProjectBase escapes view. MaxUp: $max_up, Up: $ulevel");
2338
                                $definitionError++;
2339
                            }
2340
                        }
2341
                        else
2342
                        {
2343
                            $retval = 1;
2344
                            Warning ("SetProjectBase$eSuf MAY escape view - can't detect level")
2345
                        }
2346
                    }
2347
                }
2348
            }
2349
            close $fh;
2350
        }
2351
        else
2352
        {
2353
            Warning ("SetProjectBase$eSuf - Cannot open makefile: $file");
2354
            $retval = 1;
2355
        }
2356
    }
2357
 
2358
    #
2359
    #   Detect defined, but not used
2360
    #
2361
    if ( $usesProjectBase && ! $definesProjectBase )
2362
    {
2363
        Warning ("SetProjectBase - Uses ProjectBase without defining it");
2364
    }
2365
 
2366
    if ( ! $usesProjectBase && $definesProjectBase )
2367
    {
2368
        Warning ("SetProjectBase - Defines ProjectBase without using it");
2369
    }
2370
 
2371
    if ( $usesProjectBase && $definesProjectBase && $definitionError )
2372
    {
2373
        Warning ("SetProjectBase$eSuf - Problem detected");
2374
        $retval = 1;
2375
    }
2376
    return $retval;
2377
}
2378
 
1270 dpurdie 2379
#-------------------------------------------------------------------------------
2380
# Function        : findDirWithStuff
2381
#
2382
# Description     : Find a directory that contains more than just another subdir
2383
#
2384
# Inputs          : $base               - Start of the scan
2385
#
2386
# Returns         : Path to dir with more than just a single dir in it
2387
#
2388
sub findDirWithStuff
2389
{
2390
    my ($base) = @_;
1197 dpurdie 2391
 
1270 dpurdie 2392
    while ( $base )
2393
    {
2394
    my $fileCount = 0;
2395
    my $dirCount = 0;
1272 dpurdie 2396
    my $firstDir;
1270 dpurdie 2397
 
2398
    my @list = glob( $base . '/*');
2399
    foreach ( @list )
2400
    {
2401
        next if ( $_ eq '.' );
2402
        next if ( $_ eq '..' );
2403
        if ( -d $_ )
2404
        {
2405
            $dirCount++;
1272 dpurdie 2406
            $firstDir = $_ unless ( defined $firstDir );
1270 dpurdie 2407
            return $base if ( $dirCount > 1  );
2408
        }
1272 dpurdie 2409
        elsif ( -e $_ )
1270 dpurdie 2410
        {
2411
            return $base;
2412
        }
1272 dpurdie 2413
 
2414
        # else its probably a dead symlink
1270 dpurdie 2415
    }
2416
    return $base unless ( $dirCount == 1  );
1272 dpurdie 2417
    $base = $firstDir;
1270 dpurdie 2418
    }
2419
}
2420
 
2421
 
1197 dpurdie 2422
#-------------------------------------------------------------------------------
2423
# Function        : JatsToolPrint
2424
#
2425
# Description     : Print and Execuate a JatsTool command
2426
#
2427
# Inputs          : 
2428
#
2429
# Returns         : 
2430
#
2431
 
392 dpurdie 2432
sub JatsToolPrint
2433
{
2434
    Information ("Command: @_");
2435
    JatsTool @_;
2436
}
2437
 
2438
sub GetVname
2439
{
2440
    my ($entry) = @_;
2441
    my $me = 'NONE';
2442
    if ( $entry )
2443
        {
2444
        $me = $versions{$entry}{vname};
2445
        unless ( $me )
2446
        {
2447
            $me = 'Unknown-' . $entry;
2448
        }
2449
    }
2450
    return $me;
2451
}
2452
 
2453
sub saneLabel
2454
{
2455
    my ($entry, $pkgname) = @_;
1272 dpurdie 2456
    my $me;
2457
    $me = $versions{$entry}{vname};
392 dpurdie 2458
    $pkgname = $versions{$entry}{name} unless ( defined $pkgname );
2459
 
2460
    Error ("Package does have a version string: pvid: $entry")
2461
        unless ( defined $me );
2462
 
2463
    #
2464
    #   Convert Wip format (xxxx) into a string that can be used for a label
2465
    #
2466
    if ( $me =~ m~^(.*)\((.*)\)(.*)$~ )
2467
    {
2468
        $me = $1 . '_' . $2 . '_' . $3 . '.WIP';
2469
        $me =~ s~_\.~.~;
2470
        $me =~ s~^_~~;
2471
    }
2472
 
2473
    #
2474
    #   Allow for WIPS
2475
    #   Get rid of multiple '_'
2476
    #   Replace space with -
2477
    #
2478
    $me = $pkgname . '_' . $me;
2479
    $me =~ tr~ ~-~s;
2480
    $me =~ tr~-~-~s;
2481
    $me =~ tr~_~_~s;
2482
 
2483
    return $me;
2484
}
2485
 
1341 dpurdie 2486
sub saneString
2487
{
2488
    my ($string) = @_;
2489
    #
2490
    #   Get rid of multiple '_'
2491
    #   Replace space with -
2492
    #
2493
    $string =~ s~\W~_~g;
2494
    $string =~ tr~ ~_~s;
2495
    $string =~ tr~_-~-~s;
2496
    $string =~ tr~-_~-~s;
2497
    $string =~ tr~-~-~s;
2498
    $string =~ tr~_~_~s;
2499
    $string =~ s~-$~~;
2500
    $string =~ s~_$~~;
392 dpurdie 2501
 
1341 dpurdie 2502
    return $string;
2503
}
2504
 
2505
 
392 dpurdie 2506
exit 0;
2507
 
2508
 
2509
#-------------------------------------------------------------------------------
2510
# Function        : GetPkgIdByName
2511
#
2512
# Description     :
2513
#
2514
# Inputs          : pkg_name
2515
#
2516
# Returns         : pkg_id
2517
#
2518
sub GetPkgIdByName
2519
{
2520
    my ( $pkg_name ) = @_;
2521
    my (@row);
2522
    my $pv_id;
2523
    my $pkg_id;
2524
 
2525
    #
2526
    #   Establish a connection to Release Manager
2527
    #
2528
    connectRM(\$RM_DB) unless ( $RM_DB );
2529
 
2530
    #
2531
    #   Extract data from Release Manager
2532
    #
2533
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
2534
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
2535
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
2536
 
2537
    my $sth = $RM_DB->prepare($m_sqlstr);
2538
    if ( defined($sth) )
2539
    {
2540
        if ( $sth->execute( ) )
2541
        {
2542
            if ( $sth->rows )
2543
            {
2544
                while ( @row = $sth->fetchrow_array )
2545
                {
2546
                    Verbose( "DATA: " . join(',', @row) );
2547
                    $pkg_id = $row[1] || 0;
2548
                    last;
2549
                }
2550
            }
2551
            else
2552
            {
2553
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
2554
            }
2555
            $sth->finish();
2556
        }
2557
    }
2558
    else
2559
    {
2560
        Error("GetPkgIdByName:Prepare failure" );
2561
    }
2562
 
2563
    return $pkg_id;
2564
}
2565
 
2566
#-------------------------------------------------------------------------------
2567
# Function        : GetData_by_pkg_id
2568
#
2569
# Description     :
2570
#
2571
# Inputs          : pv_id
2572
#
2573
# Returns         :
2574
#
2575
sub GetData_by_pkg_id
2576
{
2577
    my ( $pkg_id, $packageName ) = @_;
2578
    my (@row);
2579
 
2580
    #
2581
    #   Establish a connection to Release Manager
2582
    #
2583
    Message ("Extract package versions from Release Manager: $packageName");
2584
    connectRM(\$RM_DB) unless ( $RM_DB );
2585
 
2586
    #
2587
    #   Extract data from Release Manager
2588
    #
2589
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pv.PKG_VERSION, pkg.PKG_ID, pv.PV_ID, pv.LAST_PV_ID, pv.MODIFIED_STAMP, release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), amu.USER_NAME, pv.COMMENTS, pv.DLOCKED, pv.CREATOR_ID ".
2590
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, ACCESS_MANAGER.USERS amu" .
2591
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID AND amu.USER_ID (+) = pv.CREATOR_ID";
2592
 
2593
 
2594
    my $sth = $RM_DB->prepare($m_sqlstr);
2595
    if ( defined($sth) )
2596
    {
2597
        if ( $sth->execute( ) )
2598
        {
2599
            if ( $sth->rows )
2600
            {
2601
                while ( @row = $sth->fetchrow_array )
2602
                {
2603
                    Verbose( "DATA: " . join(',', @row) );
2604
                    my $pkg_name = $row[0] || 'Unknown';
2605
                    my $pkg_ver = $row[1] || 'Unknown';
2606
                       $pkg_ver =~ s~\s+$~~;
2607
                       $pkg_ver =~ s~^\s+~~;
2608
                    my $pv_id = $row[3] || 'Unknown';
2609
                    my $last_pv_id = $row[4];
2610
                    my $created =  $row[5] || 'Unknown';
2611
                    my $vcstag =  $row[6] || 'Unknown';
395 dpurdie 2612
 
392 dpurdie 2613
                    my $created_id =  $row[7] || ($row[10] ? "Userid_$row[10]" :'Unknown');
2614
                    my $comment =  $row[8] || '';
2615
                    my $locked =  $row[9] || 'N';
2616
 
2617
                    #
2618
                    #   Some developers have a 'special' package version
2619
                    #   We really need to ignore them
2620
                    #
2621
                    next if ( $pkg_ver eq '23.23.23.ssw' );
2622
 
2623
                    #
2624
                    #   Add data to the hash
2625
                    #       Remove entries that address themselves
2626
                    #
2627
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id || $last_pv_id == 0) ;
2628
                    $versions{$pv_id}{name} = $pkg_name;
2629
                    $versions{$pv_id}{pvid} = $pv_id;
2630
                    $versions{$pv_id}{vname} = $pkg_ver;
2631
                    $versions{$pv_id}{vcsTag} = $vcstag;
2632
                    $versions{$pv_id}{created} = $created;
2633
                    $versions{$pv_id}{created_id} = $created_id;
2634
                    $versions{$pv_id}{comment} = $comment;
2635
                    $versions{$pv_id}{locked} = $locked;
2636
                    $versions{$pv_id}{TimeStamp} = str2time( $created );
2637
                    $versions{$pv_id}{Age} = ($now - $versions{$pv_id}{TimeStamp}) / (60 * 60 * 24);
2638
                    $versions{$pv_id}{TooOld} = 1 if ( $opt_age && $opt_age <= $versions{$pv_id}{Age} );
2639
                    examineVcsTag($pv_id);
2640
 
2641
                    #
2642
                    #   Process version number
2643
                    #
2644
                    my ($suffix, $version, $isaR, $isaWip, $buildVersion ) = massageVersion($pkg_ver, $pkg_name);
2645
 
2646
                    $versions{$pv_id}{version} = $version;
2647
                    $versions{$pv_id}{buildVersion} = $buildVersion;
2648
                    $versions{$pv_id}{isaRipple} = 1 if ( $isaR );
2649
                    $versions{$pv_id}{isaWip} = 1 if ( $isaWip );
2650
 
2651
                    #
2652
                    #   Process suffix
2653
                    #
2654
                    $suffix = 'Unknown' unless ( $suffix );
2655
                    $suffix = lc ($suffix);
2656
                    $versions{$pv_id}{suffix} = $suffix;
2657
                    push @{$suffixes{$suffix}}, $pv_id;
2658
 
2659
#                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $locked, $created, $created_id, $suffix\n";
2660
                }
2661
            }
2662
            else
2663
            {
2664
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
2665
            }
2666
            $sth->finish();
2667
        }
2668
        else
2669
        {
2670
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
2671
        }
2672
    }
2673
    else
2674
    {
2675
        Error("GetData_by_pkg_id:Prepare failure" );
2676
    }
2677
}
2678
 
2679
#-------------------------------------------------------------------------------
2680
# Function        : massageVersion
2681
#
2682
# Description     : Process a version number and return usful bits
2683
#
2684
# Inputs          : Version Number
2685
#                   Package Name - debug only
2686
#
2687
# Returns         : An array
2688
#                       suffix
2689
#                       multipart version string useful for text comparisons
2690
#
2691
sub massageVersion
2692
{
2693
    my ($version, $name) = @_;
2694
    my ($major, $minor, $patch, $build, $suffix);
2695
    my $result;
2696
    my $buildVersion;
2697
    my $isaRipple;
2698
    my $isaWIP;
2699
    $build = 0;
2700
 
2701
#print "--- $name, $version\n";
2702
    $version =~ s~^_~~;
2703
    $version =~ s~^${name}_~~;
2704
 
2705
    #
2706
    #   xxxxxxxxx.nnnn.cots
2707
    #
2708
    if ( $version =~ m~(.*)\.cots$~ ) {
2709
        my $cots_base = $1;
2710
        $suffix = '.cots';
2711
        if ( $version =~ m~(.*?)\.([0-9]{4})\.cots$~ )
2712
        {
2713
            $result = $1 . sprintf (".%4.4d", $2) . $suffix;
2714
        }
2715
        else
2716
        {
2717
            $result = $cots_base . '.0000.cots';
2718
        }
2719
    }
2720
    #
2721
    #   Convert version into full form for comparisions
2722
    #       nnn.nnn.nnn.[p]nnn.xxx
2723
    #       nnn.nnn.nnn.[p]nnn-xxx
2724
    #       nnn.nnn.nnn-[p]nnn.xxx
2725
    #       nnn.nnn.nnn-[p]nnn-xxx
2726
    #       nnn.nnn.nnn[p]nnn-xxx
2727
    #   Don't flag as ripples - they are patches
2728
    #
2729
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-.p][p]?(\d+)([-.](.*))?$~ ) {
2730
        $major = $1;
2731
        $minor = $2;
2732
        $patch = $3;
2733
        $build = $4;
2734
        $suffix = defined $6 ? ".$6" : '';
2735
        $isaRipple = 0;
2736
    }
2737
    #
2738
    #       nn.nnn.nnnnn.xxx
2739
    #       nn.nnn.nnnnn-xxx
2740
    #       nnn.nnn.nnnx.xxx
2741
    #   Don't flag as ripples - they are patches
2742
    #
2743
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)\w?([-.](.*))?$~ ) {
2744
        $major = $1;
2745
        $minor = $2;
2746
        $patch = $3;
2747
        if ( length( $patch) >= 4 )
2748
        {
2749
            $build = substr( $patch, -3 ,3);
2750
            $patch = substr( $patch,  0 ,length($patch)-3);
2751
        }
2752
        $suffix = defined $5 ? ".$5" : '';
2753
    }
2754
 
2755
    #
2756
    #       nnn.nnn.nnn
2757
    #       nnn.nnn-nnn
2758
    #       nnn.nnn_nnn
2759
    #
2760
    elsif ( $version =~ m~^(\d+)\.(\d+)[-._](\d+)$~ ) {
2761
        $major = $1;
2762
        $minor = $2;
2763
        $patch = $3;
2764
        $suffix = '';
2765
    }
2766
 
2767
    #
2768
    #       nnn.nnn.nnn.nnn
2769
    #       nnn.nnn.nnn-nnn
2770
    #       nnn.nnn.nnn_nnn
2771
    #
2772
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-._](\d+)$~ ) {
2773
        $major = $1;
2774
        $minor = $2;
2775
        $patch = $3;
2776
        $build = $4;
2777
        $suffix = '';
2778
        $isaRipple = 0;
2779
    }
2780
 
2781
 
2782
    #
2783
    #       nnn.nnn
2784
    #
2785
    elsif ( $version =~ m~^(\d+)\.(\d+)$~ ) {
2786
        $major = $1;
2787
        $minor = $2;
2788
        $patch = 0;
2789
        $suffix = '';
2790
    }
2791
    #
2792
    #       nnn.nnn.xxx
2793
    #
2794
    elsif ( $version =~ m~^(\d+)\.(\d+)(\.\w+)$~ ) {
2795
        $major = $1;
2796
        $minor = $2;
2797
        $patch = 0;
2798
        $suffix = $3;
2799
    }
2800
 
2801
    #
2802
    #       nnn.nnn.nnnz
2803
    #
2804
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)([a-z])$~ ) {
2805
        $major = $1;
2806
        $minor = $2;
2807
        $patch = $3;
2808
        $build = ord($4) - ord('a');
2809
        $suffix = '.cots';
2810
        $isaRipple = 0;
2811
    }
2812
    #
2813
    #       ???REV=???
2814
    #
2815
    elsif ( $version =~ m~REV=~ ) {
2816
        $suffix = '.cots';
2817
        $result = $version . '.0000.cots';
2818
    }
2819
 
2820
    #
2821
    #   Wip Packages
2822
    #   (nnnnnn).xxx
2823
    #   Should be essential, but want to sort very low
2824
    #
2825
    elsif ($version =~ m~\((.*)\)(\..*)?~) {
2826
        $suffix = $2 || '';
2827
        $result = "000.000.000.000$suffix";
2828
        $isaWIP = 1;
2829
    }
2830
 
2831
    #
2832
    #   !current
2833
    #
2834
    elsif ($version eq '!current' || $version eq 'current_$USER' || $version eq 'current' || $version eq 'beta' || $version eq 'latest' || $version eq 'beta.cr' || $version eq 'CREATE') {
2835
        $suffix = '';
2836
        $result = "000.000.000.000$suffix";
2837
        $isaWIP = 1;
2838
    }
2839
 
2840
    #
2841
    #   Also WIP: FINRUN.103649.BEI.WIP
2842
    elsif ($version =~ m~(\.[a-zA-Z]+)\.WIP$~) {
2843
        $suffix = lc($1);
2844
        $result = "000.000.000.000$suffix";
2845
        $isaWIP = 1;
2846
    }
2847
 
2848
    #
2849
    #   Also ERGOFSSLS190100_015
2850
    #   Don't flag as a ripple
2851
    elsif ($version =~ m~^ERG[A-Z]+(\d\d)(\d\d)(\d\d)[-_](\d+)(\.\w+)?$~) {
2852
        $major = $1;
2853
        $minor = $2;
2854
        $patch = $3;
2855
        $build = $4;
2856
        $suffix = $5 || '.sls';
2857
        $isaRipple = 0;
2858
    }
2859
 
2860
    #
2861
    #   Stuff we don't yet handle
2862
    #
2863
    else  {
2864
        Warning ("Unknown version number: $name,$version");
2865
        $version =~ m~(\.\w+)$~;
2866
        $suffix = $1 || '';
2867
        $result = $version;
2868
    }
2869
 
2870
    $isaRipple = ($build > 0) unless defined $isaRipple;
2871
    unless ( $result )
2872
    {
2873
        # Major and minor of 99.99 are normally funy versions
2874
        # Don't make important desicions on them
2875
        #
2876
        if ( $major == 99 && $minor == 99 )
2877
        {
2878
            $major = 0;
2879
            $minor = 0;
2880
            $patch = 0;
2881
        }
2882
 
2883
        $result = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $major,$minor,$patch,$build,$suffix || '.0000');
2884
        $buildVersion = [ $major, $minor, $patch, $build ];
2885
    }
2886
 
2887
    $suffix = lc( $suffix );
2888
    if ( exists $suffixFixup{$suffix} )
2889
    {
2890
        $suffix = $suffixFixup{$suffix} ;
2891
    }
2892
 
2893
    return ($suffix, $result, $isaRipple, $isaWIP, $buildVersion );
2894
}
2895
 
2896
#-------------------------------------------------------------------------------
395 dpurdie 2897
# Function        : vcsCleanup
2898
#
2899
# Description     : Cleanup and rewrite a vcstag
2900
#
2901
#                   DUPLICATED IN:
2902
#                       - cc2svn_procdata
2903
#                       - cc2svn_importpackage
2904
#
2905
# Inputs          : vcstag
2906
#
2907
# Returns         : Cleaned up vcs tag
2908
#
2909
sub vcsCleanup
2910
{
2911
    my ($tag) = @_;
2912
    $tag =~ tr~\\/~/~;
2913
    if ( $tag =~ m~^CC::~ )
2914
    {
2915
        $tag =~ s~CC::\s+~CC::~;
2916
        $tag =~ s~MASS_Dev_Bus/Cbp/~MASS_Dev_Bus/CBP/~i;
2917
        $tag =~ s~MASS_Dev_Bus~MASS_Dev_Bus~i;
2918
        $tag =~ s~/MASS_Dev/Infra~MASS_Dev_Infra~i;
2919
        $tag =~ s~/MASS_Dev/Bus/web~/MASS_Dev_Bus/web~i;
2920
 
2921
        $tag =~ s~/Vastraffik/~/Vasttrafik/~;
2922
        $tag =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
2923
        $tag =~ s~DPC_SWCode/~DPG_SWCode/~i;
2924
    }
2925
    return $tag;
2926
}
2927
 
2928
#-------------------------------------------------------------------------------
392 dpurdie 2929
# Function        : examineVcsTag
2930
#
2931
# Description     : Examine a VCS Tag and determine if it looks like rubbish
395 dpurdie 2932
#                   Give it a clean
392 dpurdie 2933
#
2934
# Inputs          : $entry
2935
#
2936
# Returns         : Will add Data to the $entry
2937
#
2938
sub examineVcsTag
2939
{
2940
    my ($entry) = @_;
2941
    my $bad = 0;
395 dpurdie 2942
 
2943
    $versions{$entry}{vcsTag} = vcsCleanup($versions{$entry}{vcsTag});
392 dpurdie 2944
    my $vcstag = $versions{$entry}{vcsTag};
395 dpurdie 2945
 
392 dpurdie 2946
    if ( $vcstag =~ m~^SVN::~ ) {
2947
        $versions{$entry}{isSvn} = 1;
2948
 
2949
    } elsif ( $vcstag =~ m~^CC::(.*?)(::(.+))?$~ ) {
2950
        my $path = $1  || '';
2951
        my $label = $2 || '';
2952
        $bad = 1 unless ( $label );
2953
        $bad = 1 if ( $label =~ m~^N/A$~i || $label  =~ m~^na$~i );
2954
 
2955
        $bad = 1 unless ( $path );
2956
        $bad = 1 if ( $path =~ m~^N/A$~i || $path  =~ m~^na$~i );
2957
        $bad = 1 if ( $path =~ m~^/dpkg_archive~ || $path  =~ m~^dpkg_archive~ );
2958
        $bad = 1 if ( $path =~ m~^/devl/~ || $path  =~ m~^devl/~ );
395 dpurdie 2959
        $bad = 1 if ( $path =~ m~^CVS~ );
392 dpurdie 2960
        $bad = 1 if ( $path =~ m~^http:~i );
2961
        $bad = 1 if ( $path =~ m~^[A-Za-z]\:~ );
2962
        $bad = 1 if ( $path =~ m~^//~ );
395 dpurdie 2963
        $bad = 1 if ( $path =~ m~^/*none~i );
2964
        $bad = 1 if ( $path =~ m~^/*NoWhere~i );
2965
        $bad = 1 if ( $path =~ m~^-$~i );
392 dpurdie 2966
        $bad = 1 if ( $path =~ m~^cvsserver:~ );
2967
        $bad = 1 if ( $path =~ m~,\s*module:~ );
2968
#        $bad = 1 unless ( $path =~ m~^/~ );
2969
    }
2970
    else
2971
    {
2972
        $bad = 1;
2973
    }
2974
    $versions{$entry}{badVcsTag} = 1 if ( $bad );
2975
}
2976
 
2977
#-------------------------------------------------------------------------------
2978
# Function        : logToFile
2979
#
2980
# Description     : Log some data to a named file
2981
#                   Use file locking to allow multiple process to log
2982
#
2983
# Inputs          : $filename           - Name of file to log
2984
#                   ...                 - Data to log
2985
#
2986
# Returns         : Nothing
2987
#
2988
sub logToFile
2989
{
2990
    my ($file, @data) = @_;
2991
 
2992
    open  (LOGFILE, '>>', $file);
2993
    flock (LOGFILE, LOCK_EX);
2994
    print  LOGFILE "@data\n";
2995
    flock (LOGFILE, LOCK_UN);
2996
    close (LOGFILE);
2997
}
2998
 
2999
#-------------------------------------------------------------------------------
3000
# Function        : createImages
3001
#
3002
# Description     : Create nice images of the RM version tree
3003
#
3004
# Inputs          : 
3005
#
3006
# Returns         : 
3007
#
3008
sub createImages
3009
{
3010
 
3011
    my $filebase = "${packageNames}";
3012
    open (FH, '>', "$filebase.dot" ) or die "Cannot open output";
3013
    print FH "digraph \"${packageNames}\" {\n";
3014
    #print FH "rankdir=LR;\n";
3015
    print FH "node[fontsize=16];\n";
3016
    print FH "node[target=_graphviz];\n";
3017
#    print FH "subgraph cluster_A {\n";
3018
#    print FH "node[fontsize=12];\n";
3019
 
3020
    {
3021
        my @text;
3022
        push @text, $packageNames;
3023
        push @text, 'HyperLinked to Release Manager';
3024
        push @text, 'Created:' . localtime();
3025
        push @text, '|';
3026
 
3027
        push @text, 'Total RM versions: ' . $totalVersions;
3028
        push @text, 'Essential Entries: ' . scalar @EssentialPackages;
3029
        push @text, 'Initial trees: ' . $initialTrees;
3030
 
1270 dpurdie 3031
        push @text, 'Number of Entries: ' . $processTotal;
392 dpurdie 3032
        push @text, 'Type : ' . $packageType;
3033
        push @text, 'All versions in Subversion' if ( $allSvn );
3034
 
3035
        push @text, '|';
3036
        push @text, 'Total Project Branches: ' . $ProjectCount;
3037
        foreach ( sort keys %knownProjects )
3038
        {
3039
            my $count = $knownProjects{$_}{count} || 0;
3040
            if ( $count )
3041
            {
3042
                my $text = 'Project Branch: ' . $_;
3043
                $text .= " (" . $count . ")" if ( $count > 1 );
3044
                push @text, $text;
3045
            }
3046
        }
3047
 
3048
        push @text, '|';
3049
        push @text, 'Bad VCS : ' . $badVcsCount;
3050
        push @text, 'Bad Singletions : ' . $badSingletonCount;
3051
        push @text, 'Deadwood entries : ' . $trimCount;
3052
        push @text, 'Walking Mode : Flat' if ($opt_flat);
3053
        push @text, 'Pruned Mode : ' . $pruneModeString;
3054
        push @text, 'Pruned entries : ' . $pruneCount;
1272 dpurdie 3055
        push @text, 'Recent entries : ' . $recentCount;
392 dpurdie 3056
 
3057
        if ( @unknownProjects )
3058
        {
3059
            push @text, '|';
3060
            push @text, 'Unknown Projects';
3061
            push @text, 'Unknown Project: ' . $_ foreach (sort @unknownProjects );
3062
        }
3063
 
3064
        #
3065
        #   Multiple Paths
3066
        #
3067
        if ( scalar @multiplePaths > 1 )
3068
        {
3069
            push @text, '|';
3070
            push @text, 'Multiple Paths';
3071
            push @text, @multiplePaths;
3072
        }
3073
 
3074
        #
3075
        #   Bad essentials
3076
        #
3077
        if ( @badEssentials  )
3078
        {
3079
            push @text, '|';
3080
            push @text, 'Bad Essential Versions';
3081
            push @text, GetVname($_) foreach ( @badEssentials );
3082
        }
3083
 
3084
        #
3085
        #   Subversion Data
3086
        #
3087
        if ( %svnData )
3088
        {
3089
            push @text, '|';
3090
            push @text, 'Subversion';
3091
            push @text, 'Trunk used' if exists $svnData{branches}{trunk} ;
3092
            push @text, 'Labels: ' . scalar keys %{$svnData{tags}} ;
3093
            push @text, 'Branches: ' . scalar keys %{$svnData{branches}} ;
3094
        }
3095
 
3096
        push @text, '';
3097
        my $text = join '\l', @text;
3098
        $text =~ s~\|\\l~|~g;
3099
 
3100
        my @attributes;
3101
        push @attributes, "shape=record";
3102
        push @attributes, "label=\"{$text}\"";
3103
        push @attributes, "tooltip=\"$packageNames\"";
1272 dpurdie 3104
        push (@attributes, "URL=\"" . $GBE_RM_URL . "/view_by_version.asp?pkg_id=$first_pkg_id" . "\"" )if $first_pkg_id;
392 dpurdie 3105
        push @attributes, "color=red";
3106
        my $attr = join( ' ', @attributes);
3107
 
3108
        my $tld_done = 'TitleBlock';
3109
        print FH "$tld_done [$attr]\n";
3110
    }
3111
 
3112
    #
3113
    #   Generate Legend
3114
    #
3115
    {
3116
        my @text;
3117
        push @text, 'Legend';
3118
        push @text, '|';
3119
        push @text, 'Node Content';
3120
        push @text, 'Package Version';
3121
#        push @text, 'Release Manager Ref (pvid)';
3122
        push @text, 'Creation Date: yyyy-mm-dd';
3123
        push @text, '(Coded information)';
3124
        push @text, '|{Code';
3125
        push @text, '|{N: Not Locked';
3126
        push @text, 'b: Bad Singleton';
3127
        push @text, 'B: Bad VCS Tag';
3128
        push @text, 'D: DeadWood';
1272 dpurdie 3129
        push @text, 'E: Essential Release Version';
392 dpurdie 3130
        push @text, 'G: Glued into Version Tree';
1272 dpurdie 3131
        push @text, 'r: Recent version';
1328 dpurdie 3132
        push @text, 'R: Ripple';
392 dpurdie 3133
        push @text, 'S: Splitpoint';
3134
        push @text, 't: Glued into Project Tree';
3135
        push @text, 'T: Tip version';
3136
        push @text, 'V: In SVN';
3137
        push @text, '+: In Subversion';
3138
        push @text, '}}';
3139
 
3140
        push @text, '|';
3141
        push @text, 'Outline';
3142
        push @text, 'Red: Dead or Bad VCS Tag';
3143
        push @text, 'Orange: Project Branch Root';
3144
        push @text, 'Green: Ripple Build Version';
3145
        push @text, 'Blue: Essential Version';
3146
        push @text, 'Darkmagenta: Entry Glued into tree';
3147
        push @text, 'Magenta: Entry added to project tree';
3148
 
3149
 
3150
        push @text, '|';
3151
        push @text, 'Fill';
3152
        push @text, 'PowderBlue: Essential Version';
3153
        push @text, 'Red: Bad Essential Version';
3154
        push @text, 'Light Green: Migrated to SVN';
3155
#        push @text, 'Red: Entry Glued into tree';
3156
#        push @text, 'Green: Entry added to project tree';
3157
 
3158
        push @text, '|';
3159
        push @text, 'Shape';
3160
        push @text, 'Oval: Normal Package Version';
3161
        push @text, 'Invhouse: Project Branch Root';
3162
        push @text, 'Octagon: Branch Point';
3163
        push @text, 'Box: Bad Single version with no history';
3164
        push @text, 'Doublecircle: Tip of a Project Branch';
3165
 
3166
        push @text, '';
3167
        my $text = join '\l', @text;
3168
        $text =~ s~\|\\l~|~g;
3169
        $text =~ s~\}\\l~}~g;
3170
 
3171
        my @attributes;
3172
        push @attributes, "shape=record";
3173
        push @attributes, "label=\"{$text}\"";
3174
        push @attributes, "color=red";
3175
        my $attr = join( ' ', @attributes);
3176
 
3177
        my $tld_done = 'LegendBlock';
3178
        print FH "$tld_done [$attr]\n";
3179
    }
3180
 
3181
#    print FH "\n}\n";
3182
    print FH "TitleBlock -> LegendBlock [style=invis]\n";
3183
 
3184
    sub genLabelText
3185
    {
3186
        my ($entry) = @_;
3187
        my @label;
3188
        push @label, $versions{$entry}{name} if ( $multiPackages );
3189
        push @label, $versions{$entry}{vname};
3190
#        push @label, $entry;       # Add PVID
3191
        push @label, substr( $versions{$entry}{created}, 0, 10); #  2008-02-19
3192
#        push @label, 'V=' . $versions{$entry}{maxVersion};
3193
#        push @label, 'B=' . $versions{$entry}{svnBranchTip} if ( exists $versions{$entry}{svnBranchTip} );
3194
 
3195
 
3196
        my $stateText = '';
3197
        $stateText .= 'N' if ($versions{$entry}{locked} eq 'N');
3198
        $stateText .= 'b' if (exists $versions{$entry}{badSingleton});
3199
        $stateText .= 'B' if (exists $versions{$entry}{badVcsTag});
3200
        $stateText .= 'G' if (exists $versions{$entry}{GluedIn});
3201
        $stateText .= 't' if (exists $versions{$entry}{MakeTree});
3202
        $stateText .= 'E' if (exists $versions{$entry}{Essential});
3203
        $stateText .= 'D' if (exists $versions{$entry}{DeadWood});
1328 dpurdie 3204
        $stateText .= 'R' if ( $versions{$entry}{isaRipple} );
1272 dpurdie 3205
        $stateText .= 'r' if (exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 3206
        $stateText .= 'S' if (exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
3207
        $stateText .= 'T' if (exists $versions{$entry}{Tip} );
3208
        $stateText .= 'V' if (exists $versions{$entry}{isSvn} );
3209
        $stateText .= '+' if (exists $versions{$entry}{svnVersion} );
3210
#        $stateText .= 's' if (exists $versions{$entry}{branchPoint} );
3211
#        $stateText .= ' T='. $versions{$entry}{threadId} if (exists $versions{$entry}{threadId});
3212
#        $stateText .= ' EssentalPath' if (exists $versions{$entry}{EssentialPath});
3213
#        $stateText .= ' Count='. $versions{$entry}{EssentialSplitPoint} if (exists $versions{$entry}{EssentialSplitPoint});
3214
#        $stateText .= ' M='. $versions{$entry}{maxVersion} if (exists $versions{$entry}{maxVersion});
3215
 
3216
        push @label, "(${stateText})" if ( $stateText );
3217
 
1341 dpurdie 3218
##       Insert Release Names
1451 dpurdie 3219
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
3220
            next unless ( exists $ukHopsReleases{$rtag_id} );
3221
            push @label, "Release: $versions{$entry}{Releases}{$rtag_id}{rname}";
3222
        }
1341 dpurdie 3223
 
392 dpurdie 3224
        return join ('\n', @label );
3225
    }
3226
 
3227
    sub genAttributes
3228
    {
3229
        my ($entry) = @_;
3230
        my @attributes;
3231
        push @attributes, 'label="' . genLabelText($entry) . '"';
3232
        push @attributes, 'URL="' . dotUrl($entry) . '"';
3233
        push @attributes, 'tooltip="' . "Goto: $versions{$entry}{vname}, PVID=$entry" ,'"';
3234
        my $shape;
3235
            $shape = 'box' if ($versions{$entry}{badSingleton});
3236
            $shape = 'octagon'  if ($versions{$entry}{branchPoint});
3237
            $shape = 'invhouse' if ($versions{$entry}{newSuffix});
3238
            $shape = 'doublecircle' if ($versions{$entry}{Tip});
3239
 
3240
 
3241
        push @attributes, 'shape=' . $shape if ( $shape );
3242
 
3243
        my $color;
3244
        my $fill;
3245
           $color = 'color=green style=bold' if ( $versions{$entry}{isaRipple} );
3246
           $color = 'color=orange style=bold' if ( $versions{$entry}{newSuffix} );
3247
           $color = 'color=red style=bold' if ( $versions{$entry}{DeadWood} || $versions{$entry}{badVcsTag} );
3248
           $color = 'color=blue style=bold' if ( $versions{$entry}{Essential} );
3249
           $color = 'color=darkmagenta style=bold' if ( $versions{$entry}{GluedIn} );
3250
           $color = 'color=magenta style=bold' if ( $versions{$entry}{MakeTree} );
3251
 
3252
           $fill = 'style=filled fillcolor=powderblue' if ( $versions{$entry}{Essential} );
3253
           $fill = 'style=filled fillcolor=red' if ( $versions{$entry}{Essential} && $versions{$entry}{badVcsTag} );
3254
           $fill = 'style=filled fillcolor="#99FF99"' if ( exists $versions{$entry}{svnVersion} );
3255
 
3256
 
3257
        push @attributes, $color if ( $color );
3258
        push @attributes, $fill if ( $fill );
3259
 
3260
        return '[' . join( ' ', @attributes) . ']';
3261
    }
3262
 
3263
    sub genArrowAttributes
3264
    {
3265
        my ($not_first, $entry) = @_;
3266
        my @attributes;
3267
 
3268
        push @attributes, 'arrowhead=empty' if ( $not_first );
3269
        push ( @attributes, 'label="' . $versions{$entry}{svnBranchTip} .'"' ) if ( exists $versions{$entry}{svnBranchTip} );
3270
 
3271
        return ('[' . join( ' ', @attributes) . ']') if ( @attributes ) ;
3272
        return '';
3273
    }
3274
 
3275
    #
3276
    #   Flat
3277
    #
3278
    if ( $opt_flat )
3279
    {
3280
        my $last = 0;
3281
        foreach my $entry (@flatOrder )
3282
        {
3283
            if ( $last )
3284
            {
3285
                my $me = dotTag($last);
3286
 
3287
                print FH pentry($me)  ,' -> ', pentry(dotTag($entry)), genArrowAttributes(0, $entry) ,";\n";
3288
                print FH pentry($me)  ,genAttributes($last) . ";\n";
3289
            }
3290
            $last = $entry;
3291
        }
3292
        print FH pentry(dotTag($last))  ,genAttributes($last) . ";\n";
3293
 
3294
    }
3295
    else
3296
    {
3297
        foreach my $entry ( sort {$a <=> $b} keys(%versions) )
3298
        {
3299
            my $me = dotTag($entry);
3300
            my @versions = @{ $versions{$entry}{next}};
3301
            my $ii = 0;
3302
            foreach ( @versions )
3303
            {
3304
                print FH pentry($me)  ," -> ",pentry(dotTag($_)), genArrowAttributes($ii++, $_), ";\n";
3305
            }
3306
 
3307
            print FH pentry($me)  ,genAttributes($entry) . ";\n";
3308
        }
3309
    }
3310
 
3311
    print FH "\n};\n";
3312
    close FH;
3313
 
3314
    #
3315
    #   Convert DOT to a SVG
3316
    #
3317
    unless ( $UNIX )
3318
    {
3319
    print "Generating graphical images\n";
3320
#    system( "dot $filebase.dot -Tjpg -o$filebase.jpg" );  # -v
3321
    system( "dot $filebase.dot -Tsvg -o$filebase.svg" );  # -v
3322
#    unlink("$filebase.dot");
3323
 
3324
    #
3325
    #   Display a list of terminal packages
3326
    #   These are packages that are not used by any other package
3327
    #
3328
    print "\n";
3329
#    print "Generated: $filebase.dot\n";
3330
#    print "Generated: $filebase.jpg\n";
3331
    print "Generated: $filebase.svg\n";
3332
    }
3333
    else
3334
    {
3335
        print "Generated: $filebase.dot\n";
3336
    }
3337
}
3338
 
3339
sub dotTag
3340
{
3341
    my ($entry) = @_;
3342
 
3343
    my $label = '';
3344
    $label .= $versions{$entry}{name} if $multiPackages;
3345
    $label .= $versions{$entry}{vname};
3346
    $label =~ s~[-() ]~_~g;
3347
    return $label;
3348
}
3349
 
3350
sub dotUrl
3351
{
3352
    my ($entry) = @_;
3353
 
3354
    my $pv_base = $GBE_RM_URL . "/fixed_issues.asp?pv_id=$entry";
3355
}
3356
 
3357
#-------------------------------------------------------------------------------
3358
# Function        : pentry
3359
#
3360
# Description     : Generate an entry list as text
3361
#                   Replace "." with "_" since DOT doesn't like .'s
3362
#                   Seperate the arguments
3363
#
3364
# Inputs          : @_          - An array of entries to process
3365
#
3366
# Returns         : A string
3367
#
3368
sub pentry
3369
{
3370
    my ($data) = @_;
3371
    $data =~ s~\.~_~g;
3372
    $result = '"' . $data . '"' ;
3373
    return $result;
3374
}
3375
 
3376
#-------------------------------------------------------------------------------
3377
# Function        : getVobMapping
3378
#
3379
# Description     : Read in Package to Repository Mapping
3380
#
3381
# Inputs          : 
3382
#
3383
# Returns         : Populates %VobMapping
3384
#                             Mapping of PackageName to RepoName[/Subdir]
3385
#
3386
our %ScmRepoMap;
3387
sub getVobMapping
3388
{
3389
    Message ("Read in Vob Mapping");
3390
 
3391
    my $fname = 'cc2svn.repo.dat';
3392
    Error "Cannot locate $fname" unless ( -f $fname );
3393
    require $fname;
3394
 
3395
    Error "Data in $fname is not valid\n"
3396
        unless ( keys(%ScmRepoMap) >= 0 );
3397
 
3398
    $opt_vobMap = $ScmRepoMap{$packageNames}{repo}
3399
        if (exists $ScmRepoMap{$packageNames});
3400
 
3401
    #
3402
    #   Free the memory
3403
    #
3404
    %ScmRepoMap = ();
3405
 
3406
    #
3407
    #   Calculate Target Repo
3408
    #
3409
    Warning ("No VOB Mapping found")
3410
        unless ($opt_vobMap);
3411
    Error("No repository specified. ie -repo=DevTools or -repo=COTS")
3412
        unless ( $opt_repo || $opt_vobMap );
3413
 
3414
    my $r1 = ($opt_repo || '') . '/' . ($opt_vobMap || '');
3415
    $r1 =~ s~^/~~;
3416
    $r1 =~ s~/$~~;
3417
    $svnRepo = $opt_repo_base . $r1;
3418
 
3419
    Verbose( "Repo URL: $svnRepo");
3420
}
3421
 
3422
 
3423
#-------------------------------------------------------------------------------
3424
# Function        : getEssenialPackageVersions
3425
#
3426
# Description     : Determine the 'Essental' Package Versions
3427
#                   Read the data in from an external file
3428
#
3429
# Inputs          : 
3430
#
3431
# Returns         : Populates @EssentialPackages
3432
#
3433
 
3434
our %ScmReleases;
3435
our %ScmPackages;
3436
our %ScmSuffixes;
3437
sub getEssenialPackageVersions
3438
{
3439
    Message ("Read in Essential Package Versions");
3440
 
3441
    my $fname = 'cc2svn.raw.txt';
3442
    Error "Cannot locate $fname" unless ( -f $fname );
3443
    require $fname;
3444
 
3445
    Error "Data in $fname is not valid\n"
3446
        unless ( keys(%ScmReleases) >= 0 );
3447
 
3448
#    DebugDumpData("ScmReleases", \%ScmReleases );
3449
#    DebugDumpData("ScmPackages", \%ScmPackages );
3450
#    DebugDumpData("ScmSuffixes", \%ScmSuffixes );
3451
 
3452
    #
3453
    #   Create a list of essential packages
3454
    #   Retain packages-versions used in this program
3455
    #
3456
    foreach ( keys %ScmPackages )
3457
    {
3458
        next unless ( exists  $pkg_ids{ $ScmPackages{$_}{pkgid} } );
3459
        push @EssentialPackages, $_;
3460
        Error ("Essential Package Version not in extracted Release Manager Data: $_")
3461
            unless ( exists $versions{$_} );
3462
        $versions{$_}{Essential} = 1;
1341 dpurdie 3463
 
3464
        # Retain which RM Release this package-version is the tip
3465
        # Release of
1342 dpurdie 3466
        foreach my $rtag_id ( @{$ScmPackages{$_}{'release'}} )
1341 dpurdie 3467
        {
1342 dpurdie 3468
            $versions{$_}{Releases}{$rtag_id}{rname}   = $ScmReleases{$rtag_id}{name};
3469
            $versions{$_}{Releases}{$rtag_id}{pname}   = $ScmReleases{$rtag_id}{pName};
3470
            $versions{$_}{Releases}{$rtag_id}{proj_id} = $ScmReleases{$rtag_id}{proj_id};
1341 dpurdie 3471
        }
3472
 
392 dpurdie 3473
        #print "ESSENTIAL: $versions{$_}{name} $versions{$_}{vname}\n";
3474
    }
3475
 
1341 dpurdie 3476
 
392 dpurdie 3477
    #
3478
    #   Free memory
3479
    #
3480
    %ScmReleases = ();
3481
    %ScmPackages = ();
3482
    %ScmSuffixes = ();
3483
 
3484
#    DebugDumpData("Essential", \@EssentialPackages );
3485
    Message ("Essential Versions: " . scalar @EssentialPackages );
3486
}
3487
 
3488
#-------------------------------------------------------------------------------
3489
# Function        : ReportPathVariance
3490
#
3491
# Description     : Report variance in paths used by the versions
3492
#
3493
# Inputs          : 
3494
#
3495
# Returns         : 
3496
#
3497
my %VobPaths;
3498
sub ReportPathVariance
3499
{
3500
    Message ("Detect Multiple Paths");
3501
    foreach my $entry ( keys(%versions) )
3502
    {
3503
        my $e = $versions{$entry};
3504
        next if ( isSet ($e, 'DeadWood' ) );
3505
        next if ( isSet ($e, 'badVcsTag') );
3506
        next if ( isSet ($e, 'isSvn') );
3507
        my $tag = $e->{vcsTag};
3508
        next unless ( $tag );
3509
 
3510
        $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
3511
        my $vcsType = $1;
3512
        my $cc_label = $4;
3513
        my $cc_path = $2;
3514
        $cc_path = '/' . $cc_path;
3515
        $cc_path =~ tr~\\/~/~s;
3516
 
3517
        $VobPaths{$cc_path}++;
3518
    }
3519
 
3520
    @multiplePaths = sort keys %VobPaths;
3521
    if ( scalar @multiplePaths > 1 )
3522
    {
3523
        Warning ("Multiple Paths:" . $_ ) foreach (@multiplePaths);
3524
    }
3525
}
3526
 
3527
sub isSet
3528
{
3529
    my ($base, $element) = @_;
3530
    return 0 unless ( exists $base->{$element} );
3531
    return $base->{$element};
3532
}
3533
 
3534
 
3535
#-------------------------------------------------------------------------------
3536
# Function        : recurseList
3537
#
3538
# Description     : Return a list of all element below a given head element
3539
#
3540
# Inputs          : $head               - Head element
3541
#
3542
# Returns         : A list, not in any particular order
3543
#
3544
 
3545
our @recurseList;
3546
sub recurseList
3547
{
3548
    @recurseList = ();
3549
    recurseListBody (@_);
3550
    return @recurseList;
3551
}
3552
sub recurseListBody
3553
{
3554
    foreach my $entry ( @_ )
3555
    {
3556
        push @recurseList, $entry;
3557
no warnings "recursion";
3558
        recurseListBody (@{$versions{$entry}{next}});
3559
    }
3560
}
3561
 
3562
#-------------------------------------------------------------------------------
3563
# Function        : getSvnData
3564
#
3565
# Description     : Read the SVN tree and see what we have
3566
#
3567
# Inputs          : 
3568
#
3569
# Returns         : 
3570
#
3571
my @svnDataItems;
3572
sub getSvnData
3573
{
3574
    Message ("Examine Subversion Tree");
3575
 
3576
    #
3577
    #   Re-init data
3578
    #
3579
    @svnDataItems = ();
3580
    %svnData = ();
3581
 
3582
    #
3583
    #   Create an SVN session
3584
    #
3585
    return unless ( $svnRepo );
3586
    my $svn = NewSessionByUrl ( "$svnRepo/$packageNames" );
3587
    return unless ( $svn );
3588
 
3589
    #
3590
    #   extract data
3591
    #
3592
#    DebugDumpData("SVN", $svn );
3593
    $svn->SvnCmd ( 'log', '-v', '--xml', '--stop-on-copy', $svn->Full()
3594
                    , { 'credentials' => 1,
3595
                        'process' => \&ProcessSvnLog,
3596
                         }
3597
                        );
3598
 
3599
    #
3600
    #   Process data
3601
    foreach my $entry ( @svnDataItems )
3602
    {
3603
        my $name;
3604
        my $isaBranch;
3605
        my $target = $entry->{target};
3606
        if ( $target =~ m~/tags/(.*)~ ) {
3607
            $name = $1;
3608
            $svnData{tags}{$name} = 1;
3609
        } elsif ( $target =~ m~/branches/(.*)~ )  {
3610
            $name = $1;
3611
    #        $branches{$1} = 1;
3612
        } else {
3613
            $svnData{nonTag}{$target} = 1;
3614
        }
3615
 
3616
        my $fromBranch;
3617
        if ( $entry->{fromPath} =~ m~/trunk$~  ) {
3618
            $fromBranch = 'trunk';
3619
        } elsif ( $entry->{fromPath} =~ m~/branches/(.*)~ ) {
3620
            $fromBranch = $1;
3621
        }
3622
 
1341 dpurdie 3623
        # largest Rev number on branch
3624
        if ( exists $svnData{max}{$fromBranch} )
392 dpurdie 3625
        {
1341 dpurdie 3626
            if ( $svnData{max}{$fromBranch}{rev} <  $entry->{fromRev} )
392 dpurdie 3627
            {
1341 dpurdie 3628
                $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
3629
                $svnData{max}{$fromBranch}{name} = $name;
392 dpurdie 3630
            }
3631
        }
1341 dpurdie 3632
        else
3633
        {
3634
            $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
3635
            $svnData{max}{$fromBranch}{name} = $name;
3636
        }
392 dpurdie 3637
    }
1341 dpurdie 3638
 
3639
    foreach my $branch ( keys %{$svnData{max}} )
3640
    {
3641
        $svnData{tips}{$svnData{max}{$branch}{name}} = $branch;
3642
    }
3643
#    DebugDumpData("svnDataItems", \@svnDataItems);
392 dpurdie 3644
#    DebugDumpData("SvnData", \%svnData);
3645
 
1341 dpurdie 3646
 
392 dpurdie 3647
    foreach my $entry ( keys(%versions) )
3648
    {
3649
        my $import_label = saneLabel($entry);
3650
        delete $versions{$entry}{svnVersion};
3651
        delete $versions{$entry}{svnBranchTip};
3652
 
3653
        if ( exists $svnData{tags}{$import_label} )
3654
        {
3655
            $versions{$entry}{svnVersion} = 1;
3656
        }
3657
 
3658
        if ( exists $svnData{tips}{$import_label} )
3659
        {
3660
            $versions{$entry}{svnBranchTip} = $svnData{tips}{$import_label};
3661
        }
3662
    }
3663
 
1341 dpurdie 3664
    Message ( 'Trunk used: ' . (exists $svnData{'max'}{trunk} ? 'Yes' : 'No') );
392 dpurdie 3665
    Message ( 'Labels    : ' . scalar keys %{$svnData{tags}} );
1341 dpurdie 3666
    Message ( 'Branches  : ' . scalar keys %{$svnData{'max'}} );
392 dpurdie 3667
}
3668
 
3669
#-------------------------------------------------------------------------------
3670
# Function        : ProcessSvnLog
3671
#
3672
# Description     :
3673
#                   Parse
3674
#                       <logentry
3675
#                          revision="24272">
3676
#                       <author>bivey</author>
3677
#                       <date>2005-07-25T15:45:35.000000Z</date>
3678
#                       <paths>
3679
#                       <path
3680
#                          prop-mods="false"
3681
#                          text-mods="false"
3682
#                          kind="dir"
3683
#                          copyfrom-path="/enqdef/branches/Stockholm"
3684
#                          copyfrom-rev="24271"
3685
#                          action="A">/enqdef/tags/enqdef_24.0.1.sls</path>
3686
#                       </paths>
3687
#                       <msg>COTS/enqdef: Tagged by Jats Svn Import</msg>
3688
#                       </logentry>
3689
#
3690
# Inputs          : 
3691
#
3692
# Returns         : 
3693
#
3694
my $entryData;
3695
sub  ProcessSvnLog
3696
{
3697
    my ($self, $line ) = @_;
3698
#print "----- $line\n";
3699
    if ( $line =~ m~^<logentry~ ) {
3700
        $entryData = ();
3701
 
3702
    } elsif ( $line =~ m~^\s+revision="(\d+)"~ ) {
3703
        $entryData->{Rev} = $1;
3704
 
3705
    } elsif ( $line =~ m~^\s+copyfrom-path="(.*)"~ ) {
3706
        $entryData->{fromPath} = $1;
3707
 
3708
    } elsif ( $line =~ m~^\s+copyfrom-rev="(\d+)"~ ) {
3709
        $entryData->{fromRev} = $1;
3710
 
3711
    } elsif ( $line =~ m~\s+action=.*?>(.*)</path~ ) {
3712
        $entryData->{target} = $1;
3713
 
3714
    } elsif ( $line =~ m~</logentry~ ) {
3715
        if ( exists $entryData->{fromPath} )
3716
        {
3717
#            DebugDumpData("Data", $entryData);
3718
            push @svnDataItems, $entryData;
3719
        }
3720
    }
3721
 
3722
    #
3723
    #   Return 0 to keep on going
3724
    return 0;
3725
}
3726
 
1328 dpurdie 3727
#-------------------------------------------------------------------------------
392 dpurdie 3728
# Function        : saveData
3729
#
3730
# Description     : Save essential data
3731
#
3732
# Inputs          : 
3733
#
3734
# Returns         : 
3735
#
3736
sub saveData
3737
{
3738
    my $file = $cwd . "/${packageNames}.data";
3739
 
3740
    Message ("Create: $file");
3741
    my $fh = ConfigurationFile::New( $file );
3742
 
3743
    $fh->DumpData(
3744
        "\n# ScmVersions.\n#\n",
3745
        "ScmVersions", \%versions );
3746
 
3747
    #
3748
    #   Close out the file
3749
    #
3750
    $fh->Close();
3751
}
3752
 
3753
 
3754
#-------------------------------------------------------------------------------
3755
#   Documentation
3756
#
3757
 
3758
=pod
3759
 
3760
=for htmltoc    SYSUTIL::cc2svn::
3761
 
3762
=head1 NAME
3763
 
3764
cc2svn_gendata - CC2SVN tool to import an entire package into SVN
3765
 
3766
=head1 SYNOPSIS
3767
 
3768
  jats cc2svn_importpackage [options] package_name
3769
 
3770
 Options:
3771
    -help              - brief help message
3772
    -help -help        - Detailed help message
3773
    -man               - Full documentation
3774
    -repository=name   - Specify target repository
3775
    -[no]flat          - Do not create project tree. Def: -noflat
3776
    -prunemode=mode    - Mode: none, ripple, retain, severe, Def=ripple
3777
    -retain=N          - Specify retain count for pruning. Def=2
3778
    -[no]test          - Do not create packages. Def:-notest
3779
    -[no]reuse         - Keep and reuse ClearCase views
3780
    -age=nnDays        - Only keep recent package
3781
    -dump[=n]          - Dump raw data. N=0,1,2
3782
    -images[=n]        - Create SVG of version tree. N=0,1,2
3783
    -name=aaa          - Alternate output package name. Test Only
3784
    -[no]log           - Write output to log file. Def: -nolog
3785
    -[no]postimage     - Create image after transger: Def: -post
3786
    -workdir=path      - Use for temp storage (def:/work)
1270 dpurdie 3787
    -delete            - Delete SVN package before test
392 dpurdie 3788
 
3789
=head1 OPTIONS
3790
 
3791
=over 8
3792
 
3793
=item B<-help>
3794
 
3795
Print a brief help message and exits.
3796
 
3797
=item B<-help -help>
3798
 
3799
Print a detailed help message with an explanation for each option.
3800
 
3801
=item B<-man>
3802
 
3803
Prints the manual page and exits.
3804
 
3805
=item B<-prunemode=mode>
3806
 
3807
This option control the manner in which excess versions will be pruned. Valid
3808
modes are:
3809
 
3810
=over 8
3811
 
3812
=item   none
3813
 
3814
No pruning will be performed
3815
 
3816
=item   ripple
3817
 
3818
Non-Essential packages that are ripple builds will be removed.
3819
 
3820
=item   retain
3821
 
3822
Versions that preceed an Essential version will be retained.
3823
 
3824
=item   severe
3825
 
3826
Only Essential Versions, and Branching points will be retained.
3827
 
3828
=back
3829
 
3830
=back
3831
 
3832
=head1 DESCRIPTION
3833
 
3834
This program is a tool used in the conversion of ClearCase VOBS to subversion.
3835
It will take a complete package and all relevent versions from ClearCase and
3836
insert them into subversion in a sessible manner. It will attempt to retain
3837
file change order and history.
3838
 
3839
It will:
3840
 
3841
=over 8
3842
 
3843
=item *
3844
 
3845
Read in the Essential Package Version list.
3846
 
3847
=item *
3848
 
3849
Extract, from Release Manager, all known versions of the specified package.
3850
 
3851
=item *
3852
 
3853
It will attempt to determine the type of package: COTS, TOOL, CORE, PROJECT
3854
and alter the processing accordingly.
3855
 
3856
=item *
3857
 
3858
It will create a version dependency tree and determine 'new' project branch
3859
points. It will remove (prune) versions that are excess to requirements.
3860
 
3861
=item *
3862
 
3863
It will extract source from ClearCase and insert it into SVN, creating
3864
branches and tags as it goes.
3865
 
3866
=back
3867
 
3868
The program can also be used to create a SVG image of the version dependency
3869
tree. This does not work on Linux; only Windows with 'dot' installed.
3870
 
3871
=cut
3872