Subversion Repositories DevTools

Rev

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