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} );
1018
            return 0 if ( ($pruneMode == 2) && exists $versions{$entry}{KeepMe} );
1019
            return 0 if ( exists $versions{$entry}{Essential} );
1020
            return 0 if ( $versions{$entry}{newSuffix} );
1021
            return 0 if ( $versions{$entry}{newSuffix} && (exists $versions{$entry}{EssentialPath}) );
1022
#            return 1 if ( exists $versions{$entry}{DeadWood} );
1023
            return 0 if ( exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
1024
            return 0 if ( exists $versions{$entry}{keepLowestRipple} &&  $versions{$entry}{keepLowestRipple} );
1025
            return 0 if ( ($pruneMode == 1) && ! $versions{$entry}{isaRipple} );
1272 dpurdie 1026
            return 0 if ( exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 1027
            return 1;
1028
        }
1029
 
1030
        foreach my $entry ( keys(%versions) )
1031
        {
1032
#last;
1033
            next unless ( pruneMe($entry) );
1034
#print "--- Prune: $versions{$entry}{vname}\n";
1035
 
1036
            # Delete the current node
1037
            #
1038
            my @newNext;
1039
            $pruneCount++;
1040
            my $last = $versions{$entry}{last};
1041
            foreach ( @{$versions{$last}{next}} )
1042
            {
1043
                next if ( $_ == $entry );
1044
                push @newNext, $_;
1045
            }
1046
            foreach ( @{$versions{$entry}{next}} )
1047
            {
1048
                push @newNext, $_;
1049
                $versions{$_}{last} = $last;
1050
            }
1051
 
1052
            @{$versions{$last}{next}} = @newNext;
1053
            delete $versions{$entry};
1054
        }
1055
 
1056
        # Recalculate endpoints
1057
        calcLinks();
1058
    }
1059
    else
1060
    {
1061
        #   No rippling happening
1062
        #   Some process still need to happen
1063
        #
1064
        calcRippleGroups();
1065
    }
1066
 
1067
    #
1068
    #   Calculate best through-path for branches in the tree
1069
    #   Attempt to keep that 'max' version on the mainline
1070
    #   May be modified by -tip=nnnn
1071
    #
1072
    #   For each leaf (end point), walk backwards and mark each node with the
1073
    #   max version see. If we get to a node which already has been marked then
1074
    #   stop if our version is greater. We want the value to be the max version
1075
    #   to a leaf
1076
    #
1077
    #   Account for 'suffix'. When suffix changes, then the 'max' version must
1078
    #   be recalculated
1079
    #
1080
 
1081
    Message ("Calculate Max Version");
1082
    my $maxVersion;
1083
 
1084
    foreach my $entry ( @endPoints )
1085
    {
1086
        my $lastSuffix;
1087
        my $forceTip;
1088
        while ( $entry )
1089
        {
1090
            if (!defined($lastSuffix) || ($versions{$entry}{suffix} ne $lastSuffix) )
1091
            {
1092
                $maxVersion = '0';
1093
                $visitId++;
1094
                $forceTip = ( exists $tipVersions{$versions{$entry}{vname}} );
1451 dpurdie 1095
                $forceTip = 1 if $versions{$entry}{ukTrunk};
392 dpurdie 1096
                delete $tipVersions{$versions{$entry}{vname}};
1097
                $maxVersion = '999.999.999.999.zzz' if ( $forceTip );
1098
                $lastSuffix = $versions{$entry}{suffix};
1099
#print "---Tip Found\n" if $forceTip;
1100
            }
1101
 
1102
            # Detect circular dependencies
1103
            if ( ($versions{$entry}{visitId} || 0) == $visitId )
1104
            {
1105
                DebugDumpData ("Circular dependency: Versions", \%versions );
1106
                Warning ("Circular dependency");
1107
                last;
1108
            }
1109
            $versions{$entry}{visitId} = $visitId;
1110
 
1111
            my $thisVersion = $versions{$entry}{version} || '';
1112
            if ( $thisVersion gt $maxVersion )
1113
            {
1114
                $maxVersion = $thisVersion;
1115
            }
1116
 
1117
            if ( exists $versions{$entry}{maxVersion} )
1118
            {
1119
                if ( $versions{$entry}{maxVersion} gt $maxVersion )
1120
                {
1121
                    last;
1122
                }
1123
            }
1124
 
1125
            $versions{$entry}{maxVersion} = $maxVersion;
1126
            $entry = $versions{$entry}{last};
1127
        }
1128
    }
1129
 
1130
 
1131
    #
1132
    #   Locate all instances where a package-version branches
1133
    #   Determine the version that should be on the non-branching path
1134
    #
1135
    #   Reorder the 'next' list so that the first item is the non-branching
1136
    #   path. This will be used in the data-insertion phase to simplify the
1137
    #   processing.
1138
    #
1139
    Message ("Calculate package version branches");
1140
    foreach my $entry ( sort {$a <=> $b} keys(%versions) )
1141
    {
1142
        calculateWalkOrder($entry);
1143
    }
1144
 
1145
    #
1146
    #   Mark Project Branch Tips as they will be in the Repository
1147
    #   Find each project head and walk primary entry to the end.
1148
    #
1149
    foreach my $entry ( keys(%versions) )
1150
    {
1151
        #
1152
        #   Root of each tree is 'new'
1153
        #
1154
        unless ( defined $versions{$entry}{last})
1155
        {
1156
            unless ( $versions{$entry}{badSingleton} )
1157
            {
1158
                $versions{$entry}{newSuffix} = 1;
1159
            }
1160
        }
1161
 
1162
        #
1163
        #   Update stats
1164
        #
1165
        $badVcsCount++ if ( $versions{$entry}{badVcsTag} );
1166
        $ProjectCount++ if ( $versions{$entry}{newSuffix} );
1167
        next if ( $opt_flat );
1168
 
1169
        next unless ($versions{$entry}{newSuffix} );
1170
#print "--- Project new Suffix $versions{$entry}{vname}\n";
1171
 
1172
 
1173
        my $suffix = $versions{$entry}{suffix};
1174
        $knownProjects{$suffix}{count}++;
1175
 
1176
        my $next = $versions{$entry}{next}[0];
1177
        my $tip;
1178
        while ( $next )
1179
        {
1180
            last if ( $suffix ne $versions{$next}{suffix} );
1181
            $tip = $next unless (exists ($versions{$next}{DeadWood}) || $versions{$next}{badSingleton});
1182
            $next = $versions{$next}{next}[0];
1183
        }
1184
 
1185
        $versions{$tip}{Tip} = 1 if $tip;
1186
    }
1187
 
1188
    unless ( $opt_flat )
1189
    {
1190
        my $finalTrees = scalar @startPoints;
1191
        Warning ("Still have multiple trees: $finalTrees") unless ( $finalTrees == 1 );
1192
    }
1193
 
1194
    #
1195
    #   Display warnings about multiple
1196
    #
1197
    foreach ( sort keys %knownProjects )
1198
    {
1199
        my $count = $knownProjects{$_}{count} || 0;
1200
        Warning ("Multiple Project Roots: $_ ($count)" )
1201
            if ( $count > 1 );
1202
    }
1203
 
1204
    #
1205
    #   Display warnings about Bad Essential Packages
1206
    #
1207
    $allSvn = 1;
1208
    foreach my $entry ( keys(%versions) )
1209
    {
1210
        $rippleCount++ if ( exists($versions{$entry}{isaRipple}) && $versions{$entry}{isaRipple} );
1211
        $allSvn = 0 unless ( $versions{$entry}{isSvn} );
1212
        next unless ( exists $versions{$entry}{Essential}  );
1213
        next unless ( $versions{$entry}{badVcsTag}  );
1214
        push @badEssentials, $entry;
1215
        Warning ("BadVCS Essential: " . GetVname($entry))
1216
    }
1217
 
1218
    #
1219
    #   All done
1220
    #
1270 dpurdie 1221
    $processTotal = scalar keys %versions;
1222
    Message("Retained entries: $processTotal" );
392 dpurdie 1223
    Message("Pruned entries: $pruneCount");
1224
    Message("Deadwood entries: $trimCount");
1225
    Message("Bad Singletons: $badSingletonCount");
1226
    Message("Ripples: $rippleCount");
1272 dpurdie 1227
    Message("Recent entries: $recentCount");
392 dpurdie 1228
}
1229
 
1230
sub calculateWalkOrder
1231
{
1232
    my ($entry) = @_;
1233
    my @next = @{$versions{$entry}{next}};
1234
    my $count = @next;
1235
    my @ordered;
1236
    my $main;
1237
 
1238
    if ( $count > 1 )
1239
    {
1240
        # Array to hash to simplify removal
1241
        my %nexts = map { $_ => 1 } @next;
1242
        foreach my $e ( @next )
1243
        {
1244
 
1245
            #
1246
            #   Locate branch points that are not a part of a new project
1247
            #   These will not be preferred paths for walking
1248
            #
1249
            if ( !defined($versions{$e}{branchPoint}) && $versions{$entry}{suffix} ne $versions{$e}{suffix} )
1250
            {
1251
                unless ( exists $versions{$e}{DeadWood} || $versions{$e}{badSingleton}  )
1252
                {
1253
#print "--- Project Branch (1) $versions{$e}{vname}\n";
1254
                    $versions{$e}{branchPoint} = 1;
1255
                    $versions{$e}{newSuffix} = 1;
1256
                }
1257
            }
1258
 
1259
            #
1260
            #   Remove those that already have a branch,
1261
            #
1262
            if ( $versions{$e}{branchPoint} || $versions{$e}{newSuffix} || $versions{$e}{DeadWood}  )
1263
            {
1264
                push @ordered, $e;
1265
                delete $nexts{$e};
1266
            }
1267
        }
1268
        #
1269
        #   Select longest arm as the non-branching path
1270
        #   Note: Reverse sort order
1271
        #         Done so that 'newest' item is given preference
1272
        #         to the main trunk in cases where all subtrees are
1273
        #         the same length
1274
        #
1275
        my $maxData = '';
1276
        my $countEntry;
1277
        foreach my $e ( sort {$b <=> $a} keys %nexts )
1278
        {
1279
            if ( $versions{$e}{maxVersion} gt $maxData )
1280
            {
1281
                $maxData = $versions{$e}{maxVersion};
1282
                $countEntry = $e;
1283
            }
1284
        }
1285
        if ($countEntry)
1286
        {
1287
            $main = $countEntry;
1288
            delete $nexts{$countEntry};
1289
        }
1290
 
1291
        #
1292
        #   Append the remaining
1293
        #
1294
        push @ordered, keys %nexts;
1295
 
1296
        #
1297
        #   Re-order 'next' so that the main path is first
1298
        #   Sort (non main) by number
1299
        #
1300
        @ordered = sort {$a <=> $b} @ordered;
1301
        unshift @ordered, $main if ( $main );
1302
        @{$versions{$entry}{next}} = @ordered;
1303
 
1304
        #
1305
        #   Ensure all except the first are a branch point
1306
        #   First may still be a branch point
1307
        #
1308
        shift @ordered;
1309
        foreach my $e ( @ordered )
1310
        {
1311
            $versions{$e}{branchPoint} = 1;
1312
        }
1313
    }
1314
}
1315
 
1316
#-------------------------------------------------------------------------------
1317
# Function        : calcRippleGroups
1318
#
1319
# Description     : Locate and mark ripple groups
1272 dpurdie 1320
#                   packages that are ripples of each other
392 dpurdie 1321
#                       Keep first version of each ripple. Must keep first
1322
#                       Group ripples together so that they can be
1323
#                       proccessed at the same time
1324
#
1325
# Inputs          : 
1326
#
1327
# Returns         : 
1328
#
1329
sub calcRippleGroups
1330
{
1331
    my %rippleVersions;
1332
    foreach my $entry ( keys(%versions) )
1333
    {
1334
        my $ep = $versions{$entry};
1335
        if ( defined $ep->{buildVersion} )
1336
        {
1337
            my $suffix = $ep->{suffix};
1338
            my ($major, $minor, $patch, $build) = @{$ep->{buildVersion}};
1339
#print "--- $major, $minor, $patch, $build, $suffix\n";
1340
            $rippleVersions{$suffix}{"$major.$minor.$patch"}{count}++;
1341
            my $rp = $rippleVersions{$suffix}{"$major.$minor.$patch"};
1342
            $rp->{list}{$entry} = 1;
1343
 
1344
            next if ( $ep->{badVcsTag} );
1345
            next if ( $ep->{locked} eq 'N');
1346
            if (!defined ($rp->{min}) || $rp->{min} > $build )
1347
            {
1348
                $rp->{pvid} = $entry;
1349
                $rp->{min} = $build;
1350
            }
1351
        }
1352
    }
1353
#            DebugDumpData("rippleVersions", \%rippleVersions );
1354
 
1355
    while ( my($suffix, $e1) = each %rippleVersions )
1356
    {
1357
        while ( my( $mmp, $e2) = each %{$e1} )
1358
        {
1359
            next unless ( exists  $e2->{pvid} );
1360
            my $entry = $e2->{pvid};
1361
            if ( !exists $versions{$entry} )
1362
            {
1363
                Error ("Internal: Expected entry not found: $entry, $mmp");
1364
            }
1365
 
1366
            $versions{$entry}{keepLowestRipple} = 1;
1367
#print "--- Keep Riple $versions{$entry}{vname}\n";
1368
 
1369
            #
1370
            #   Update entry with list of associated ripples, removing lowest
1371
            #
1372
            delete $e2->{list}{$entry};
1373
            my @rippleList = sort keys %{$e2->{list}};
1374
            if ( @rippleList)
1375
            {
1376
#DebugDumpData("LIST: $entry", $e2->{list}, \@rippleList  );
1377
                @{$versions{$entry}{rippleList}} = @rippleList;
1378
            }
1379
        }
1380
    }
1381
}
1382
 
