Subversion Repositories DevTools

Rev

Rev 1272 | Rev 2429 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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