Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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