1383
#-------------------------------------------------------------------------------
1384
# Function        : processBranch
1385
#
1386
# Description     : Process one complete branch within the tree of versions
1387
#                   May be called recursivly to walk the tree
1388
#
1389
# Inputs          : Array of package-version ID to process
1390
#
1391
# Returns         : Nothing
1392
#
1393
 
1394
sub processBranch
1395
{
1396
    foreach my $entry ( @_ )
1397
    {
1398
        #
1399
        #   Do we need to create a branch before we can process this package
1400
        #
1401
        if ( $versions{$entry}{newSuffix} || $versions{$entry}{branchPoint} )
1402
        {
1403
            newProject();
1404
            $createBranch = 1;
1405
            $createSuffix = 1 if $versions{$entry}{newSuffix};
1406
        }
1407
 
1408
        newPackageVersion( $entry );
1409
no warnings "recursion";
1410
        processBranch (@{$versions{$entry}{next}});
1411
    }
1412
}
1413
 
1414
#-------------------------------------------------------------------------------
1415
# Function        : newPackageVersion
1416
#
1417
# Description     : Create a package version
1418
#
1419
# Inputs          : $entry              - Ref to entry being proccessed
1420
#
1421
# Returns         :
1422
#
1423
sub newPackageVersion
1424
{
1425
    my ($entry) = @_;
1426
    my %data;
1427
    my $flags = 'e';
1428
    my $rv = 1;
1429
    my $startTime = time();
1430
    my $timestamp = localtime;
1431
 
1432
    $data{rmRef} = 'ERROR';
1433
    $data{tag} = 'ERROR';
1434
 
1435
    #
1436
    #   If its been processed then fake that its been done
1437
    #   May have been a ripple that we processed
1438
    #
1270 dpurdie 1439
    return if ($versions{$entry}{Processed});
1440
    $processCount++;
392 dpurdie 1441
    Message ("------------------------------------------------------------------" );
1270 dpurdie 1442
    Message ("Package $processCount of $processTotal");
1443
 
392 dpurdie 1444
    Message ("New package-version: " . GetVname($entry) . " Tag: " . $versions{$entry}{vcsTag} );
1445
 
1328 dpurdie 1446
    #
1447
    #   Detect user abort
1448
    #
1449
    if ( -f $cwd . '/stopfile' )
1450
    {
1451
        $globalError = 1;
1452
        Message ("Stop file located");
1453
    }
392 dpurdie 1454
 
1455
    #
1456
    #   If we have a global error,then we pretend to process, but we
1457
    #   report errors for the logging system
1458
    #
1342 dpurdie 1459
    if ( $globalError )
392 dpurdie 1460
    {
1342 dpurdie 1461
        Message ("Global error prevents futher importation");
1462
    }
1463
    else
1464
    {
392 dpurdie 1465
        #
1466
        #   Call worker function
1467
        #   It will exist on any error so that it can be logged
1468
        #
1469
        $rv = newPackageVersionBody( \%data, @_ );
1470
        $globalError = 1 if ( $rv >= 10 );
1471
    }
1472
 
1473
    #
1474
    #   Highlight essential packages that failed to transfer
1475
    #
1476
    if ( $globalError ) {
1477
        $flags = 'e';
1478
    } elsif ( $rv && ( exists $versions{$entry}{Essential} ) ) {
1479
        $flags = 'X';
1480
    } elsif ( $rv ) {
1481
        $flags = 'E';
1482
    } else {
1483
        $flags = 'G';
1484
    }
1485
 
1486
    #
1487
    #   Always log results to a file
1488
    #   Flags:
1489
    #       e - Error: Global Fatal causes other versions to be ignored
1490
    #       X - Essential Package NOT proccessed
1491
    #       E - Error processing package
1492
    #       G - Good
1493
    #
1494
    my $duration = time() - $startTime;
1495
    my $line = join(';',
1496
            $flags,
1497
            $entry,
1498
            $packageNames,
1499
            $versions{$entry}{vname},
1500
            $data{rmRef},
1501
            $data{tag},
1502
            $timestamp,
1503
            $duration,
1504
            $data{errStr} || ''
1505
            );
1506
    logToFile( $cwd . '/importsummary.txt', ";$line;");
1507
    #
1508
    #   Sava data
1509
    #
1270 dpurdie 1510
    $data{errFlags} = $flags;
1511
    $data{duration} = $duration;
392 dpurdie 1512
    $versions{$entry}{rmRef} = $data{rmRef};
1270 dpurdie 1513
    delete $data{rmRef};
1514
    delete $data{tag};
1340 dpurdie 1515
    ##delete $data{ViewRoot};
1270 dpurdie 1516
    $versions{$entry}{data} = \%data;
1517
 
392 dpurdie 1518
    #
1519
    #   Delete the created view
1520
    #   Its just a directory, so delete it
1521
    #
1522
    if ( $data{ViewRoot} && -d $data{ViewRoot})
1523
    {
1340 dpurdie 1524
        if ( !$opt_reuse || $rv )
1525
        {
1526
            Message ("Delete View: $data{ViewRoot}");
1527
            RmDirTree ($data{ViewRoot} );
1528
        }
1529
        else
1530
        {
1531
            Message ("Retaining View: $data{ViewRoot}");
1532
        }
1533
 
392 dpurdie 1534
    }
1340 dpurdie 1535
    else
1536
    {
1537
        Message ("No view to delete");
1538
    }
392 dpurdie 1539
 
1540
 
1541
    #
1542
    #   If this version has any 'ripples' then process them while we have the
1543
    #   main view. Note the ripple list may contain entries that do not
1544
    #   exist - they will have been pruned.
1545
    #
1546
    foreach my $rentry ( @{$versions{$entry}{rippleList}} )
1547
    {
1548
        next unless( exists $versions{$rentry} );
1549
 
1550
        if ($versions{$rentry}{Processed})
1551
        {
1552
            Warning ("Ripple Processed before main entry");
1553
            $versions{$rentry}{rippleProcessed} = 1;
1554
        }
1555
 
1556
        Message ("Proccessing associated Ripple: " . GetVname($rentry));
1557
        newPackageVersion($rentry);
1558
    }
1559
}
1560
 
1561
#-------------------------------------------------------------------------------
1562
# Function        : newPackageVersionBody
1563
#
1564
# Description     : Perform the bulk of the work in creating a new PackageVersion
1565
#                   Designed to return on error and have error processing
1566
#                   performed by caller
1567
#
1568
# Inputs          : $data               - Shared data
1569
#                   $entry              - Package entry to process
1570
#
1571
# Returns         : Error Code
1572
#                         0 - All is well
1272 dpurdie 1573
#                       <10 - Recoverable error
392 dpurdie 1574
#                       >10 - Fatal error
1575
#
1576
sub newPackageVersionBody
1577
{
1578
    my ($data, $entry) = @_;
1579
    my $rv;
1580
    my $cc_label;
1581
    my $cc_path;
1582
 
1583
    #
1584
    #   Init Data
1585
    #
1586
    $data->{rmRef} = 'ERROR';
1587
    $data->{tag} = '';
1588
    $data->{ViewRoot} = undef;
1589
    $data->{ViewPath} = undef;
1590
    $data->{errStr} = '';
1591
    $versions{$entry}{Processed} = 1;
1592
 
1593
 
1594
    SystemConfig ('ExitOnError' => 0);
1595
 
1596
    push @processOrder, $entry;
1597
    return 0 if ( $opt_test );
1598
 
1599
#   Keep DeadWood. May be a WIP
1600
#    if ( exists $versions{$entry}{DeadWood} && $versions{$entry}{DeadWood} )
1601
#    {
1602
#        $data->{errStr} = 'Package is DeadWood';
1603
#        return 3;
1604
#    }
1605
 
1606
    #
1607
    #   Determine version information
1608
    #
1609
    $data->{tag} = $versions{$entry}{vcsTag} || '';
1610
    if ( $versions{$entry}{badVcsTag} )
1611
    {
1612
        Warning ("Error: Bad VcsTag for: " . GetVname($entry),
1613
                 "Tag: $data->{tag}" );
1614
        $data->{errStr} = 'VCS Tag Marked as Bad';
1615
        return 1;
1616
    }
1617
 
1618
 
1619
    $data->{tag} =~ m~^(.+?)::(.*?)(::(.+))?$~;
1620
    $cc_label = $4;
1621
    $cc_path = $2;
1622
    $cc_path = '/' . $cc_path;
1623
    $cc_path =~ tr~\\/~/~s;
1624
 
1625
    #
1626
    #   Correct well known path mistakes
1627
    #
394 dpurdie 1628
    $cc_path =~ s~/MASS_Dev/Bus/~/MASS_Dev_Bus/~i;
392 dpurdie 1629
    $cc_path =~ s~/MASS_Dev_Bus/Cbp/~/MASS_Dev_Bus/CBP/~i;
1630
    $cc_path =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
1197 dpurdie 1631
    $cc_path =~ s~/MREF_21/MREF_Package/~/MREF_Package/~i;
392 dpurdie 1632
 
1197 dpurdie 1633
 
392 dpurdie 1634
#print "--- Path: $cc_path, Label: $cc_label\n";
1635
 
1636
    #
1637
    #   Create CC view
1638
    #   Import into Subversion View
1639
    #
1640
    $data->{ViewRoot} = $opt_name ? $opt_name : "$cc_label";
1197 dpurdie 1641
    $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
1642
 
1643
    if ( $opt_preserveProjectBase )
1644
    {
1645
        my $cc_vob = $cc_path;
1646
        $cc_vob =~ s~^/~~;
1647
        $cc_vob =~ s~/.*~~;
1648
        $data->{ViewPath} =  $data->{ViewRoot} . '/' . $cc_vob;
1649
        Message ("Preserving Project Base");
1650
    }
392 dpurdie 1651
    $data->{ViewPath} =~  tr~/~/~s;
1652
 
1653
    if ( $opt_reuse && -d $data->{ViewPath}  )
1654
    {
1655
        Message ("Reusing view: $cc_label");
1656
    }
1657
    else
1658
    {
1659
        my @args;
1660
        push (@args, '-view', $opt_name ) if ( defined $opt_name );
1661
        $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
1662
                    "-label=$cc_label" ,
1663
                    "-path=$cc_path",
1664
                    @args
1665
                    );
1666
 
1667
        unless ( -d $data->{ViewPath}  )
1668
        {
1669
            $data->{errStr} = 'Failed to extract files from CC';
1670
            return 2;
1671
        }
1672
    }
1673
 
1197 dpurdie 1674
 
392 dpurdie 1675
    #
1197 dpurdie 1676
    #   Some really ugly packages make use of a Jats feature called 'SetProjectBase'
1677
    #   Detect such packages as we will need to handle them differently
1678
    #   Can't really handle it on the fly
1453 dpurdie 1679
    #   All we can do is detect it and report it - at the moment
1197 dpurdie 1680
    #
1681
    if (detectProjectBaseUsage($data, $cc_path) )
1682
    {
1683
        unless ( $opt_ignoreProjectBaseErrors )
1684
        {
1685
            $data->{BadProjectBase}++;
1686
            $data->{errStr} = 'Bad usage of ProjectBase detected';
1687
            return 14;
1688
        }
1689
    }
1690
 
1270 dpurdie 1691
 
1197 dpurdie 1692
    #
1270 dpurdie 1693
    #   Developers have been slack
1694
    #       Sometime the mark the source path as 'GMTPE2005'
1695
    #       Sometimes as 'GMTPE2005/Package/Fred/Jill/Harry'
1696
    #
1697
    #   Attempt to suck up empty directories below the specified
1698
    #   source path
1699
    #
1700
    unless ( $opt_preserveProjectBase )
1701
    {
1702
        #
1703
        #   Look in ViewPath
1704
        #   If it contains only ONE directory then we can suck it up
1705
        #
1706
        my $testDir = findDirWithStuff( $data->{ViewPath} );
1328 dpurdie 1707
 
1270 dpurdie 1708
        unless ( $data->{ViewPath} eq $testDir  )
1709
        {
1710
            Message ("Adjust Base Dir: $testDir");
1711
            $data->{adjustedPath} = $data->{ViewPath};
1712
            $data->{ViewPath} = $testDir;
1713
        }
1714
    }
