Subversion Repositories DevTools

Rev

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

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