Subversion Repositories DevTools

Rev

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

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