1715
 
1716
 
1717
    #
392 dpurdie 1718
    #   Have a CC view
1719
    #   Now we can create the SVN package and branching point before we
1720
    #   import the CC data into SVN
1721
    #
1722
    my @args;
1723
 
1724
    #
1725
    #   Calculate args for functions
1726
    #
1727
    my $author = $versions{$entry}{created_id};
1728
    if ( $author )
1729
    {
1730
        push @args, '-author', $author;
1731
    }
1732
    my $created = $versions{$entry}{created};
1733
    if ( $created )
1734
    {
1735
        $created =~ s~ ~T~;
1736
        $created .= '00000Z';
1737
        push @args, '-date', $created;
1738
    }
1739
 
1740
    my $log = $versions{$entry}{comment};
1741
    if ( $log )
1742
    {
1743
        push @args, '-log', $log;
1744
    }
1745
 
1746
    #
1747
    #   Create package skeleton if needed
1748
    #
1749
    $rv = createPackage( $author, $created);
1750
    if ( $rv )
1751
    {
1752
        $data->{errStr} = 'Failed to create Package';
1753
        return 10;
1754
    }
1755
 
1756
    #
1757
    #   Calculate the label for the target package
1758
    #   Use format <packageName>_<PackageVersion>
1759
    #   Need to handle WIPs too.
1760
    #
1761
    my $import_label = saneLabel($entry);
1762
 
1763
    #
1764
    #   May need to create the branchpoint
1765
    #   The process is delayed until its needed so avoid creating unneeded
1766
    #   branch points
1767
    #
1768
    if ( $createBranch )
1769
    {
1770
        $rv = createBranchPoint ($entry, $author, $created);
1771
        $createBranch = 0;
1772
        $createSuffix = 0;
1773
        if ( $rv )
1774
        {
1775
            $data->{errStr} = 'Failed to create Branch Point';
1776
            return 11;
1777
        }
1778
    }
1779
    push @args, "-branch=$currentBranchName" if ( defined $currentBranchName );
1780
 
1781
    my $datafile = "importdata.$import_label.properties";
1782
    $rv = JatsToolPrint ( 'jats_svn', 'import', '-reuse' ,
1783
                    "-package=$svnRepo/$packageNames",
1784
                    "-dir=$data->{ViewPath}",
1785
                    "-label=$import_label",
1786
                    "-datafile=$datafile",
1787
                    @args,
1788
                     );
1789
 
1790
    if ( $rv )
1791
    {
1792
        $data->{errStr} = 'Failed to import to SVN';
1793
        return 12;
1794
    }
1795
 
1796
    $versions{$entry}{TagCreated} = 1;
1797
    $firstVersionCreated = $entry unless ( $firstVersionCreated );
1798
 
1799
    #
1800
    #   Read in the Rm Reference
1801
    #   Retain entries in a global file
1802
    #
1803
    if ( -f $datafile  )
1804
    {
1805
        my $rmData = JatsProperties::New($datafile);
1806
        $data->{rmRef} = 'SVN::' . $rmData->getProperty('subversion.tag');
1807
    }
1808
 
1809
    unless ( $data->{rmRef}  )
1810
    {
1272 dpurdie 1811
        $data->{errStr} = 'Failed to determine Rm Reference';
392 dpurdie 1812
        return 13;
1813
    }
1814
 
1380 dpurdie 1815
######################## Deleted ###############################################
1816
#
1817
#
1818
#    #
1819
#    #   Add supplemental tags if this version is in a 'Release'
1820
#    #   But only for some packages - else looks like a mess
1821
#    #   Just a solution for the ITSO guys
1822
#    #
1823
#    foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  )
1824
#    {
1825
#        next unless ( $svnRepo =~ m~/ITSO_TRACS(/|$)~);
1826
#
1827
#        my $prog_id = $versions{$entry}{Releases}{$rtag_id}{proj_id};
1828
#        Message ("Adding Release Tag:$prog_id:$rtag_id");
1829
#
1830
#        my $rtext = 'Release_' . saneString($versions{$entry}{Releases}{$rtag_id}{rname});
1831
#        my @comment;
1832
#        push @comment, "Tagged by ClearCase to Subversion import";
1833
#        push @comment, "Project:$prog_id:$versions{$entry}{Releases}{$rtag_id}{pname}";
1834
#        push @comment, "Release:$rtag_id:$versions{$entry}{Releases}{$rtag_id}{rname}";
1835
#
1836
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{name} = $rtext;
1837
#
1838
#        $rv = JatsToolPrint ( 'jats_svnlabel' ,
1839
#                    '-comment', encode('UTF-8', join("\n", @comment), Encode::FB_DEFAULT),
1840
#                    $data->{rmRef},
1841
#                    '-clone',
1842
#                    $rtext,
1843
##                    @args,
1844
#                    '-author=buildadm',
1845
#                     );
1846
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{eState} = $rv;
1847
#        $data->{ReleaseTag}{tCount}++;
1848
#
1849
#        if ( $rv )
1850
#        {
1851
#            $data->{ReleaseTag}{eCount}++;
1852
#            Warning("Failed to add Release Tag: $rtext");
1853
#        }
1854
#    }
1855
#
1856
######################## Deleted ###############################################
1341 dpurdie 1857
 
392 dpurdie 1858
    Message ("RM Ref: $data->{rmRef}");
1859
    unlink $datafile;
1860
 
1861
    #
1862
    #   All is good
1863
    #
1864
    $data->{errStr} = '';
1865
    return 0;
1866
}
1867
 
1868
 
1869
#-------------------------------------------------------------------------------
1870
# Function        : newProject
1871
#
1872
# Description     : Start a new project within a package
1873
#
1874
# Inputs          : 
1875
#
1876
# Returns         : 
1877
#
1878
sub newProject
1879
{
1880
#    Message ("---- New Project");
1881
    $createSuffix = 0;
1882
 
1883
    #
1884
    #   New project
1885
    #   Kill the running import directory
1886
    #
1887
    RmDirTree ('SvnImportDir');
1888
}
1889
 
1890
#-------------------------------------------------------------------------------
1891
# Function        : newPackage
1892
#
1893
# Description     : Start processing a new package
1894
#
1895
# Inputs          : 
1896
#
1897
# Returns         : 
1898
#
1899
my $createPackageDone;
1900
sub newPackage
1901
{
1902
#    Message( "---- New Package");
1903
 
1904
    #
1905
    #   Create a package specific log file
1906
    #
1907
    $logSummary = $packageNames . ".summary.log";
1908
    unlink $logSummary;
1909
    Message( "PackageName: $packageNames");
1910
    $createPackageDone = 1;
1911
    $createBranch = 0;
1912
    $createSuffix = 0;
1913
 
1914
    #
1915
    #   First entry being created
1916
    #   Prime the work area
1917
    #
1918
    RmDirTree ('SvnImportDir');
1919
}
1920
 
1921
#-------------------------------------------------------------------------------
1922
# Function        : createPackage
1923
#
1924
# Description     : Create a new Package in SVN
1925
#                   Called before any serious SVN operation to ensure that the
1926
#                   package has been created. Don't create a package until
1927
#                   we expect to put something into it.
1928
#
1929
#                   Will only create a package once
1930
 
1931
#
1932
# Inputs          : $author         - Who done it
1933
#                   $date           - When
1934
#
1935
# Returns         : 
1936
#
1937
sub createPackage
1938
{
1939
    my ($author, $date) = @_;
1940
    my @opts;
1941
    push (@opts, '-date', $date) if ( $date );
1942
    push (@opts, '-author', $author) if ( $author );
1943
    #
1944
    #   Only do once
1945
    #
1946
    return unless ( $createPackageDone );
1947
    $createPackageDone = 0;
1948
 
1197 dpurdie 1949
    #
1950
    #   Real import
1951
    #       Do not Delete package if it exists
1952
    #       Package must NOT exist
1953
    #
392 dpurdie 1954
    Message ("Creating new SVN package: $packageNames");
1270 dpurdie 1955
    if ( $opt_delete )
1956
    {
1957
        Message ("Delete existing version of package: $packageNames");
1958
        JatsToolPrint ( 'jats_svn', 'delete-package', '-noerror',  "$svnRepo/$packageNames" );
1959
    }
1197 dpurdie 1960
    JatsToolPrint ( 'jats_svn', 'create', "$svnRepo/$packageNames", '-new', @opts );
392 dpurdie 1961
}
1962
 
1963
 
1964
#-------------------------------------------------------------------------------
1965
# Function        : createBranchPoint
1966
#
1967
# Description     : Create a branch point for the current work
1968
#                   Perform the calculation to determine the details of
1969
#                   the branch point. The work will only be done when its
1970
#                   needed. This will avoid the creation of branchpoints
1971
#                   that are not used.
1972
#
1973
# Inputs          : $entry                  Entry being processed
1974
#                   $author         - Who done it
1975
#                   $date           - When
1976
#
1977
# Returns         : 
1978
#
1979
sub createBranchPoint
1980
{
1981
    my ($entry, $author, $date) = @_;
1982
    my $forceNewProject;
1983
 
1984
#    Message ("---- Create Branch Point");
1985
 
1986
    #
1987
    #   Find previous good tag
1988
    #   We are walking a tree so something should have been created, but
1989
    #   the one we want may have had an error
1990
    #
1991
    #   Walk backwards looking for one that has been created
1992
    #
1993
    my $last = $versions{$entry}{last};
1994
    while ( $last )
1995
    {
1996
        unless ( $versions{$last}{TagCreated} )
1997
        {
1998
            $last = $versions{$last}{last};
1999
        }
2000
        else
2001
        {
2002
            last;
2003
        }
2004
    }
2005
 
2006
    #
2007
    #   If we have walked back to the base of the tree
2008
    #   If we transferred any software at all, then use the first
2009
    #   version as the base for this disconnected version
2010
    #
2011
    #   Otherwise we create a new, and empty, view
2012
    #
2013
    unless ( $last )
2014
    {
2015
        if ( $firstVersionCreated )
2016
        {
2017
            Warning ("Cannot find previous version to branch. Use first version");
2018
            $last = $firstVersionCreated;
2019
        }
2020
        else
2021
        {
2022
            Warning ("Forcing First instance of a Project");
2023
            $forceNewProject = 1;
2024
        }
2025
    }
2026
 
2027
    #
2028
    #   Determine source name
2029
    #   This MUST have been created before we can branch
2030
    #
2031
    my $src_label;
2032
    $src_label = saneLabel($last) if $last;
2033
 
2034
    #
2035
    #   Create target name
2036
    #
2037
    my $tgt_label;
2038
    if ( $forceNewProject || $versions{$entry}{newSuffix} || $createSuffix || !defined $src_label )
2039
    {
2040
        #
2041
        #   Create target name based on project
2042
        #
2043
        return if ( $singleProject );
2044
 
2045
        my $suffix = $versions{$entry}{suffix};
2046
        if ( $suffix )
2047
        {
2048
            Error ("Unknown Project: $suffix") unless ( defined $Projects{$suffix} );
2049
 
2050
            #
2051
            #   If this project can be considered to be a truck, then 'claim' the
2052
            #   truck for the first created element.
2053
            #
2054
            if ( $Projects{$suffix}{Trunk} )
2055
            {
2056
                # This project can use the trunk, if it has not been allocated.
2057
                $ProjectTrunk = $suffix unless ( defined $ProjectTrunk );
2058
 
2059
                #
2060
                #   If this package has multiple instances of the potential
2061
                #   trunk, then don't place either of them on the trunk as it
2062
                #   may cause confusion
2063
                #
2064
                if ($knownProjects{$suffix}{count} < 2 )
2065
                {
2066
                    if ( $suffix eq $ProjectTrunk )
2067
                    {
2068
                        return unless $currentBranchName;
2069
                    }
2070
                }
2071
            }
2072
 
2073
            $tgt_label = $Projects{$suffix}{Name};
2074
            $tgt_label = $versions{$entry}{name} . '_' . $tgt_label if ($multiPackages);
2075
            if ( !exists $ProjectsBaseCreated{$tgt_label}  )
2076
            {
2077
                $ProjectsBaseCreated{$tgt_label} = 1;
2078
            }
2079
            else
2080
            {
2081
                #   Project Base Already taken
2082
                #   Have disjoint starting points
2083
                $tgt_label .= '.' . $ProjectsBaseCreated{$tgt_label} ++;
2084
            }
2085
        }
2086
        else
2087
        {
2088
            #
2089
            #   No suffix in use
2090
            #
2091
            #   Currently not handled
2092
            #   May have to force the use of the trunk
2093
            #
2094
            Error ("INTERNAL ERROR: No suffix present");
2095
        }
2096
    }
2097
    else
2098
    {
2099
        $tgt_label = saneLabel($entry, $src_label . '_for_');
2100
    }
2101
 
2102
    #
2103
    #   Save branch name for use when populating sandbox
2104
    #
2105
    $currentBranchName = $tgt_label;
2106
 
2107
    #
2108
    #   Perform the branch
2109
    #
2110
    if ( defined $src_label )
2111
    {
1328 dpurdie 2112
        #
1341 dpurdie 2113
        #   The 'clone' operation will backtrack the branch point
2114
        #   to the source of the label. This will make the output version
2115
        #   tree much prettier
1328 dpurdie 2116
        #
392 dpurdie 2117
        my @opts;
2118
        push (@opts, '-date', $date) if ( $date );
2119
        push (@opts, '-author', $author) if ( $author );
2120
 
2121
        JatsToolPrint ( 'jats_svnlabel',
2122
                        '-packagebase', "$svnRepo/$packageNames",
1341 dpurdie 2123
                        'tags/' . $src_label,
392 dpurdie 2124
                        '-branch',
2125
                        '-clone', $tgt_label,
2126
                        @opts
2127
                      );
2128
    }
2129
}
2130
 
