Subversion Repositories DevTools

Rev

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

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