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