Subversion Repositories DevTools

Rev

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

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