2131
 
2132
#-------------------------------------------------------------------------------
2133
# Function        : endPackage
2134
#
2135
# Description     : End of package processing
2136
#                   Clean up and display problems
2137
#
2138
# Inputs          : 
2139
#
2140
# Returns         : 
2141
#
2142
sub endPackage
2143
{
2144
    RmDirTree ('SvnImportDir');
2145
 
2146
    #
2147
    #   Display versions that did get captured
2148
    #
2149
    foreach my $entry ( @processOrder )
2150
    {
2151
        $versions{$entry}{Scanned} = 1;
2152
        next unless ( $versions{$entry}{TagCreated} );
2153
        Warning ("Processed: " . GetVname($entry) . ' :: ' . $versions{$entry}{rmRef} || $versions{$entry}{errStr} || '???' );
2154
    }
2155
 
2156
    #
2157
    #   Display versions that did not get created
2158
    #
2159
    foreach my $entry ( @processOrder )
2160
    {
2161
        $versions{$entry}{Scanned} = 1;
2162
        next if ( $versions{$entry}{TagCreated} );
2163
        Warning ("Not Processed: " . GetVname($entry) );
2164
    }
2165
 
2166
    foreach my $entry ( keys(%versions) )
2167
    {
2168
        next if ( $versions{$entry}{Scanned} );
2169
        Warning ("(E) INTERNAL ERROR. Package Not Processed: " . GetVname($entry) );
2170
    }
2171
 
2172
    Message ("All Done");
2173
}
2174
 
1197 dpurdie 2175
#-------------------------------------------------------------------------------
2176
# Function        : detectProjectBaseUsage
2177
#
2178
# Description     : Detect and report usage of the SetProjectBase directive
2179
#
2180
# Inputs          : $data               - Ref to a hash of bits
2181
#                   $cc_path            - Packages cc_path
2182
#
2183
# Returns         : true    - Bad usage (Really good usage not detected)
2184
#                   false   - Good usage detected
2185
#
2186
sub detectProjectBaseUsage
2187
{
2188
    my ($data, $cc_path) = @_;
2189
    my $retval = 0;
2190
    my $eSuf = $opt_ignoreProjectBaseErrors ? '' : 'Error';
2191
 
2192
    #
2193
    #   Find makefile.pl
2194
    #
2195
    Message ("Locate JATS makefiles");
2196
    my $usesProjectBase = 0;
2197
    my $definesProjectBase = 0;
2198
    my $definitionError = 0;
2199
 
2200
    my $search = JatsLocateFiles->new("--Recurse=1",
2201
                                       "--FilterIn=makefile.pl",
2202
                                       );
2203
    my @makefiles = $search->search($data->{ViewRoot});
2204
    foreach my $file ( @makefiles )
2205
    {
2206
        if ( open( my $fh, '<', "$data->{ViewRoot}/$file" ) )
2207
        {
2208
            while ( <$fh> )
2209
            {
2210
                s~\s+$~~;
2211
                s~^\s+~~;
2212
                next if ( m~^#~ );
2213
 
2214
                if ( m~\$ProjectBase~ )
2215
                {
2216
                    $usesProjectBase++;
2217
                    Message ("Project Base Use: $_");
2218
                    $data->{UsesProjectBase}++;
2219
                }
2220
 
2221
                if ( m~^SetProjectBase~ )
2222
                {
2223
                    $definesProjectBase++;
2224
                    $data->{DefinesProjectBase}++;
2225
                    Warning ("Package uses SetProjectBase:",
2226
                             "Line: " . $_,
2227
                             "Root: " . "$data->{ViewRoot}",
2228
                             "File: " . "$data->{ViewRoot}/$file",
2229
                            );
2230
 
2231
                    # The only problem is if the user attempts to escape
2232
                    # from the root of the view.
2233
                    #
2234
                    # Examine the depth of the makefile with the directive
2235
                    # Examine the depth of the view base
2236
                    #
2237
                    #
2238
                    # Locate the build.pl file
2239
                    # This is the basis for for the directive
2240
                    #
2241
                    my $blevel;
2242
                    my @bpaths = split ('/', $file );
2243
                    while ( @bpaths )
2244
                    {
2245
                        $bpaths[-1] = 'build.pl';
2246
                        my $bfile = join '/', @bpaths ;
2247
                        if ( -f "$data->{ViewRoot}/$bfile" )
2248
                        {
2249
                            $blevel = scalar @bpaths;
2250
                            last;
2251
                        }
2252
                        pop @bpaths;
2253
                    }
2254
                    unless (defined $blevel)
2255
                    {
2256
                        Warning ("SetProjectBase$eSuf calculation failed - can't find build.pl");
2257
                        $retval = 1;
2258
                    }
2259
                    else
2260
                    {
2261
                        #
2262
                        #   Determine the depth of the view root
2263
                        #   This is given by cc_path, but cc_path has a leading /
2264
                        #
2265
                        my @cpaths = split ('/', $cc_path );
2266
                        my $clevel = (scalar @cpaths) - 1;
2267
                        my $max_up = $blevel - $clevel - 1;
2268
 
2269
                        m~--Up=(\d+)~i;
2270
                        my $ulevel = $1;
2271
                        if ( defined $ulevel )
2272
                        {
2273
                            my @paths = split ('/', $file );
2274
                            my $plevel = scalar @paths;
2275
 
2276
#print "--- blevel: $blevel\n";
2277
#print "--- bpaths: @bpaths\n";
2278
#print "--- ulevel: $ulevel\n";
2279
#print "--- paths: @paths\n";
2280
#print "--- plevel: $plevel\n";
2281
#print "--- cpaths: @cpaths\n";
2282
#print "--- clevel: $clevel\n";
2283
#print "--- max_up: $max_up\n";
2284
 
2285
                            if ( $ulevel > $max_up )
2286
                            {
2287
                                Warning ("SetProjectBase escapes view. MaxUp: $max_up, Up: $ulevel");
2288
                                $definitionError++;
2289
                            }
2290
                        }
2291
                        else
2292
                        {
2293
                            $retval = 1;
2294
                            Warning ("SetProjectBase$eSuf MAY escape view - can't detect level")
2295
                        }
2296
                    }
2297
                }
2298
            }
2299
            close $fh;
2300
        }
2301
        else
2302
        {
2303
            Warning ("SetProjectBase$eSuf - Cannot open makefile: $file");
2304
            $retval = 1;
2305
        }
2306
    }
2307
 
2308
    #
2309
    #   Detect defined, but not used
2310
    #
2311
    if ( $usesProjectBase && ! $definesProjectBase )
2312
    {
2313
        Warning ("SetProjectBase - Uses ProjectBase without defining it");
2314
    }
2315
 
2316
    if ( ! $usesProjectBase && $definesProjectBase )
2317
    {
2318
        Warning ("SetProjectBase - Defines ProjectBase without using it");
2319
    }
2320
 
2321
    if ( $usesProjectBase && $definesProjectBase && $definitionError )
2322
    {
2323
        Warning ("SetProjectBase$eSuf - Problem detected");
2324
        $retval = 1;
2325
    }
2326
    return $retval;
2327
}
2328
 
1270 dpurdie 2329
#-------------------------------------------------------------------------------
2330
# Function        : findDirWithStuff
2331
#
2332
# Description     : Find a directory that contains more than just another subdir
2333
#
2334
# Inputs          : $base               - Start of the scan
2335
#
2336
# Returns         : Path to dir with more than just a single dir in it
2337
#
2338
sub findDirWithStuff
2339
{
2340
    my ($base) = @_;
1197 dpurdie 2341
 
1270 dpurdie 2342
    while ( $base )
2343
    {
2344
    my $fileCount = 0;
2345
    my $dirCount = 0;
1272 dpurdie 2346
    my $firstDir;
1270 dpurdie 2347
 
2348
    my @list = glob( $base . '/*');
2349
    foreach ( @list )
2350
    {
2351
        next if ( $_ eq '.' );
2352
        next if ( $_ eq '..' );
2353
        if ( -d $_ )
2354
        {
2355
            $dirCount++;
1272 dpurdie 2356
            $firstDir = $_ unless ( defined $firstDir );
1270 dpurdie 2357
            return $base if ( $dirCount > 1  );
2358
        }
1272 dpurdie 2359
        elsif ( -e $_ )
1270 dpurdie 2360
        {
2361
            return $base;
2362
        }
1272 dpurdie 2363
 
2364
        # else its probably a dead symlink
1270 dpurdie 2365
    }
2366
    return $base unless ( $dirCount == 1  );
1272 dpurdie 2367
    $base = $firstDir;
1270 dpurdie 2368
    }
2369
}
2370
 
2371
 
1197 dpurdie 2372
#-------------------------------------------------------------------------------
2373
# Function        : JatsToolPrint
2374
#
2375
# Description     : Print and Execuate a JatsTool command
2376
#
2377
# Inputs          : 
2378
#
2379
# Returns         : 
2380
#
2381
 
392 dpurdie 2382
sub JatsToolPrint
2383
{
2384
    Information ("Command: @_");
2385
    JatsTool @_;
2386
}
2387
 
2388
sub GetVname
2389
{
2390
    my ($entry) = @_;
2391
    my $me = 'NONE';
2392
    if ( $entry )
2393
        {
2394
        $me = $versions{$entry}{vname};
2395
        unless ( $me )
2396
        {
2397
            $me = 'Unknown-' . $entry;
2398
        }
2399
    }
2400
    return $me;
2401
}
2402
 
2403
sub saneLabel
2404
{
2405
    my ($entry, $pkgname) = @_;
1272 dpurdie 2406
    my $me;
2407
    $me = $versions{$entry}{vname};
392 dpurdie 2408
    $pkgname = $versions{$entry}{name} unless ( defined $pkgname );
2409
 
2410
    Error ("Package does have a version string: pvid: $entry")
2411
        unless ( defined $me );
2412
 
2413
    #
2414
    #   Convert Wip format (xxxx) into a string that can be used for a label
2415
    #
2416
    if ( $me =~ m~^(.*)\((.*)\)(.*)$~ )
2417
    {
2418
        $me = $1 . '_' . $2 . '_' . $3 . '.WIP';
2419
        $me =~ s~_\.~.~;
2420
        $me =~ s~^_~~;
2421
    }
2422
 
2423
    #
2424
    #   Allow for WIPS
2425
    #   Get rid of multiple '_'
2426
    #   Replace space with -
2427
    #
2428
    $me = $pkgname . '_' . $me;
2429
    $me =~ tr~ ~-~s;
2430
    $me =~ tr~-~-~s;
2431
    $me =~ tr~_~_~s;
2432
 
2433
    return $me;
2434
}
2435
 
1341 dpurdie 2436
sub saneString
2437
{
2438
    my ($string) = @_;
2439
    #
2440
    #   Get rid of multiple '_'
2441
    #   Replace space with -
2442
    #
2443
    $string =~ s~\W~_~g;
2444
    $string =~ tr~ ~_~s;
2445
    $string =~ tr~_-~-~s;
2446
    $string =~ tr~-_~-~s;
2447
    $string =~ tr~-~-~s;
2448
    $string =~ tr~_~_~s;
2449
    $string =~ s~-$~~;
2450
    $string =~ s~_$~~;
392 dpurdie 2451
 
1341 dpurdie 2452
    return $string;
2453
}
2454
 
2455
 
392 dpurdie 2456
exit 0;
2457
 
2458
 
2459
#-------------------------------------------------------------------------------
2460
# Function        : GetPkgIdByName
2461
#
2462
# Description     :
2463
#
2464
# Inputs          : pkg_name
2465
#
2466
# Returns         : pkg_id
2467
#
2468
sub GetPkgIdByName
2469
{
2470
    my ( $pkg_name ) = @_;
2471
    my (@row);
2472
    my $pv_id;
2473
    my $pkg_id;
2474
 
2475
    #
2476
    #   Establish a connection to Release Manager
2477
    #
2478
    connectRM(\$RM_DB) unless ( $RM_DB );
2479
 
2480
    #
2481
    #   Extract data from Release Manager
2482
    #
2483
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
2484
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
2485
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
2486
 
2487
    my $sth = $RM_DB->prepare($m_sqlstr);
2488
    if ( defined($sth) )
2489
    {
2490
        if ( $sth->execute( ) )
2491
        {
2492
            if ( $sth->rows )
2493
            {
2494
                while ( @row = $sth->fetchrow_array )
2495
                {
2496
                    Verbose( "DATA: " . join(',', @row) );
2497
                    $pkg_id = $row[1] || 0;
2498
                    last;
2499
                }
2500
            }
2501
            else
2502
            {
2503
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
2504
            }
2505
            $sth->finish();
2506
        }
2507
    }
2508
    else
2509
    {
2510
        Error("GetPkgIdByName:Prepare failure" );
2511
    }
2512
 
2513
    return $pkg_id;
2514
}
2515
 
2516
#-------------------------------------------------------------------------------
2517
# Function        : GetData_by_pkg_id
2518
#
2519
# Description     :
2520
#
2521
# Inputs          : pv_id
2522
#
2523
# Returns         :
2524
#
2525
sub GetData_by_pkg_id
2526
{
2527
    my ( $pkg_id, $packageName ) = @_;
2528
    my (@row);
2529
 
2530
    #
2531
    #   Establish a connection to Release Manager
2532
    #
2533
    Message ("Extract package versions from Release Manager: $packageName");
2534
    connectRM(\$RM_DB) unless ( $RM_DB );
2535
 
2536
    #
2537
    #   Extract data from Release Manager
2538
    #
2539
    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 ".
2540
                   " FROM RELEASE_MANAGER.PACKAGES pkg, RELEASE_MANAGER.PACKAGE_VERSIONS pv, ACCESS_MANAGER.USERS amu" .
2541
                   " WHERE pv.PKG_ID = \'$pkg_id\' AND pkg.PKG_ID = pv.PKG_ID AND amu.USER_ID (+) = pv.CREATOR_ID";
2542
 
2543
 
2544
    my $sth = $RM_DB->prepare($m_sqlstr);
2545
    if ( defined($sth) )
2546
    {
2547
        if ( $sth->execute( ) )
2548
        {
2549
            if ( $sth->rows )
2550
            {
2551
                while ( @row = $sth->fetchrow_array )
2552
                {
2553
                    Verbose( "DATA: " . join(',', @row) );
2554
                    my $pkg_name = $row[0] || 'Unknown';
2555
                    my $pkg_ver = $row[1] || 'Unknown';
2556
                       $pkg_ver =~ s~\s+$~~;
2557
                       $pkg_ver =~ s~^\s+~~;
2558
                    my $pv_id = $row[3] || 'Unknown';
2559
                    my $last_pv_id = $row[4];
2560
                    my $created =  $row[5] || 'Unknown';
2561
                    my $vcstag =  $row[6] || 'Unknown';
395 dpurdie 2562
 
392 dpurdie 2563
                    my $created_id =  $row[7] || ($row[10] ? "Userid_$row[10]" :'Unknown');
2564
                    my $comment =  $row[8] || '';
2565
                    my $locked =  $row[9] || 'N';
2566
 
2567
                    #
2568
                    #   Some developers have a 'special' package version
2569
                    #   We really need to ignore them
2570
                    #
2571
                    next if ( $pkg_ver eq '23.23.23.ssw' );
2572
 
2573
                    #
2574
                    #   Add data to the hash
2575
                    #       Remove entries that address themselves
2576
                    #
2577
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id || $last_pv_id == 0) ;
2578
                    $versions{$pv_id}{name} = $pkg_name;
2579
                    $versions{$pv_id}{pvid} = $pv_id;
2580
                    $versions{$pv_id}{vname} = $pkg_ver;
2581
                    $versions{$pv_id}{vcsTag} = $vcstag;
2582
                    $versions{$pv_id}{created} = $created;
2583
                    $versions{$pv_id}{created_id} = $created_id;
2584
                    $versions{$pv_id}{comment} = $comment;
2585
                    $versions{$pv_id}{locked} = $locked;
2586
                    $versions{$pv_id}{TimeStamp} = str2time( $created );
2587
                    $versions{$pv_id}{Age} = ($now - $versions{$pv_id}{TimeStamp}) / (60 * 60 * 24);
2588
                    $versions{$pv_id}{TooOld} = 1 if ( $opt_age && $opt_age <= $versions{$pv_id}{Age} );
2589
                    examineVcsTag($pv_id);
2590
 
2591
                    #
2592
                    #   Process version number
2593
                    #
2594
                    my ($suffix, $version, $isaR, $isaWip, $buildVersion ) = massageVersion($pkg_ver, $pkg_name);
2595
 
2596
                    $versions{$pv_id}{version} = $version;
2597
                    $versions{$pv_id}{buildVersion} = $buildVersion;
2598
                    $versions{$pv_id}{isaRipple} = 1 if ( $isaR );
2599
                    $versions{$pv_id}{isaWip} = 1 if ( $isaWip );
2600
 
2601
                    #
2602
                    #   Process suffix
2603
                    #
2604
                    $suffix = 'Unknown' unless ( $suffix );
2605
                    $suffix = lc ($suffix);
2606
                    $versions{$pv_id}{suffix} = $suffix;
2607
                    push @{$suffixes{$suffix}}, $pv_id;
2608
 
2609
#                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $locked, $created, $created_id, $suffix\n";
2610
                }
2611
            }
2612
            else
2613
            {
2614
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
2615
            }
2616
            $sth->finish();
2617
        }
2618
        else
2619
        {
2620
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
2621
        }
2622
    }
2623
    else
2624
    {
2625
        Error("GetData_by_pkg_id:Prepare failure" );
2626
    }
2627
}
2628
 
