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