Subversion Repositories DevTools

Rev

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