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