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