Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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