Subversion Repositories DevTools

Rev

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

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