Subversion Repositories DevTools

Rev

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

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