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