Subversion Repositories DevTools

Rev

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