Subversion Repositories DevTools

Rev

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