Subversion Repositories DevTools

Rev

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

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