Subversion Repositories DevTools

Rev

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