Subversion Repositories DevTools

Rev

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