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