2629
#-------------------------------------------------------------------------------
2630
# Function        : massageVersion
2631
#
2632
# Description     : Process a version number and return usful bits
2633
#
2634
# Inputs          : Version Number
2635
#                   Package Name - debug only
2636
#
2637
# Returns         : An array
2638
#                       suffix
2639
#                       multipart version string useful for text comparisons
2640
#
2641
sub massageVersion
2642
{
2643
    my ($version, $name) = @_;
2644
    my ($major, $minor, $patch, $build, $suffix);
2645
    my $result;
2646
    my $buildVersion;
2647
    my $isaRipple;
2648
    my $isaWIP;
2649
    $build = 0;
2650
 
2651
#print "--- $name, $version\n";
2652
    $version =~ s~^_~~;
2653
    $version =~ s~^${name}_~~;
2654
 
2655
    #
2656
    #   xxxxxxxxx.nnnn.cots
2657
    #
2658
    if ( $version =~ m~(.*)\.cots$~ ) {
2659
        my $cots_base = $1;
2660
        $suffix = '.cots';
2661
        if ( $version =~ m~(.*?)\.([0-9]{4})\.cots$~ )
2662
        {
2663
            $result = $1 . sprintf (".%4.4d", $2) . $suffix;
2664
        }
2665
        else
2666
        {
2667
            $result = $cots_base . '.0000.cots';
2668
        }
2669
    }
2670
    #
2671
    #   Convert version into full form for comparisions
2672
    #       nnn.nnn.nnn.[p]nnn.xxx
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
    #   Don't flag as ripples - they are patches
2678
    #
2679
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-.p][p]?(\d+)([-.](.*))?$~ ) {
2680
        $major = $1;
2681
        $minor = $2;
2682
        $patch = $3;
2683
        $build = $4;
2684
        $suffix = defined $6 ? ".$6" : '';
2685
        $isaRipple = 0;
2686
    }
2687
    #
2688
    #       nn.nnn.nnnnn.xxx
2689
    #       nn.nnn.nnnnn-xxx
2690
    #       nnn.nnn.nnnx.xxx
2691
    #   Don't flag as ripples - they are patches
2692
    #
2693
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)\w?([-.](.*))?$~ ) {
2694
        $major = $1;
2695
        $minor = $2;
2696
        $patch = $3;
2697
        if ( length( $patch) >= 4 )
2698
        {
2699
            $build = substr( $patch, -3 ,3);
2700
            $patch = substr( $patch,  0 ,length($patch)-3);
2701
        }
2702
        $suffix = defined $5 ? ".$5" : '';
2703
    }
2704
 
2705
    #
2706
    #       nnn.nnn.nnn
2707
    #       nnn.nnn-nnn
2708
    #       nnn.nnn_nnn
2709
    #
2710
    elsif ( $version =~ m~^(\d+)\.(\d+)[-._](\d+)$~ ) {
2711
        $major = $1;
2712
        $minor = $2;
2713
        $patch = $3;
2714
        $suffix = '';
2715
    }
2716
 
2717
    #
2718
    #       nnn.nnn.nnn.nnn
2719
    #       nnn.nnn.nnn-nnn
2720
    #       nnn.nnn.nnn_nnn
2721
    #
2722
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-._](\d+)$~ ) {
2723
        $major = $1;
2724
        $minor = $2;
2725
        $patch = $3;
2726
        $build = $4;
2727
        $suffix = '';
2728
        $isaRipple = 0;
2729
    }
2730
 
2731
 
2732
    #
2733
    #       nnn.nnn
2734
    #
2735
    elsif ( $version =~ m~^(\d+)\.(\d+)$~ ) {
2736
        $major = $1;
2737
        $minor = $2;
2738
        $patch = 0;
2739
        $suffix = '';
2740
    }
2741
    #
2742
    #       nnn.nnn.xxx
2743
    #
2744
    elsif ( $version =~ m~^(\d+)\.(\d+)(\.\w+)$~ ) {
2745
        $major = $1;
2746
        $minor = $2;
2747
        $patch = 0;
2748
        $suffix = $3;
2749
    }
2750
 
2751
    #
2752
    #       nnn.nnn.nnnz
2753
    #
2754
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)([a-z])$~ ) {
2755
        $major = $1;
2756
        $minor = $2;
2757
        $patch = $3;
2758
        $build = ord($4) - ord('a');
2759
        $suffix = '.cots';
2760
        $isaRipple = 0;
2761
    }
2762
    #
2763
    #       ???REV=???
2764
    #
2765
    elsif ( $version =~ m~REV=~ ) {
2766
        $suffix = '.cots';
2767
        $result = $version . '.0000.cots';
2768
    }
2769
 
2770
    #
2771
    #   Wip Packages
2772
    #   (nnnnnn).xxx
2773
    #   Should be essential, but want to sort very low
2774
    #
2775
    elsif ($version =~ m~\((.*)\)(\..*)?~) {
2776
        $suffix = $2 || '';
2777
        $result = "000.000.000.000$suffix";
2778
        $isaWIP = 1;
2779
    }
2780
 
2781
    #
2782
    #   !current
2783
    #
2784
    elsif ($version eq '!current' || $version eq 'current_$USER' || $version eq 'current' || $version eq 'beta' || $version eq 'latest' || $version eq 'beta.cr' || $version eq 'CREATE') {
2785
        $suffix = '';
2786
        $result = "000.000.000.000$suffix";
2787
        $isaWIP = 1;
2788
    }
2789
 
2790
    #
2791
    #   Also WIP: FINRUN.103649.BEI.WIP
2792
    elsif ($version =~ m~(\.[a-zA-Z]+)\.WIP$~) {
2793
        $suffix = lc($1);
2794
        $result = "000.000.000.000$suffix";
2795
        $isaWIP = 1;
2796
    }
2797
 
2798
    #
2799
    #   Also ERGOFSSLS190100_015
2800
    #   Don't flag as a ripple
2801
    elsif ($version =~ m~^ERG[A-Z]+(\d\d)(\d\d)(\d\d)[-_](\d+)(\.\w+)?$~) {
2802
        $major = $1;
2803
        $minor = $2;
2804
        $patch = $3;
2805
        $build = $4;
2806
        $suffix = $5 || '.sls';
2807
        $isaRipple = 0;
2808
    }
2809
 
2810
    #
2811
    #   Stuff we don't yet handle
2812
    #
2813
    else  {
2814
        Warning ("Unknown version number: $name,$version");
2815
        $version =~ m~(\.\w+)$~;
2816
        $suffix = $1 || '';
2817
        $result = $version;
2818
    }
2819
 
2820
    $isaRipple = ($build > 0) unless defined $isaRipple;
2821
    unless ( $result )
2822
    {
2823
        # Major and minor of 99.99 are normally funy versions
2824
        # Don't make important desicions on them
2825
        #
2826
        if ( $major == 99 && $minor == 99 )
2827
        {
2828
            $major = 0;
2829
            $minor = 0;
2830
            $patch = 0;
2831
        }
2832
 
2833
        $result = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $major,$minor,$patch,$build,$suffix || '.0000');
2834
        $buildVersion = [ $major, $minor, $patch, $build ];
2835
    }
2836
 
2837
    $suffix = lc( $suffix );
2838
    if ( exists $suffixFixup{$suffix} )
2839
    {
2840
        $suffix = $suffixFixup{$suffix} ;
2841
    }
2842
 
