Subversion Repositories DevTools

Rev

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