Subversion Repositories DevTools

Rev

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