Subversion Repositories DevTools

Rev

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

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