Subversion Repositories DevTools

Rev

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