Subversion Repositories DevTools

Rev

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

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