2843
    return ($suffix, $result, $isaRipple, $isaWIP, $buildVersion );
2844
}
2845
 
2846
#-------------------------------------------------------------------------------
395 dpurdie 2847
# Function        : vcsCleanup
2848
#
2849
# Description     : Cleanup and rewrite a vcstag
2850
#
2851
#                   DUPLICATED IN:
2852
#                       - cc2svn_procdata
2853
#                       - cc2svn_importpackage
2854
#
2855
# Inputs          : vcstag
2856
#
2857
# Returns         : Cleaned up vcs tag
2858
#
2859
sub vcsCleanup
2860
{
2861
    my ($tag) = @_;
2862
    $tag =~ tr~\\/~/~;
2863
    if ( $tag =~ m~^CC::~ )
2864
    {
2865
        $tag =~ s~CC::\s+~CC::~;
2866
        $tag =~ s~MASS_Dev_Bus/Cbp/~MASS_Dev_Bus/CBP/~i;
2867
        $tag =~ s~MASS_Dev_Bus~MASS_Dev_Bus~i;
2868
        $tag =~ s~/MASS_Dev/Infra~MASS_Dev_Infra~i;
2869
        $tag =~ s~/MASS_Dev/Bus/web~/MASS_Dev_Bus/web~i;
2870
 
2871
        $tag =~ s~/Vastraffik/~/Vasttrafik/~;
2872
        $tag =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
2873
        $tag =~ s~DPC_SWCode/~DPG_SWCode/~i;
2874
    }
2875
    return $tag;
2876
}
2877
 
