Subversion Repositories DevTools

Rev

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

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