2878
#-------------------------------------------------------------------------------
392 dpurdie 2879
# Function        : examineVcsTag
2880
#
2881
# Description     : Examine a VCS Tag and determine if it looks like rubbish
395 dpurdie 2882
#                   Give it a clean
392 dpurdie 2883
#
2884
# Inputs          : $entry
2885
#
2886
# Returns         : Will add Data to the $entry
2887
#
2888
sub examineVcsTag
2889
{
2890
    my ($entry) = @_;
2891
    my $bad = 0;
395 dpurdie 2892
 
2893
    $versions{$entry}{vcsTag} = vcsCleanup($versions{$entry}{vcsTag});
392 dpurdie 2894
    my $vcstag = $versions{$entry}{vcsTag};
395 dpurdie 2895
 
392 dpurdie 2896
    if ( $vcstag =~ m~^SVN::~ ) {
2897
        $versions{$entry}{isSvn} = 1;
2898
 
2899
    } elsif ( $vcstag =~ m~^CC::(.*?)(::(.+))?$~ ) {
2900
        my $path = $1  || '';
2901
        my $label = $2 || '';
2902
        $bad = 1 unless ( $label );
2903
        $bad = 1 if ( $label =~ m~^N/A$~i || $label  =~ m~^na$~i );
2904
 
2905
        $bad = 1 unless ( $path );
2906
        $bad = 1 if ( $path =~ m~^N/A$~i || $path  =~ m~^na$~i );
2907
        $bad = 1 if ( $path =~ m~^/dpkg_archive~ || $path  =~ m~^dpkg_archive~ );
2908
        $bad = 1 if ( $path =~ m~^/devl/~ || $path  =~ m~^devl/~ );
395 dpurdie 2909
        $bad = 1 if ( $path =~ m~^CVS~ );
392 dpurdie 2910
        $bad = 1 if ( $path =~ m~^http:~i );
2911
        $bad = 1 if ( $path =~ m~^[A-Za-z]\:~ );
2912
        $bad = 1 if ( $path =~ m~^//~ );
395 dpurdie 2913
        $bad = 1 if ( $path =~ m~^/*none~i );
2914
        $bad = 1 if ( $path =~ m~^/*NoWhere~i );
2915
        $bad = 1 if ( $path =~ m~^-$~i );
392 dpurdie 2916
        $bad = 1 if ( $path =~ m~^cvsserver:~ );
2917
        $bad = 1 if ( $path =~ m~,\s*module:~ );
2918
#        $bad = 1 unless ( $path =~ m~^/~ );
2919
    }
2920
    else
2921
    {
2922
        $bad = 1;
2923
    }
2924
    $versions{$entry}{badVcsTag} = 1 if ( $bad );
2925
}
2926
 
2927
#-------------------------------------------------------------------------------
2928
# Function        : logToFile
2929
#
2930
# Description     : Log some data to a named file
2931
#                   Use file locking to allow multiple process to log
2932
#
2933
# Inputs          : $filename           - Name of file to log
2934
#                   ...                 - Data to log
2935
#
2936
# Returns         : Nothing
2937
#
2938
sub logToFile
2939
{
2940
    my ($file, @data) = @_;
2941
 
2942
    open  (LOGFILE, '>>', $file);
2943
    flock (LOGFILE, LOCK_EX);
2944
    print  LOGFILE "@data\n";
2945
    flock (LOGFILE, LOCK_UN);
2946
    close (LOGFILE);
2947
}
2948
 
2949
#-------------------------------------------------------------------------------
2950
# Function        : createImages
2951
#
2952
# Description     : Create nice images of the RM version tree
2953
#
2954
# Inputs          : 
2955
#
2956
# Returns         : 
2957
#
2958
sub createImages
2959
{
2960
 
2961
    my $filebase = "${packageNames}";
2962
    open (FH, '>', "$filebase.dot" ) or die "Cannot open output";
2963
    print FH "digraph \"${packageNames}\" {\n";
2964
    #print FH "rankdir=LR;\n";
2965
    print FH "node[fontsize=16];\n";
2966
    print FH "node[target=_graphviz];\n";
2967
#    print FH "subgraph cluster_A {\n";
2968
#    print FH "node[fontsize=12];\n";
2969
 
2970
    {
2971
        my @text;
2972
        push @text, $packageNames;
2973
        push @text, 'HyperLinked to Release Manager';
2974
        push @text, 'Created:' . localtime();
2975
        push @text, '|';
2976
 
2977
        push @text, 'Total RM versions: ' . $totalVersions;
2978
        push @text, 'Essential Entries: ' . scalar @EssentialPackages;
2979
        push @text, 'Initial trees: ' . $initialTrees;
2980
 
1270 dpurdie 2981
        push @text, 'Number of Entries: ' . $processTotal;
392 dpurdie 2982
        push @text, 'Type : ' . $packageType;
2983
        push @text, 'All versions in Subversion' if ( $allSvn );
2984
 
2985
        push @text, '|';
2986
        push @text, 'Total Project Branches: ' . $ProjectCount;
2987
        foreach ( sort keys %knownProjects )
2988
        {
2989
            my $count = $knownProjects{$_}{count} || 0;
2990
            if ( $count )
2991
            {
2992
                my $text = 'Project Branch: ' . $_;
2993
                $text .= " (" . $count . ")" if ( $count > 1 );
2994
                push @text, $text;
2995
            }
2996
        }
2997
 
2998
        push @text, '|';
2999
        push @text, 'Bad VCS : ' . $badVcsCount;
3000
        push @text, 'Bad Singletions : ' . $badSingletonCount;
3001
        push @text, 'Deadwood entries : ' . $trimCount;
3002
        push @text, 'Walking Mode : Flat' if ($opt_flat);
3003
        push @text, 'Pruned Mode : ' . $pruneModeString;
3004
        push @text, 'Pruned entries : ' . $pruneCount;
1272 dpurdie 3005
        push @text, 'Recent entries : ' . $recentCount;
392 dpurdie 3006
 
3007
        if ( @unknownProjects )
3008
        {
3009
            push @text, '|';
3010
            push @text, 'Unknown Projects';
3011
            push @text, 'Unknown Project: ' . $_ foreach (sort @unknownProjects );
3012
        }
3013
 
3014
        #
3015
        #   Multiple Paths
3016
        #
3017
        if ( scalar @multiplePaths > 1 )
3018
        {
3019
            push @text, '|';
3020
            push @text, 'Multiple Paths';
3021
            push @text, @multiplePaths;
3022
        }
3023
 
3024
        #
3025
        #   Bad essentials
3026
        #
3027
        if ( @badEssentials  )
3028
        {
3029
            push @text, '|';
3030
            push @text, 'Bad Essential Versions';
3031
            push @text, GetVname($_) foreach ( @badEssentials );
3032
        }
3033
 
3034
        #
3035
        #   Subversion Data
3036
        #
3037
        if ( %svnData )
3038
        {
3039
            push @text, '|';
3040
            push @text, 'Subversion';
3041
            push @text, 'Trunk used' if exists $svnData{branches}{trunk} ;
3042
            push @text, 'Labels: ' . scalar keys %{$svnData{tags}} ;
3043
            push @text, 'Branches: ' . scalar keys %{$svnData{branches}} ;
3044
        }
3045
 
3046
        push @text, '';
3047
        my $text = join '\l', @text;
3048
        $text =~ s~\|\\l~|~g;
3049
 
3050
        my @attributes;
3051
        push @attributes, "shape=record";
3052
        push @attributes, "label=\"{$text}\"";
3053
        push @attributes, "tooltip=\"$packageNames\"";
1272 dpurdie 3054
        push (@attributes, "URL=\"" . $GBE_RM_URL . "/view_by_version.asp?pkg_id=$first_pkg_id" . "\"" )if $first_pkg_id;
392 dpurdie 3055
        push @attributes, "color=red";
3056
        my $attr = join( ' ', @attributes);
3057
 
3058
        my $tld_done = 'TitleBlock';
3059
        print FH "$tld_done [$attr]\n";
3060
    }
3061
 
3062
    #
3063
    #   Generate Legend
3064
    #
3065
    {
3066
        my @text;
3067
        push @text, 'Legend';
3068
        push @text, '|';
3069
        push @text, 'Node Content';
3070
        push @text, 'Package Version';
3071
#        push @text, 'Release Manager Ref (pvid)';
3072
        push @text, 'Creation Date: yyyy-mm-dd';
3073
        push @text, '(Coded information)';
3074
        push @text, '|{Code';
3075
        push @text, '|{N: Not Locked';
3076
        push @text, 'b: Bad Singleton';
3077
        push @text, 'B: Bad VCS Tag';
3078
        push @text, 'D: DeadWood';
1272 dpurdie 3079
        push @text, 'E: Essential Release Version';
392 dpurdie 3080
        push @text, 'G: Glued into Version Tree';
1272 dpurdie 3081
        push @text, 'r: Recent version';
1328 dpurdie 3082
        push @text, 'R: Ripple';
392 dpurdie 3083
        push @text, 'S: Splitpoint';
3084
        push @text, 't: Glued into Project Tree';
3085
        push @text, 'T: Tip version';
3086
        push @text, 'V: In SVN';
3087
        push @text, '+: In Subversion';
3088
        push @text, '}}';
3089
 
3090
        push @text, '|';
3091
        push @text, 'Outline';
3092
        push @text, 'Red: Dead or Bad VCS Tag';
3093
        push @text, 'Orange: Project Branch Root';
3094
        push @text, 'Green: Ripple Build Version';
3095
        push @text, 'Blue: Essential Version';
3096
        push @text, 'Darkmagenta: Entry Glued into tree';
3097
        push @text, 'Magenta: Entry added to project tree';
3098
 
3099
 
3100
        push @text, '|';
3101
        push @text, 'Fill';
3102
        push @text, 'PowderBlue: Essential Version';
3103
        push @text, 'Red: Bad Essential Version';
3104
        push @text, 'Light Green: Migrated to SVN';
3105
#        push @text, 'Red: Entry Glued into tree';
3106
#        push @text, 'Green: Entry added to project tree';
3107
 
3108
        push @text, '|';
3109
        push @text, 'Shape';
3110
        push @text, 'Oval: Normal Package Version';
3111
        push @text, 'Invhouse: Project Branch Root';
3112
        push @text, 'Octagon: Branch Point';
3113
        push @text, 'Box: Bad Single version with no history';
3114
        push @text, 'Doublecircle: Tip of a Project Branch';
3115
 
3116
        push @text, '';
3117
        my $text = join '\l', @text;
3118
        $text =~ s~\|\\l~|~g;
3119
        $text =~ s~\}\\l~}~g;
3120
 
3121
        my @attributes;
3122
        push @attributes, "shape=record";
3123
        push @attributes, "label=\"{$text}\"";
3124
        push @attributes, "color=red";
3125
        my $attr = join( ' ', @attributes);
3126
 
3127
        my $tld_done = 'LegendBlock';
3128
        print FH "$tld_done [$attr]\n";
3129
    }
3130
 
3131
#    print FH "\n}\n";
3132
    print FH "TitleBlock -> LegendBlock [style=invis]\n";
3133
 
3134
    sub genLabelText
3135
    {
3136
        my ($entry) = @_;
3137
        my @label;
3138
        push @label, $versions{$entry}{name} if ( $multiPackages );
3139
        push @label, $versions{$entry}{vname};
3140
#        push @label, $entry;       # Add PVID
3141
        push @label, substr( $versions{$entry}{created}, 0, 10); #  2008-02-19
3142
#        push @label, 'V=' . $versions{$entry}{maxVersion};
3143
#        push @label, 'B=' . $versions{$entry}{svnBranchTip} if ( exists $versions{$entry}{svnBranchTip} );
3144
 
3145
 
3146
        my $stateText = '';
3147
        $stateText .= 'N' if ($versions{$entry}{locked} eq 'N');
3148
        $stateText .= 'b' if (exists $versions{$entry}{badSingleton});
3149
        $stateText .= 'B' if (exists $versions{$entry}{badVcsTag});
3150
        $stateText .= 'G' if (exists $versions{$entry}{GluedIn});
3151
        $stateText .= 't' if (exists $versions{$entry}{MakeTree});
3152
        $stateText .= 'E' if (exists $versions{$entry}{Essential});
3153
        $stateText .= 'D' if (exists $versions{$entry}{DeadWood});
1328 dpurdie 3154
        $stateText .= 'R' if ( $versions{$entry}{isaRipple} );
1272 dpurdie 3155
        $stateText .= 'r' if (exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 3156
        $stateText .= 'S' if (exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
3157
        $stateText .= 'T' if (exists $versions{$entry}{Tip} );
3158
        $stateText .= 'V' if (exists $versions{$entry}{isSvn} );
3159
        $stateText .= '+' if (exists $versions{$entry}{svnVersion} );
3160
#        $stateText .= 's' if (exists $versions{$entry}{branchPoint} );
3161
#        $stateText .= ' T='. $versions{$entry}{threadId} if (exists $versions{$entry}{threadId});
3162
#        $stateText .= ' EssentalPath' if (exists $versions{$entry}{EssentialPath});
3163
#        $stateText .= ' Count='. $versions{$entry}{EssentialSplitPoint} if (exists $versions{$entry}{EssentialSplitPoint});
3164
#        $stateText .= ' M='. $versions{$entry}{maxVersion} if (exists $versions{$entry}{maxVersion});
3165
 
3166
        push @label, "(${stateText})" if ( $stateText );
3167
 
1341 dpurdie 3168
##       Insert Release Names
1451 dpurdie 3169
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
3170
            next unless ( exists $ukHopsReleases{$rtag_id} );
3171
            push @label, "Release: $versions{$entry}{Releases}{$rtag_id}{rname}";
3172
        }
1341 dpurdie 3173
 
392 dpurdie 3174
        return join ('\n', @label );
3175
    }
3176
 
3177
    sub genAttributes
3178
    {
3179
        my ($entry) = @_;
3180
        my @attributes;
3181
        push @attributes, 'label="' . genLabelText($entry) . '"';
3182
        push @attributes, 'URL="' . dotUrl($entry) . '"';
3183
        push @attributes, 'tooltip="' . "Goto: $versions{$entry}{vname}, PVID=$entry" ,'"';
3184
        my $shape;
3185
            $shape = 'box' if ($versions{$entry}{badSingleton});
3186
            $shape = 'octagon'  if ($versions{$entry}{branchPoint});
3187
            $shape = 'invhouse' if ($versions{$entry}{newSuffix});
3188
            $shape = 'doublecircle' if ($versions{$entry}{Tip});
3189
 
3190
 
3191
        push @attributes, 'shape=' . $shape if ( $shape );
3192
 
3193
        my $color;
3194
        my $fill;
3195
           $color = 'color=green style=bold' if ( $versions{$entry}{isaRipple} );
3196
           $color = 'color=orange style=bold' if ( $versions{$entry}{newSuffix} );
3197
           $color = 'color=red style=bold' if ( $versions{$entry}{DeadWood} || $versions{$entry}{badVcsTag} );
3198
           $color = 'color=blue style=bold' if ( $versions{$entry}{Essential} );
3199
           $color = 'color=darkmagenta style=bold' if ( $versions{$entry}{GluedIn} );
3200
           $color = 'color=magenta style=bold' if ( $versions{$entry}{MakeTree} );
3201
 
3202
           $fill = 'style=filled fillcolor=powderblue' if ( $versions{$entry}{Essential} );
3203
           $fill = 'style=filled fillcolor=red' if ( $versions{$entry}{Essential} && $versions{$entry}{badVcsTag} );
3204
           $fill = 'style=filled fillcolor="#99FF99"' if ( exists $versions{$entry}{svnVersion} );
3205
 
3206
 
3207
        push @attributes, $color if ( $color );
3208
        push @attributes, $fill if ( $fill );
3209
 
3210
        return '[' . join( ' ', @attributes) . ']';
3211
    }
3212
 
3213
    sub genArrowAttributes
3214
    {
3215
        my ($not_first, $entry) = @_;
3216
        my @attributes;
3217
 
3218
        push @attributes, 'arrowhead=empty' if ( $not_first );
3219
        push ( @attributes, 'label="' . $versions{$entry}{svnBranchTip} .'"' ) if ( exists $versions{$entry}{svnBranchTip} );
3220
 
3221
        return ('[' . join( ' ', @attributes) . ']') if ( @attributes ) ;
3222
        return '';
3223
    }
3224
 
3225
    #
3226
    #   Flat
3227
    #
3228
    if ( $opt_flat )
3229
    {
3230
        my $last = 0;
3231
        foreach my $entry (@flatOrder )
3232
        {
3233
            if ( $last )
3234
            {
3235
                my $me = dotTag($last);
3236
 
3237
                print FH pentry($me)  ,' -> ', pentry(dotTag($entry)), genArrowAttributes(0, $entry) ,";\n";
3238
                print FH pentry($me)  ,genAttributes($last) . ";\n";
3239
            }
3240
            $last = $entry;
3241
        }
3242
        print FH pentry(dotTag($last))  ,genAttributes($last) . ";\n";
3243
 
3244
    }
3245
    else
3246
    {
3247
        foreach my $entry ( sort {$a <=> $b} keys(%versions) )
3248
        {
3249
            my $me = dotTag($entry);
3250
            my @versions = @{ $versions{$entry}{next}};
3251
            my $ii = 0;
3252
            foreach ( @versions )
3253
            {
3254
                print FH pentry($me)  ," -> ",pentry(dotTag($_)), genArrowAttributes($ii++, $_), ";\n";
3255
            }
3256
 
3257
            print FH pentry($me)  ,genAttributes($entry) . ";\n";
3258
        }
3259
    }
3260
 
3261
    print FH "\n};\n";
3262
    close FH;
3263
 
3264
    #
3265
    #   Convert DOT to a SVG
3266
    #
3267
    unless ( $UNIX )
3268
    {
3269
    print "Generating graphical images\n";
3270
#    system( "dot $filebase.dot -Tjpg -o$filebase.jpg" );  # -v
3271
    system( "dot $filebase.dot -Tsvg -o$filebase.svg" );  # -v
3272
#    unlink("$filebase.dot");
3273
 
3274
    #
3275
    #   Display a list of terminal packages
3276
    #   These are packages that are not used by any other package
3277
    #
3278
    print "\n";
3279
#    print "Generated: $filebase.dot\n";
3280
#    print "Generated: $filebase.jpg\n";
3281
    print "Generated: $filebase.svg\n";
3282
    }
3283
    else
3284
    {
3285
        print "Generated: $filebase.dot\n";
3286
    }
3287
}
3288
 
3289
sub dotTag
3290
{
3291
    my ($entry) = @_;
3292
 
3293
    my $label = '';
3294
    $label .= $versions{$entry}{name} if $multiPackages;
3295
    $label .= $versions{$entry}{vname};
3296
    $label =~ s~[-() ]~_~g;
3297
    return $label;
3298
}
3299
 
3300
sub dotUrl
3301
{
3302
    my ($entry) = @_;
3303
 
3304
    my $pv_base = $GBE_RM_URL . "/fixed_issues.asp?pv_id=$entry";
3305
}
3306
 
3307
#-------------------------------------------------------------------------------
3308
# Function        : pentry
3309
#
3310
# Description     : Generate an entry list as text
3311
#                   Replace "." with "_" since DOT doesn't like .'s
3312
#                   Seperate the arguments
3313
#
3314
# Inputs          : @_          - An array of entries to process
3315
#
3316
# Returns         : A string
3317
#
3318
sub pentry
3319
{
3320
    my ($data) = @_;
3321
    $data =~ s~\.~_~g;
3322
    $result = '"' . $data . '"' ;
3323
    return $result;
3324
}
3325
 
3326
#-------------------------------------------------------------------------------
3327
# Function        : getVobMapping
3328
#
3329
# Description     : Read in Package to Repository Mapping
3330
#
3331
# Inputs          : 
3332
#
3333
# Returns         : Populates %VobMapping
3334
#                             Mapping of PackageName to RepoName[/Subdir]
3335
#
3336
our %ScmRepoMap;
3337
sub getVobMapping
3338
{
3339
    Message ("Read in Vob Mapping");
3340
 
3341
    my $fname = 'cc2svn.repo.dat';
3342
    Error "Cannot locate $fname" unless ( -f $fname );
3343
    require $fname;
3344
 
3345
    Error "Data in $fname is not valid\n"
3346
        unless ( keys(%ScmRepoMap) >= 0 );
3347
 
3348
    $opt_vobMap = $ScmRepoMap{$packageNames}{repo}
3349
        if (exists $ScmRepoMap{$packageNames});
3350
 
3351
    #
3352
    #   Free the memory
3353
    #
3354
    %ScmRepoMap = ();
3355
 
3356
    #
3357
    #   Calculate Target Repo
3358
    #
3359
    Warning ("No VOB Mapping found")
3360
        unless ($opt_vobMap);
3361
    Error("No repository specified. ie -repo=DevTools or -repo=COTS")
3362
        unless ( $opt_repo || $opt_vobMap );
3363
 
3364
    my $r1 = ($opt_repo || '') . '/' . ($opt_vobMap || '');
3365
    $r1 =~ s~^/~~;
3366
    $r1 =~ s~/$~~;
3367
    $svnRepo = $opt_repo_base . $r1;
3368
 
3369
    Verbose( "Repo URL: $svnRepo");
3370
}
3371
 
3372
 
3373
#-------------------------------------------------------------------------------
3374
# Function        : getEssenialPackageVersions
3375
#
3376
# Description     : Determine the 'Essental' Package Versions
3377
#                   Read the data in from an external file
3378
#
3379
# Inputs          : 
3380
#
3381
# Returns         : Populates @EssentialPackages
3382
#
3383
 
3384
our %ScmReleases;
3385
our %ScmPackages;
3386
our %ScmSuffixes;
3387
sub getEssenialPackageVersions
3388
{
3389
    Message ("Read in Essential Package Versions");
3390
 
3391
    my $fname = 'cc2svn.raw.txt';
3392
    Error "Cannot locate $fname" unless ( -f $fname );
3393
    require $fname;
3394
 
3395
    Error "Data in $fname is not valid\n"
3396
        unless ( keys(%ScmReleases) >= 0 );
3397
 
3398
#    DebugDumpData("ScmReleases", \%ScmReleases );
3399
#    DebugDumpData("ScmPackages", \%ScmPackages );
3400
#    DebugDumpData("ScmSuffixes", \%ScmSuffixes );
3401
 
3402
    #
3403
    #   Create a list of essential packages
3404
    #   Retain packages-versions used in this program
3405
    #
3406
    foreach ( keys %ScmPackages )
3407
    {
3408
        next unless ( exists  $pkg_ids{ $ScmPackages{$_}{pkgid} } );
3409
        push @EssentialPackages, $_;
3410
        Error ("Essential Package Version not in extracted Release Manager Data: $_")
3411
            unless ( exists $versions{$_} );
3412
        $versions{$_}{Essential} = 1;
1341 dpurdie 3413
 
3414
        # Retain which RM Release this package-version is the tip
3415
        # Release of
1342 dpurdie 3416
        foreach my $rtag_id ( @{$ScmPackages{$_}{'release'}} )
1341 dpurdie 3417
        {
1342 dpurdie 3418
            $versions{$_}{Releases}{$rtag_id}{rname}   = $ScmReleases{$rtag_id}{name};
3419
            $versions{$_}{Releases}{$rtag_id}{pname}   = $ScmReleases{$rtag_id}{pName};
3420
            $versions{$_}{Releases}{$rtag_id}{proj_id} = $ScmReleases{$rtag_id}{proj_id};
1341 dpurdie 3421
        }
3422
 
392 dpurdie 3423
        #print "ESSENTIAL: $versions{$_}{name} $versions{$_}{vname}\n";
3424
    }
3425
 
1341 dpurdie 3426
 
392 dpurdie 3427
    #
3428
    #   Free memory
3429
    #
3430
    %ScmReleases = ();
3431
    %ScmPackages = ();
3432
    %ScmSuffixes = ();
3433
 
3434
#    DebugDumpData("Essential", \@EssentialPackages );
3435
    Message ("Essential Versions: " . scalar @EssentialPackages );
3436
}
3437
 
3438
#-------------------------------------------------------------------------------
3439
# Function        : ReportPathVariance
3440
#
3441
# Description     : Report variance in paths used by the versions
3442
#
3443
# Inputs          : 
3444
#
3445
# Returns         : 
3446
#
3447
my %VobPaths;
3448
sub ReportPathVariance
3449
{
3450
    Message ("Detect Multiple Paths");
3451
    foreach my $entry ( keys(%versions) )
3452
    {
3453
        my $e = $versions{$entry};
3454
        next if ( isSet ($e, 'DeadWood' ) );
3455
        next if ( isSet ($e, 'badVcsTag') );
3456
        next if ( isSet ($e, 'isSvn') );
3457
        my $tag = $e->{vcsTag};
3458
        next unless ( $tag );
3459
 
3460
        $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
3461
        my $vcsType = $1;
3462
        my $cc_label = $4;
3463
        my $cc_path = $2;
3464
        $cc_path = '/' . $cc_path;
3465
        $cc_path =~ tr~\\/~/~s;
3466
 
3467
        $VobPaths{$cc_path}++;
3468
    }
3469
 
3470
    @multiplePaths = sort keys %VobPaths;
3471
    if ( scalar @multiplePaths > 1 )
3472
    {
3473
        Warning ("Multiple Paths:" . $_ ) foreach (@multiplePaths);
3474
    }
3475
}
3476
 
3477
sub isSet
3478
{
3479
    my ($base, $element) = @_;
3480
    return 0 unless ( exists $base->{$element} );
3481
    return $base->{$element};
3482
}
3483
 
3484
 
3485
#-------------------------------------------------------------------------------
3486
# Function        : recurseList
3487
#
3488
# Description     : Return a list of all element below a given head element
3489
#
3490
# Inputs          : $head               - Head element
3491
#
3492
# Returns         : A list, not in any particular order
3493
#
3494
 
3495
our @recurseList;
3496
sub recurseList
3497
{
3498
    @recurseList = ();
3499
    recurseListBody (@_);
3500
    return @recurseList;
3501
}
3502
sub recurseListBody
3503
{
3504
    foreach my $entry ( @_ )
3505
    {
3506
        push @recurseList, $entry;
3507
no warnings "recursion";
3508
        recurseListBody (@{$versions{$entry}{next}});
3509
    }
3510
}
3511
 
3512
#-------------------------------------------------------------------------------
3513
# Function        : getSvnData
3514
#
3515
# Description     : Read the SVN tree and see what we have
3516
#
3517
# Inputs          : 
3518
#
3519
# Returns         : 
3520
#
3521
my @svnDataItems;
3522
sub getSvnData
3523
{
3524
    Message ("Examine Subversion Tree");
3525
 
3526
    #
3527
    #   Re-init data
3528
    #
3529
    @svnDataItems = ();
3530
    %svnData = ();
3531
 
3532
    #
3533
    #   Create an SVN session
3534
    #
3535
    return unless ( $svnRepo );
3536
    my $svn = NewSessionByUrl ( "$svnRepo/$packageNames" );
3537
    return unless ( $svn );
3538
 
3539
    #
3540
    #   extract data
3541
    #
3542
#    DebugDumpData("SVN", $svn );
3543
    $svn->SvnCmd ( 'log', '-v', '--xml', '--stop-on-copy', $svn->Full()
3544
                    , { 'credentials' => 1,
3545
                        'process' => \&ProcessSvnLog,
3546
                         }
3547
                        );
3548
 
3549
    #
3550
    #   Process data
3551
    foreach my $entry ( @svnDataItems )
3552
    {
3553
        my $name;
3554
        my $isaBranch;
3555
        my $target = $entry->{target};
3556
        if ( $target =~ m~/tags/(.*)~ ) {
3557
            $name = $1;
3558
            $svnData{tags}{$name} = 1;
3559
        } elsif ( $target =~ m~/branches/(.*)~ )  {
3560
            $name = $1;
3561
    #        $branches{$1} = 1;
3562
        } else {
3563
            $svnData{nonTag}{$target} = 1;
3564
        }
3565
 
3566
        my $fromBranch;
3567
        if ( $entry->{fromPath} =~ m~/trunk$~  ) {
3568
            $fromBranch = 'trunk';
3569
        } elsif ( $entry->{fromPath} =~ m~/branches/(.*)~ ) {
3570
            $fromBranch = $1;
3571
        }
3572
 
1341 dpurdie 3573
        # largest Rev number on branch
3574
        if ( exists $svnData{max}{$fromBranch} )
392 dpurdie 3575
        {
1341 dpurdie 3576
            if ( $svnData{max}{$fromBranch}{rev} <  $entry->{fromRev} )
392 dpurdie 3577
            {
1341 dpurdie 3578
                $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
3579
                $svnData{max}{$fromBranch}{name} = $name;
392 dpurdie 3580
            }
3581
        }
1341 dpurdie 3582
        else
3583
        {
3584
            $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
3585
            $svnData{max}{$fromBranch}{name} = $name;
3586
        }
392 dpurdie 3587
    }
1341 dpurdie 3588
 
3589
    foreach my $branch ( keys %{$svnData{max}} )
3590
    {
3591
        $svnData{tips}{$svnData{max}{$branch}{name}} = $branch;
3592
    }
3593
#    DebugDumpData("svnDataItems", \@svnDataItems);
392 dpurdie 3594
#    DebugDumpData("SvnData", \%svnData);
3595
 
1341 dpurdie 3596
 
392 dpurdie 3597
    foreach my $entry ( keys(%versions) )
3598
    {
3599
        my $import_label = saneLabel($entry);
3600
        delete $versions{$entry}{svnVersion};
3601
        delete $versions{$entry}{svnBranchTip};
3602
 
3603
        if ( exists $svnData{tags}{$import_label} )
3604
        {
3605
            $versions{$entry}{svnVersion} = 1;
3606
        }
3607
 
3608
        if ( exists $svnData{tips}{$import_label} )
3609
        {
3610
            $versions{$entry}{svnBranchTip} = $svnData{tips}{$import_label};
3611
        }
3612
    }
3613
 
1341 dpurdie 3614
    Message ( 'Trunk used: ' . (exists $svnData{'max'}{trunk} ? 'Yes' : 'No') );
392 dpurdie 3615
    Message ( 'Labels    : ' . scalar keys %{$svnData{tags}} );
1341 dpurdie 3616
    Message ( 'Branches  : ' . scalar keys %{$svnData{'max'}} );
392 dpurdie 3617
}
3618
 
3619
#-------------------------------------------------------------------------------
3620
# Function        : ProcessSvnLog
3621
#
3622
# Description     :
3623
#                   Parse
3624
#                       <logentry
3625
#                          revision="24272">
3626
#                       <author>bivey</author>
3627
#                       <date>2005-07-25T15:45:35.000000Z</date>
3628
#                       <paths>
3629
#                       <path
3630
#                          prop-mods="false"
3631
#                          text-mods="false"
3632
#                          kind="dir"
3633
#                          copyfrom-path="/enqdef/branches/Stockholm"
3634
#                          copyfrom-rev="24271"
3635
#                          action="A">/enqdef/tags/enqdef_24.0.1.sls</path>
3636
#                       </paths>
3637
#                       <msg>COTS/enqdef: Tagged by Jats Svn Import</msg>
3638
#                       </logentry>
3639
#
3640
# Inputs          : 
3641
#
3642
# Returns         : 
3643
#
3644
my $entryData;
3645
sub  ProcessSvnLog
3646
{
3647
    my ($self, $line ) = @_;
3648
#print "----- $line\n";
3649
    if ( $line =~ m~^<logentry~ ) {
3650
        $entryData = ();
3651
 
3652
    } elsif ( $line =~ m~^\s+revision="(\d+)"~ ) {
3653
        $entryData->{Rev} = $1;
3654
 
3655
    } elsif ( $line =~ m~^\s+copyfrom-path="(.*)"~ ) {
3656
        $entryData->{fromPath} = $1;
3657
 
3658
    } elsif ( $line =~ m~^\s+copyfrom-rev="(\d+)"~ ) {
3659
        $entryData->{fromRev} = $1;
3660
 
3661
    } elsif ( $line =~ m~\s+action=.*?>(.*)</path~ ) {
3662
        $entryData->{target} = $1;
3663
 
3664
    } elsif ( $line =~ m~</logentry~ ) {
3665
        if ( exists $entryData->{fromPath} )
3666
        {
3667
#            DebugDumpData("Data", $entryData);
3668
            push @svnDataItems, $entryData;
3669
        }
3670
    }
3671
 
3672
    #
3673
    #   Return 0 to keep on going
3674
    return 0;
3675
}
3676
 
1328 dpurdie 3677
#-------------------------------------------------------------------------------
392 dpurdie 3678
# Function        : saveData
3679
#
3680
# Description     : Save essential data
3681
#
3682
# Inputs          : 
3683
#
3684
# Returns         : 
3685
#
3686
sub saveData
3687
{
3688
    my $file = $cwd . "/${packageNames}.data";
3689
 
3690
    Message ("Create: $file");
3691
    my $fh = ConfigurationFile::New( $file );
3692
 
3693
    $fh->DumpData(
3694
        "\n# ScmVersions.\n#\n",
3695
        "ScmVersions", \%versions );
3696
 
3697
    #
3698
    #   Close out the file
3699
    #
3700
    $fh->Close();
3701
}
3702
 
3703
 
3704
#-------------------------------------------------------------------------------
3705
#   Documentation
3706
#
3707
 
3708
=pod
3709
 
3710
=for htmltoc    SYSUTIL::cc2svn::
3711
 
3712
=head1 NAME
3713
 
3714
cc2svn_gendata - CC2SVN tool to import an entire package into SVN
3715
 
3716
=head1 SYNOPSIS
3717
 
3718
  jats cc2svn_importpackage [options] package_name
3719
 
3720
 Options:
3721
    -help              - brief help message
3722
    -help -help        - Detailed help message
3723
    -man               - Full documentation
3724
    -repository=name   - Specify target repository
3725
    -[no]flat          - Do not create project tree. Def: -noflat
3726
    -prunemode=mode    - Mode: none, ripple, retain, severe, Def=ripple
3727
    -retain=N          - Specify retain count for pruning. Def=2
3728
    -[no]test          - Do not create packages. Def:-notest
3729
    -[no]reuse         - Keep and reuse ClearCase views
3730
    -age=nnDays        - Only keep recent package
3731
    -dump[=n]          - Dump raw data. N=0,1,2
3732
    -images[=n]        - Create SVG of version tree. N=0,1,2
3733
    -name=aaa          - Alternate output package name. Test Only
3734
    -[no]log           - Write output to log file. Def: -nolog
3735
    -[no]postimage     - Create image after transger: Def: -post
3736
    -workdir=path      - Use for temp storage (def:/work)
1270 dpurdie 3737
    -delete            - Delete SVN package before test
392 dpurdie 3738
 
3739
=head1 OPTIONS
3740
 
3741
=over 8
3742
 
3743
=item B<-help>
3744
 
3745
Print a brief help message and exits.
3746
 
3747
=item B<-help -help>
3748
 
3749
Print a detailed help message with an explanation for each option.
3750
 
3751
=item B<-man>
3752
 
3753
Prints the manual page and exits.
3754
 
3755
=item B<-prunemode=mode>
3756
 
3757
This option control the manner in which excess versions will be pruned. Valid
3758
modes are:
3759
 
3760
=over 8
3761
 
3762
=item   none
3763
 
3764
No pruning will be performed
3765
 
3766
=item   ripple
3767
 
3768
Non-Essential packages that are ripple builds will be removed.
3769
 
3770
=item   retain
3771
 
3772
Versions that preceed an Essential version will be retained.
3773
 
3774
=item   severe
3775
 
3776
Only Essential Versions, and Branching points will be retained.
3777
 
3778
=back
3779
 
3780
=back
3781
 
3782
=head1 DESCRIPTION
3783
 
3784
This program is a tool used in the conversion of ClearCase VOBS to subversion.
3785
It will take a complete package and all relevent versions from ClearCase and
3786
insert them into subversion in a sessible manner. It will attempt to retain
3787
file change order and history.
3788
 
3789
It will:
3790
 
3791
=over 8
3792
 
3793
=item *
3794
 
3795
Read in the Essential Package Version list.
3796
 
3797
=item *
3798
 
3799
Extract, from Release Manager, all known versions of the specified package.
3800
 
3801
=item *
3802
 
3803
It will attempt to determine the type of package: COTS, TOOL, CORE, PROJECT
3804
and alter the processing accordingly.
3805
 
3806
=item *
3807
 
3808
It will create a version dependency tree and determine 'new' project branch
3809
points. It will remove (prune) versions that are excess to requirements.
3810
 
3811
=item *
3812
 
3813
It will extract source from ClearCase and insert it into SVN, creating
3814
branches and tags as it goes.
3815
 
3816
=back
3817
 
3818
The program can also be used to create a SVG image of the version dependency
3819
tree. This does not work on Linux; only Windows with 'dot' installed.
3820
 
3821
=cut
3822