| 267 |
dpurdie |
1 |
########################################################################
|
|
|
2 |
# Copyright (C) 1998-2008 ERG Limited, All rights reserved
|
|
|
3 |
#
|
|
|
4 |
# Module name : jats_svn.pl
|
|
|
5 |
# Module type : Jats Utility
|
|
|
6 |
# Compiler(s) : Perl
|
|
|
7 |
# Environment(s): Jats
|
|
|
8 |
#
|
|
|
9 |
# Description : A script to perform a number of SVN utility functions
|
|
|
10 |
# The script will:
|
|
|
11 |
# Delete a package
|
|
|
12 |
# Create a package
|
|
|
13 |
# Import source to a package
|
|
|
14 |
#
|
|
|
15 |
#
|
|
|
16 |
#......................................................................#
|
|
|
17 |
|
|
|
18 |
require 5.006_001;
|
|
|
19 |
use strict;
|
|
|
20 |
use warnings;
|
|
|
21 |
use JatsError;
|
|
|
22 |
use JatsSvn qw(:All);
|
|
|
23 |
use JatsLocateFiles;
|
|
|
24 |
|
|
|
25 |
use Pod::Usage; # required for help support
|
|
|
26 |
use Getopt::Long qw(:config require_order); # Stop on non-option
|
|
|
27 |
use Cwd;
|
|
|
28 |
use File::Path;
|
|
|
29 |
use File::Copy;
|
|
|
30 |
use File::Basename;
|
|
|
31 |
use File::Compare;
|
|
|
32 |
|
|
|
33 |
my $VERSION = "1.0.0"; # Update this
|
|
|
34 |
|
|
|
35 |
#
|
|
|
36 |
# Options
|
|
|
37 |
#
|
|
|
38 |
my $opt_debug = $ENV{'GBE_DEBUG'}; # Allow global debug
|
|
|
39 |
my $opt_verbose = $ENV{'GBE_VERBOSE'}; # Allow global verbose
|
|
|
40 |
my $opt_help = 0;
|
|
|
41 |
|
|
|
42 |
#
|
|
|
43 |
# Globals
|
|
|
44 |
#
|
|
|
45 |
my $opr_done; # User has done something
|
|
|
46 |
|
|
|
47 |
#-------------------------------------------------------------------------------
|
|
|
48 |
# Function : Mainline Entry Point
|
|
|
49 |
#
|
|
|
50 |
# Description :
|
|
|
51 |
#
|
|
|
52 |
# Inputs :
|
|
|
53 |
#
|
|
|
54 |
my $result = GetOptions (
|
|
|
55 |
"help:+" => \$opt_help, # flag, multiple use allowed
|
|
|
56 |
"manual:3" => \$opt_help, # flag
|
|
|
57 |
"verbose:+" => \$opt_verbose, # flag, multiple use allowed
|
|
|
58 |
|
|
|
59 |
);
|
|
|
60 |
|
|
|
61 |
#
|
|
|
62 |
# UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
|
|
|
63 |
#
|
|
|
64 |
|
|
|
65 |
#
|
|
|
66 |
# Process help and manual options
|
|
|
67 |
#
|
|
|
68 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
69 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
70 |
pod2usage(-verbose => 2) if ($opt_help > 2);
|
|
|
71 |
|
|
|
72 |
#
|
|
|
73 |
# Configure the error reporting process now that we have the user options
|
|
|
74 |
#
|
|
|
75 |
ErrorConfig( 'name' =>'SVN',
|
|
|
76 |
'verbose' => $opt_verbose,
|
|
|
77 |
);
|
|
|
78 |
|
|
|
79 |
#
|
|
|
80 |
# Reconfigure the optiosn parser to allow subcommands to parse options
|
|
|
81 |
#
|
|
|
82 |
Getopt::Long::Configure('permute');
|
|
|
83 |
|
|
|
84 |
#
|
|
|
85 |
# Process command
|
|
|
86 |
# First command line argument is a subversion command
|
|
|
87 |
#
|
|
|
88 |
my $cmd = shift @ARGV || "help";
|
|
|
89 |
CreatePackage() if ( $cmd =~ m/^create/ );
|
|
|
90 |
DeletePackage() if ( $cmd =~ m/^delete-package/ );
|
|
|
91 |
ImportPackage() if ( $cmd =~ m/^import/ );
|
|
|
92 |
SvnRepoCmd($cmd, @ARGV) if ( $cmd eq 'ls' );
|
|
|
93 |
|
|
|
94 |
pod2usage(-verbose => 0, -message => "No valid operations specified") unless ( $opr_done );
|
|
|
95 |
exit 0;
|
|
|
96 |
|
|
|
97 |
#-------------------------------------------------------------------------------
|
|
|
98 |
# Function : SvnRepoCmd
|
|
|
99 |
#
|
|
|
100 |
# Description : Execute a SVN command, where the first argument
|
|
|
101 |
# is a repository specifier
|
|
|
102 |
#
|
|
|
103 |
# Inputs : $cmd
|
|
|
104 |
# $repo_url
|
|
|
105 |
# @opts
|
|
|
106 |
#
|
|
|
107 |
# Returns :
|
|
|
108 |
#
|
|
|
109 |
sub SvnRepoCmd
|
|
|
110 |
{
|
|
|
111 |
my ( $cmd, $repo_url, @opts ) = @_;
|
|
|
112 |
my $uref = NewSessionByUrl ( $repo_url );
|
|
|
113 |
|
|
|
114 |
SvnUserCmd( $cmd,
|
|
|
115 |
$uref->Full,
|
|
|
116 |
@opts,
|
|
|
117 |
{ 'credentials' => 1 });
|
|
|
118 |
|
|
|
119 |
$opr_done = 1;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
#-------------------------------------------------------------------------------
|
|
|
123 |
# Function : DeletePackage
|
|
|
124 |
#
|
|
|
125 |
# Description : Delete a Package structure within a Repository
|
|
|
126 |
# Intended for test usage
|
|
|
127 |
#
|
|
|
128 |
# Inputs : URL - Url to Repo + Package Base
|
|
|
129 |
#
|
|
|
130 |
# Returns :
|
|
|
131 |
#
|
|
|
132 |
sub DeletePackage
|
|
|
133 |
{
|
|
|
134 |
#
|
|
|
135 |
# Parse more options
|
|
|
136 |
#
|
|
|
137 |
GetOptions (
|
|
|
138 |
"help:+" => \$opt_help,
|
|
|
139 |
"manual:3" => \$opt_help,
|
|
|
140 |
) || Error ("Invalid command line" );
|
|
|
141 |
|
|
|
142 |
#
|
|
|
143 |
# Subcommand specific help
|
|
|
144 |
#
|
|
|
145 |
SubCommandHelp( $opt_help, "Delete a Package") if ($opt_help || $#ARGV < 0);
|
|
|
146 |
|
|
|
147 |
#
|
|
|
148 |
# Sanity Tests
|
|
|
149 |
#
|
|
|
150 |
Message ("Delete Entire Package Tree" );
|
|
|
151 |
Warning ("Too many arguments: @ARGV") if ( $#ARGV >= 1 );
|
|
|
152 |
|
|
|
153 |
#
|
|
|
154 |
# Do all the hard work
|
|
|
155 |
# Create
|
|
|
156 |
# Import
|
|
|
157 |
# Label
|
|
|
158 |
#
|
|
|
159 |
my $uref = NewSessionByUrl ( $ARGV[0] );
|
|
|
160 |
$uref->SvnValidatePackageRoot();
|
|
|
161 |
$uref->SvnDelete (
|
|
|
162 |
'target' => $uref->Full,
|
|
|
163 |
'comment' => ['Deleted by user command','jats svn delete-package'],
|
|
|
164 |
'noerror' => 0,
|
|
|
165 |
);
|
|
|
166 |
$opr_done = 1;
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
#-------------------------------------------------------------------------------
|
|
|
170 |
# Function : CreatePackage
|
|
|
171 |
#
|
|
|
172 |
# Description : Create a Package structure within a Repository
|
|
|
173 |
# Optionally Import Data
|
|
|
174 |
# Optionally Tag the import
|
| 297 |
dpurdie |
175 |
# Optionally Tag the import on a branch
|
| 267 |
dpurdie |
176 |
#
|
|
|
177 |
# Inputs : URL - Url to Repo + Package Base
|
|
|
178 |
# Options - Command modifiers
|
|
|
179 |
# -import=path - Import named directory
|
|
|
180 |
# -label=name - Label the result
|
| 297 |
dpurdie |
181 |
# -tag=name - Import to Tag Only
|
|
|
182 |
# -branch=name - Import to Branch only
|
| 267 |
dpurdie |
183 |
# -new - Must be new package
|
| 297 |
dpurdie |
184 |
# -replace - Replace existing
|
| 267 |
dpurdie |
185 |
#
|
|
|
186 |
# Returns :
|
|
|
187 |
#
|
|
|
188 |
sub CreatePackage
|
|
|
189 |
{
|
|
|
190 |
my $opt_import;
|
|
|
191 |
my $opt_tag;
|
|
|
192 |
my $opt_branch;
|
|
|
193 |
my $opt_trunk;
|
|
|
194 |
my $opt_new;
|
|
|
195 |
my $opt_label;
|
|
|
196 |
my $opt_replace;
|
|
|
197 |
my $pname;
|
|
|
198 |
my $type;
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
Message ("Create New Package Version" );
|
|
|
202 |
|
|
|
203 |
#
|
|
|
204 |
# Parse more options
|
|
|
205 |
#
|
|
|
206 |
GetOptions (
|
|
|
207 |
"help:+" => \$opt_help,
|
|
|
208 |
"manual:3" => \$opt_help,
|
|
|
209 |
"verbose:+" => \$opt_verbose,
|
|
|
210 |
"import=s" => \$opt_import,
|
|
|
211 |
"new" => \$opt_new,
|
|
|
212 |
"branch=s" => \$opt_branch,
|
|
|
213 |
"trunk" => \$opt_trunk,
|
|
|
214 |
"tag=s" => \$opt_tag,
|
|
|
215 |
"label=s" => \$opt_label,
|
|
|
216 |
"replace" => \$opt_replace,
|
|
|
217 |
|
|
|
218 |
) || Error ("Invalid command line" );
|
|
|
219 |
|
|
|
220 |
#
|
|
|
221 |
# Subcommand specific help
|
|
|
222 |
#
|
|
|
223 |
SubCommandHelp( $opt_help, "Create a Package Version") if ($opt_help || $#ARGV < 0);
|
|
|
224 |
|
|
|
225 |
#
|
|
|
226 |
# Alter the error reporting paramters
|
|
|
227 |
#
|
|
|
228 |
ErrorConfig( 'verbose' => $opt_verbose );
|
|
|
229 |
|
|
|
230 |
#
|
|
|
231 |
# Sanity Tests
|
|
|
232 |
#
|
|
|
233 |
my $count = 0;
|
|
|
234 |
$count++ if ( $opt_trunk );
|
|
|
235 |
$count++ if ( $opt_branch );
|
|
|
236 |
$count++ if ( $opt_tag );
|
|
|
237 |
Error ("Conflicting options: -trunk, -tag, -branch") if ( $count > 1 );
|
|
|
238 |
Error ("Nothing imported to be labeled") if ( $count && !$opt_import );
|
|
|
239 |
Error ("Import path does not exist: $opt_import") if ( $opt_import && ! -d $opt_import );
|
|
|
240 |
Error ("Conflicting options: new and replace") if ( $opt_new && $opt_replace );
|
|
|
241 |
|
|
|
242 |
($type, $opt_label) = ('tags', $opt_tag) if ( $opt_tag);
|
|
|
243 |
($type, $opt_label) = ('branches', $opt_branch) if ( $opt_branch );
|
|
|
244 |
($type, $opt_label) = ('trunk', $opt_label) if ( $opt_trunk);
|
|
|
245 |
|
|
|
246 |
#
|
|
|
247 |
# Do all the hard work
|
|
|
248 |
# Create
|
|
|
249 |
# Import
|
|
|
250 |
# Label
|
|
|
251 |
#
|
|
|
252 |
my $uref = NewSessionByUrl ( $ARGV[0] );
|
|
|
253 |
$uref->SvnCreatePackage (
|
|
|
254 |
'import' => $opt_import,
|
|
|
255 |
'label' => $opt_label,
|
|
|
256 |
'type' => $type,
|
|
|
257 |
'new' => $opt_new,
|
|
|
258 |
'replace' => $opt_replace,
|
|
|
259 |
);
|
|
|
260 |
Message ("Repository Ref: " . $uref->RmRef);
|
|
|
261 |
$opr_done = 1;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
#-------------------------------------------------------------------------------
|
|
|
265 |
# Function : ImportPackage
|
|
|
266 |
#
|
|
|
267 |
# Description : Import a new version of a package
|
|
|
268 |
# Take great care to reuse file-versions that are already in
|
|
|
269 |
# the package
|
|
|
270 |
#
|
|
|
271 |
# Intended to allow the imprtation of multiple
|
|
|
272 |
# versions of a package
|
|
|
273 |
#
|
|
|
274 |
# Inputs :
|
|
|
275 |
#
|
|
|
276 |
# Returns :
|
|
|
277 |
#
|
|
|
278 |
sub ImportPackage
|
|
|
279 |
{
|
|
|
280 |
Message ("Import Package Version" );
|
|
|
281 |
|
|
|
282 |
#
|
|
|
283 |
# Options
|
|
|
284 |
#
|
|
|
285 |
my $opt_package;
|
|
|
286 |
my $opt_dir;
|
|
|
287 |
my $opt_label;
|
|
|
288 |
my $opt_replace = 0;
|
|
|
289 |
my $opt_reuse;
|
| 297 |
dpurdie |
290 |
my $opt_workdir = "SvnImportDir";
|
| 299 |
dpurdie |
291 |
my $opt_delete = 1;
|
| 267 |
dpurdie |
292 |
|
|
|
293 |
#
|
|
|
294 |
# Other globals
|
|
|
295 |
#
|
|
|
296 |
my $url_label;
|
|
|
297 |
|
|
|
298 |
#
|
|
|
299 |
# Configuration options
|
|
|
300 |
#
|
|
|
301 |
my $result = GetOptions (
|
|
|
302 |
"help:+" => \$opt_help,
|
|
|
303 |
"manual:3" => \$opt_help,
|
|
|
304 |
"verbose:+" => \$opt_verbose,
|
|
|
305 |
"package=s" => \$opt_package,
|
|
|
306 |
"dir=s" => \$opt_dir,
|
|
|
307 |
"label=s" => \$opt_label,
|
|
|
308 |
"replace" => \$opt_replace,
|
|
|
309 |
"reuse" => \$opt_reuse,
|
| 299 |
dpurdie |
310 |
"workspace=s" => \$opt_workdir,
|
|
|
311 |
"delete!" => \$opt_delete,
|
| 267 |
dpurdie |
312 |
|
|
|
313 |
#
|
|
|
314 |
# Update documentation at the end of the file
|
|
|
315 |
#
|
|
|
316 |
) || Error ("Invalid command line" );
|
|
|
317 |
|
|
|
318 |
#
|
|
|
319 |
# Insert defaults
|
|
|
320 |
# User can specify base package via -package or unoptions arguments
|
|
|
321 |
#
|
|
|
322 |
$opt_package = $ARGV[0] unless ( $opt_package );
|
|
|
323 |
|
|
|
324 |
#
|
|
|
325 |
# Subcommand specific help
|
|
|
326 |
#
|
|
|
327 |
SubCommandHelp( $opt_help, "Import directory to a Package")
|
|
|
328 |
if ($opt_help || ! $opt_package );
|
|
|
329 |
|
|
|
330 |
#
|
|
|
331 |
# Alter the error reporting paramters
|
|
|
332 |
#
|
|
|
333 |
ErrorConfig( 'verbose' => $opt_verbose );
|
|
|
334 |
|
|
|
335 |
#
|
|
|
336 |
# Configure the error reporting process now that we have the user options
|
|
|
337 |
#
|
|
|
338 |
Error ("No package URL specified") unless ( $opt_package );
|
|
|
339 |
Error ("No base directory specified") unless ( $opt_dir );
|
|
|
340 |
Error ("Invalid base directory: $opt_dir") unless ( -d $opt_dir );
|
|
|
341 |
|
|
|
342 |
#
|
|
|
343 |
# Create an SVN session
|
|
|
344 |
#
|
|
|
345 |
my $svn = NewSessionByUrl ( $opt_package );
|
|
|
346 |
|
|
|
347 |
#
|
|
|
348 |
# Ensure that the required label is available
|
|
|
349 |
#
|
|
|
350 |
if ( $opt_label )
|
|
|
351 |
{
|
|
|
352 |
$opt_label = SvnIsaSimpleLabel ($opt_label);
|
|
|
353 |
$url_label = $svn->BranchName( $opt_label, 'tags' );
|
|
|
354 |
$svn->SvnValidateTarget (
|
|
|
355 |
'target' => $url_label,
|
|
|
356 |
'available' => 1,
|
|
|
357 |
) unless ( $opt_replace );
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
#
|
|
|
361 |
# Create a workspace based on the users package
|
|
|
362 |
# Allow the workspace to be reused to speed up multiple
|
|
|
363 |
# operations
|
|
|
364 |
#
|
|
|
365 |
unless ( $opt_reuse && -d $opt_workdir )
|
|
|
366 |
{
|
|
|
367 |
Message ("Creating Workspace");
|
|
|
368 |
rmtree( $opt_workdir );
|
|
|
369 |
|
|
|
370 |
$svn->SvnValidatePackageRoot ();
|
|
|
371 |
#DebugDumpData( 'Svn', $svn );
|
|
|
372 |
$svn->SvnValidateTarget (
|
|
|
373 |
'cmd' => 'SvnImporter',
|
|
|
374 |
'target' => $svn->Full,
|
|
|
375 |
'require' => 1,
|
|
|
376 |
);
|
|
|
377 |
|
|
|
378 |
$svn->SvnCo ( $svn->Full . '/trunk', $opt_workdir );
|
|
|
379 |
Error ("Cannot locate the created Workspace")
|
|
|
380 |
unless ( -d $opt_workdir );
|
|
|
381 |
}
|
| 299 |
dpurdie |
382 |
else
|
|
|
383 |
{
|
|
|
384 |
Message ("Reusing Workspace");
|
|
|
385 |
}
|
| 267 |
dpurdie |
386 |
|
|
|
387 |
#
|
|
|
388 |
# Determine differences between the two folders
|
|
|
389 |
# Create structures for each directory
|
|
|
390 |
#
|
|
|
391 |
Message ("Determine Files in packages");
|
|
|
392 |
|
|
|
393 |
my $search = JatsLocateFiles->new("--Recurse=1",
|
|
|
394 |
"--DirsToo",
|
|
|
395 |
"--FilterOutRe=/\.svn/",
|
|
|
396 |
"--FilterOutRe=/\.svn\$",
|
| 299 |
dpurdie |
397 |
"--FilterOutRe=^/${opt_workdir}\$",
|
|
|
398 |
"--FilterOutRe=^/${opt_workdir}/",
|
| 267 |
dpurdie |
399 |
);
|
|
|
400 |
my @ws = $search->search($opt_workdir);
|
|
|
401 |
my @dir = $search->search($opt_dir);
|
|
|
402 |
|
|
|
403 |
#Information ("WS Results", @ws);
|
|
|
404 |
#Information ("DIR Results", @dir);
|
|
|
405 |
|
|
|
406 |
#
|
|
|
407 |
# Create a hash the Workspace and the User dir
|
|
|
408 |
# The key will be file names
|
|
|
409 |
#
|
|
|
410 |
my %ws; map ( $ws{$_} = 1 , @ws );
|
|
|
411 |
my %dir; map ( $dir{$_} = 1 , @dir );
|
|
|
412 |
|
|
|
413 |
#
|
|
|
414 |
# Create a hash of common elements
|
|
|
415 |
# Removing then from the other two
|
|
|
416 |
#
|
|
|
417 |
my %common;
|
|
|
418 |
foreach ( keys %ws )
|
|
|
419 |
{
|
|
|
420 |
next unless ( exists $dir{$_} );
|
|
|
421 |
$common{$_} = 1;
|
|
|
422 |
delete $ws{$_};
|
|
|
423 |
delete $dir{$_};
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
#DebugDumpData( 'WS', \%ws );
|
|
|
427 |
#DebugDumpData( 'DIR', \%dir );
|
|
|
428 |
#DebugDumpData( 'COMMON', \%common );
|
|
|
429 |
|
|
|
430 |
#
|
|
|
431 |
# Add New Files
|
|
|
432 |
# Won't add empty directories at this point
|
|
|
433 |
#
|
|
|
434 |
# Process by sorted list
|
|
|
435 |
# This will ensure we process parent directories first
|
|
|
436 |
#
|
|
|
437 |
my @added = sort keys %dir;
|
|
|
438 |
|
|
|
439 |
if ( @added )
|
|
|
440 |
{
|
|
|
441 |
foreach my $file ( @added )
|
|
|
442 |
{
|
|
|
443 |
my $src = "$opt_dir/$file";
|
|
|
444 |
my $target = "$opt_workdir/$file";
|
|
|
445 |
|
|
|
446 |
if ( -d $src )
|
|
|
447 |
{
|
|
|
448 |
mkdir ( $target ) unless (-d $target);
|
|
|
449 |
}
|
|
|
450 |
else
|
|
|
451 |
{
|
|
|
452 |
|
|
|
453 |
my $path = dirname ( $target);
|
|
|
454 |
mkdir ( $path ) unless (-d $path);
|
|
|
455 |
|
|
|
456 |
Verbose ("Adding $file");
|
|
|
457 |
unless (File::Copy::copy( $src, $target ))
|
|
|
458 |
{
|
|
|
459 |
Error("Failed to transfer file [$file]: $!");
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
#
|
|
|
465 |
# Inform Subversion about the added files
|
| 297 |
dpurdie |
466 |
# The command line does have a finite length, so add them 200 at a
|
|
|
467 |
# time.
|
| 267 |
dpurdie |
468 |
#
|
| 297 |
dpurdie |
469 |
|
|
|
470 |
my $base = 0;
|
|
|
471 |
my $num = $#added;
|
|
|
472 |
Message ("Update the workspace: Added $num files");
|
|
|
473 |
|
|
|
474 |
while ( $base <= $num )
|
|
|
475 |
{
|
|
|
476 |
my $end = $base + 200;
|
|
|
477 |
$end = $num if ( $end > $num );
|
|
|
478 |
|
|
|
479 |
$svn->SvnCmd ( 'add'
|
|
|
480 |
, '--depth=empty'
|
|
|
481 |
, '--parents'
|
|
|
482 |
, map ("$opt_workdir/$_", @added[$base .. $end] ),
|
|
|
483 |
{ 'error' => 'Adding files to workspace' } );
|
|
|
484 |
|
|
|
485 |
$base = $end + 1;
|
|
|
486 |
}
|
| 267 |
dpurdie |
487 |
}
|
|
|
488 |
|
|
|
489 |
#
|
|
|
490 |
# Remove files
|
|
|
491 |
# Don't really need to delete the files as the svn delete
|
|
|
492 |
# comamdn will do this too. Just do it anyway
|
|
|
493 |
#
|
|
|
494 |
my @rm_files = sort keys %ws;
|
|
|
495 |
if ( @rm_files )
|
|
|
496 |
{
|
|
|
497 |
foreach my $file ( @rm_files )
|
|
|
498 |
{
|
|
|
499 |
Verbose ("Removing $file");
|
|
|
500 |
unlink "$opt_workdir/$file";
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
#
|
|
|
504 |
# Inform Subversion about the removed files
|
|
|
505 |
#
|
| 297 |
dpurdie |
506 |
my $base = 0;
|
|
|
507 |
my $num = $#rm_files;
|
|
|
508 |
Message ("Update the workspace: Removed $num Files");
|
|
|
509 |
|
|
|
510 |
while ( $base <= $num )
|
|
|
511 |
{
|
|
|
512 |
my $end = $base + 200;
|
|
|
513 |
$end = $num if ( $end > $num );
|
|
|
514 |
|
|
|
515 |
$svn->SvnCmd ( 'delete', map ("$opt_workdir/$_", @rm_files[$base .. $end] ),
|
|
|
516 |
{ 'error' => 'Deleting files from workspace' } );
|
|
|
517 |
|
|
|
518 |
|
|
|
519 |
$base = $end + 1;
|
|
|
520 |
}
|
| 267 |
dpurdie |
521 |
}
|
|
|
522 |
|
|
|
523 |
#
|
|
|
524 |
# The common files may have changed
|
|
|
525 |
# Simply copy them all in and let subversion figure it out
|
|
|
526 |
#
|
|
|
527 |
foreach my $file ( sort keys %common )
|
|
|
528 |
{
|
|
|
529 |
my $src = "$opt_dir/$file";
|
|
|
530 |
my $target = "$opt_workdir/$file";
|
|
|
531 |
|
|
|
532 |
next if ( -d $src );
|
|
|
533 |
if ( File::Compare::compare ($src, $target) )
|
|
|
534 |
{
|
|
|
535 |
Verbose ("Transfer $file");
|
|
|
536 |
unlink $target;
|
|
|
537 |
unless (File::Copy::copy( $src, $target ))
|
|
|
538 |
{
|
|
|
539 |
Error("Failed to transfer file [$file]: $!",
|
|
|
540 |
"Src: $src",
|
|
|
541 |
"Tgt: $target");
|
|
|
542 |
}
|
|
|
543 |
}
|
|
|
544 |
}
|
|
|
545 |
|
|
|
546 |
#
|
|
|
547 |
# Commit the workspace
|
|
|
548 |
# This will go back onto the trunk
|
|
|
549 |
#
|
|
|
550 |
$svn = NewSessionByWS( $opt_workdir );
|
|
|
551 |
$svn->SvnCi ('comment' => "Checkin by Svn Import" );
|
|
|
552 |
Message ("Repository Ref: " . $svn->RmRef);
|
|
|
553 |
|
|
|
554 |
#
|
|
|
555 |
# Label the result
|
|
|
556 |
# The workspace will have been updated, so we can use it as the base for
|
|
|
557 |
# the labeling process
|
|
|
558 |
#
|
|
|
559 |
if ( $opt_label )
|
|
|
560 |
{
|
|
|
561 |
$svn->SvnCopyWs (
|
|
|
562 |
target => $url_label,
|
|
|
563 |
'noswitch' => 1,
|
|
|
564 |
'replace' => $opt_replace,
|
|
|
565 |
'comment' => 'Created by Jats Svn Import',
|
|
|
566 |
);
|
|
|
567 |
Message ("Repository Ref: " . $svn->RmRef);
|
|
|
568 |
}
|
| 299 |
dpurdie |
569 |
|
|
|
570 |
#
|
|
|
571 |
# Clean up
|
|
|
572 |
#
|
|
|
573 |
if ( $opt_delete && ! $opt_reuse )
|
|
|
574 |
{
|
|
|
575 |
Message ("Delete Workspace");
|
|
|
576 |
rmtree( $opt_workdir );
|
|
|
577 |
}
|
|
|
578 |
|
| 267 |
dpurdie |
579 |
$opr_done = 1;
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
#-------------------------------------------------------------------------------
|
|
|
583 |
# Function : SubCommandHelp
|
|
|
584 |
#
|
|
|
585 |
# Description : Provide help on a subcommand
|
|
|
586 |
#
|
|
|
587 |
# Inputs : $help_level - Help Level 1,2,3
|
|
|
588 |
# $topic - Topic Name
|
|
|
589 |
#
|
|
|
590 |
# Returns : This function does not return
|
|
|
591 |
#
|
|
|
592 |
sub SubCommandHelp
|
|
|
593 |
{
|
|
|
594 |
my ($help_level, $topic) = @_;
|
|
|
595 |
|
|
|
596 |
#
|
|
|
597 |
# Spell out the section we want to display
|
|
|
598 |
#
|
|
|
599 |
# Note:
|
|
|
600 |
# Due to bug in pod2usage cant use 'head1' by itself
|
|
|
601 |
# Each one needs a subsection.
|
|
|
602 |
#
|
|
|
603 |
my $help_re;
|
|
|
604 |
my @sections;
|
|
|
605 |
if ( $help_level <= 1 ) {
|
|
|
606 |
@sections = qw( NAME SYNOPSIS );
|
|
|
607 |
} elsif ( $help_level <= 2 ) {
|
|
|
608 |
@sections = qw( NAME SYNOPSIS ARGUMENTS OPTIONS );
|
|
|
609 |
} else {
|
|
|
610 |
@sections = qw( NAME SYNOPSIS ARGUMENTS OPTIONS DESCRIPTION );
|
|
|
611 |
};
|
|
|
612 |
|
|
|
613 |
#
|
|
|
614 |
# Build up a topic list
|
|
|
615 |
#
|
|
|
616 |
$help_re .= $topic . '\/' . $_ . '|' foreach ( @sections );
|
|
|
617 |
|
|
|
618 |
#
|
|
|
619 |
# Extract section from the POD
|
|
|
620 |
# Need trailling DUMMY to overcome BUG in pod2usage
|
|
|
621 |
#
|
|
|
622 |
pod2usage({-verbose => 99,
|
|
|
623 |
-sections => $help_re . 'DUMMY'} );
|
|
|
624 |
}
|
|
|
625 |
|
|
|
626 |
|
|
|
627 |
|
|
|
628 |
#-------------------------------------------------------------------------------
|
|
|
629 |
# Documentation
|
|
|
630 |
# NOTE
|
|
|
631 |
#
|
|
|
632 |
# Each subcommand MUST have
|
|
|
633 |
# head1 section as used by the subcommand
|
|
|
634 |
# This should be empty
|
|
|
635 |
# head2 sections called
|
|
|
636 |
# NAME SYNOPSIS ARGUMENTS OPTIONS DESCRIPTION
|
|
|
637 |
#
|
|
|
638 |
#=head1 xxxxxx
|
|
|
639 |
#=head2 NAME
|
|
|
640 |
#=head2 SYNOPSIS
|
|
|
641 |
#=head2 ARGUMENTS
|
|
|
642 |
#=head2 OPTIONS
|
|
|
643 |
#=head2 DESCRIPTION
|
|
|
644 |
#
|
|
|
645 |
|
|
|
646 |
=pod
|
|
|
647 |
|
|
|
648 |
=head1 NAME
|
|
|
649 |
|
|
|
650 |
jats svn - Miscellaneous SubVersion Operations
|
|
|
651 |
|
|
|
652 |
=head1 SYNOPSIS
|
|
|
653 |
|
|
|
654 |
jats svn [options] command [command options]
|
|
|
655 |
|
|
|
656 |
Options:
|
|
|
657 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
658 |
-man - Full documentation [-help=3]
|
|
|
659 |
-verbose[=n] - Verbose command operation
|
|
|
660 |
|
|
|
661 |
Common Command Options:
|
|
|
662 |
All command support suboptions to provide command specific help
|
|
|
663 |
|
|
|
664 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
665 |
-man - Full documentation [-help=3]
|
|
|
666 |
|
|
|
667 |
Commands are:
|
|
|
668 |
ls URL - List Repo contents for URL
|
|
|
669 |
delete-package URL - Delete Package Subtree
|
|
|
670 |
create URL - Create a new package at URL
|
|
|
671 |
import URL - Import files to package at URL
|
|
|
672 |
|
|
|
673 |
Use the command
|
|
|
674 |
jats svn command -h
|
|
|
675 |
for command specific help
|
|
|
676 |
|
|
|
677 |
|
|
|
678 |
=head1 OPTIONS
|
|
|
679 |
|
|
|
680 |
=over
|
|
|
681 |
|
|
|
682 |
=item B<-help[=n]>
|
|
|
683 |
|
|
|
684 |
Print a help message and exit. The level of help may be either 1, 2 or
|
|
|
685 |
3 for a full manual.
|
|
|
686 |
|
|
|
687 |
This option may be specified multiple times to increment the help level, or
|
|
|
688 |
the help level may be directly specified as a number.
|
|
|
689 |
|
|
|
690 |
=item B<-man>
|
|
|
691 |
|
|
|
692 |
This is the same as '-help=3'.
|
|
|
693 |
The complete help is produced in a man page format.
|
|
|
694 |
|
|
|
695 |
=item B<--verbose[=n]>
|
|
|
696 |
|
|
|
697 |
This option will increase the level of verbosity of the commands.
|
|
|
698 |
|
|
|
699 |
If an argument is provided, then it will be used to set the level, otherwise the
|
|
|
700 |
existing level will be incremented. This option may be specified multiple times.
|
|
|
701 |
|
|
|
702 |
=back
|
|
|
703 |
|
|
|
704 |
=head1 DESCRIPTION
|
|
|
705 |
|
|
|
706 |
This program provides a number of useful Subversion based operations.
|
|
|
707 |
|
|
|
708 |
=head1 List Repository
|
|
|
709 |
|
|
|
710 |
This command will take a URL and perform a 'svn' list operation. The URL will
|
|
|
711 |
be expanded to include the site specific repository.
|
|
|
712 |
|
|
|
713 |
=head1 Delete a Package
|
|
|
714 |
|
|
|
715 |
=head2 NAME
|
|
|
716 |
|
|
|
717 |
Delete a Package
|
|
|
718 |
|
|
|
719 |
=head2 SYNOPSIS
|
|
|
720 |
|
|
|
721 |
jats svn delete-package URL [options]
|
|
|
722 |
|
|
|
723 |
Options:
|
|
|
724 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
725 |
-man - Full documentation [-help=3]
|
|
|
726 |
-verbose[=n] - Verbose command operation
|
|
|
727 |
|
|
|
728 |
=head2 ARGUMENTS
|
|
|
729 |
|
| 299 |
dpurdie |
730 |
The command takes one argument: The URL of the desired package.
|
| 267 |
dpurdie |
731 |
This may be be:
|
|
|
732 |
|
|
|
733 |
=over
|
|
|
734 |
|
|
|
735 |
=item * A full URL
|
|
|
736 |
|
|
|
737 |
Complete with protocol and path information.
|
|
|
738 |
|
|
|
739 |
=item * A simple URL
|
|
|
740 |
|
|
|
741 |
JATS will prepend the site-specific repository location to the user provided URL
|
|
|
742 |
|
|
|
743 |
=back
|
|
|
744 |
|
|
|
745 |
=head2 OPTIONS
|
|
|
746 |
|
|
|
747 |
This command has no significant options, other than the general help options.
|
|
|
748 |
|
|
|
749 |
=head2 DESCRIPTION
|
|
|
750 |
|
|
|
751 |
This command will delete a package from the repository. It will ensure
|
|
|
752 |
that the package is a valid package, before it is deleted.
|
|
|
753 |
|
|
|
754 |
The command is intended to be used by test scripts, rather than users.
|
|
|
755 |
|
|
|
756 |
=head1 Create a Package Version
|
|
|
757 |
|
|
|
758 |
=head2 NAME
|
|
|
759 |
|
|
|
760 |
Create a Package Version
|
|
|
761 |
|
|
|
762 |
=head2 SYNOPSIS
|
|
|
763 |
|
|
|
764 |
jats svn [options] create URL [command options]
|
|
|
765 |
|
|
|
766 |
Options:
|
|
|
767 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
768 |
-man - Full documentation [-help=3]
|
|
|
769 |
-verbose[=n] - Verbose command operation
|
|
|
770 |
|
|
|
771 |
Command Options
|
| 299 |
dpurdie |
772 |
-help[=n] - Provide command specific help
|
| 267 |
dpurdie |
773 |
-import=nnn - Import directory tree
|
|
|
774 |
-label=nnn - Label it (trunk import only)
|
|
|
775 |
-new - Package must not exist
|
|
|
776 |
-replace - Replace any existing versions
|
|
|
777 |
-trunk - Import to trunk
|
|
|
778 |
-tags=nnn - Import to tags
|
|
|
779 |
-branch=nnn - Import to branches
|
|
|
780 |
|
|
|
781 |
=head2 ARGUMENTS
|
|
|
782 |
|
| 299 |
dpurdie |
783 |
The command takes one argument: The URL of the desired package.
|
| 267 |
dpurdie |
784 |
This may be be:
|
|
|
785 |
|
|
|
786 |
=over
|
|
|
787 |
|
|
|
788 |
=item * A full URL
|
|
|
789 |
|
|
|
790 |
Complete with protocol and path information.
|
|
|
791 |
|
|
|
792 |
=item * A simple URL
|
|
|
793 |
|
|
|
794 |
JATS will prepend the site-specific repository location to the user provided URL
|
|
|
795 |
|
|
|
796 |
=back
|
|
|
797 |
|
|
|
798 |
=head2 OPTIONS
|
|
|
799 |
|
|
|
800 |
=over
|
|
|
801 |
|
|
|
802 |
=item -help[=n]
|
|
|
803 |
|
|
|
804 |
Print a help message and exit. The level of help may be either 1, 2 or 3.
|
|
|
805 |
|
|
|
806 |
This option may be specified multiple times to increment the help level, or
|
|
|
807 |
the help level may be directly specified as a number.
|
|
|
808 |
|
|
|
809 |
=item -import=nnn
|
|
|
810 |
|
|
|
811 |
This option specifies the path of a subdirectory tree to import into the newly
|
|
|
812 |
created package. In not provided, then only a package skeleton will be created.
|
|
|
813 |
|
|
|
814 |
=item -label=nnn
|
|
|
815 |
|
| 299 |
dpurdie |
816 |
This option specifies a label to place the imported source, if the source is
|
| 267 |
dpurdie |
817 |
being imported to the 'trunk' of the package.
|
|
|
818 |
|
|
|
819 |
=item -new
|
|
|
820 |
|
|
|
821 |
This option specifies that the named package MUST not exist at all.
|
|
|
822 |
|
|
|
823 |
=item -replace
|
|
|
824 |
|
|
|
825 |
This option allows the program to replace any existing versions of the
|
| 299 |
dpurdie |
826 |
imported source. It will allow the deletion of any existing trunk, tags or
|
| 267 |
dpurdie |
827 |
branches.
|
|
|
828 |
|
|
|
829 |
=item -trunk
|
|
|
830 |
|
|
|
831 |
This option specifies that imported source will be placed on the trunk of the
|
|
|
832 |
package. This is the default mode of import.
|
|
|
833 |
|
| 299 |
dpurdie |
834 |
The options -trunk, -tags and -branch are mutually exclusive.
|
| 267 |
dpurdie |
835 |
|
|
|
836 |
=item -tags=nnn
|
|
|
837 |
|
|
|
838 |
This option specifies that imported source will be placed directly on the
|
| 299 |
dpurdie |
839 |
named tag of the package.
|
| 267 |
dpurdie |
840 |
|
| 299 |
dpurdie |
841 |
The options -trunk, -tags and -branch are mutually exclusive.
|
| 267 |
dpurdie |
842 |
|
|
|
843 |
=item -branch=nnn
|
|
|
844 |
|
|
|
845 |
This option specifies that imported source will be placed directly on the
|
| 299 |
dpurdie |
846 |
named branch of the package.
|
| 267 |
dpurdie |
847 |
|
| 299 |
dpurdie |
848 |
The options -trunk, -tags and -branch are mutually exclusive.
|
| 267 |
dpurdie |
849 |
|
|
|
850 |
=back
|
|
|
851 |
|
|
|
852 |
=head2 DESCRIPTION
|
|
|
853 |
|
|
|
854 |
This command will create a new package within a repository. It will ensure
|
|
|
855 |
that the package contains the three required subdirectories: trunk, tags and
|
|
|
856 |
branches.
|
|
|
857 |
|
|
|
858 |
The command will also ensure that packages are not placed at inappropriate
|
|
|
859 |
locations within the repository. It is not correct to place a package within
|
|
|
860 |
another package.
|
|
|
861 |
|
|
|
862 |
The command will, optionally, import a directory tree into the repository and,
|
|
|
863 |
optionally, label the package.
|
|
|
864 |
|
|
|
865 |
The package body may be imported to the 'trunk' or to a branch or a tag.
|
| 299 |
dpurdie |
866 |
By default the data will be imported to the trunk and may be labeled (tagged).
|
| 267 |
dpurdie |
867 |
|
| 299 |
dpurdie |
868 |
Options allow the targets to be deleted if they exist or to ensure that they
|
| 267 |
dpurdie |
869 |
are not present.
|
|
|
870 |
|
|
|
871 |
The command does not attempt to merge file versions within the repository. It
|
|
|
872 |
may result in multiple instances of a file within the repository. Use only for
|
|
|
873 |
simple imports.
|
|
|
874 |
|
|
|
875 |
=head1 Import directory to a Package
|
|
|
876 |
|
|
|
877 |
=head2 NAME
|
|
|
878 |
|
|
|
879 |
Import directory to a Package
|
|
|
880 |
|
|
|
881 |
=head2 SYNOPSIS
|
|
|
882 |
|
|
|
883 |
jats svn [options] import URL [command options]
|
|
|
884 |
|
|
|
885 |
Options:
|
|
|
886 |
-help[=n] - Help message, [n=1,2,3]
|
|
|
887 |
-man - Full documentation [-help=3]
|
|
|
888 |
-verbose[=n] - Verbose command operation
|
|
|
889 |
|
|
|
890 |
Command Options
|
|
|
891 |
-help[=n] - Command specific help, [n=1,2,3]
|
|
|
892 |
-verbose[=n] - Verbose operation
|
|
|
893 |
-package=name - Name of source package
|
|
|
894 |
-dir=path - Path to new version
|
|
|
895 |
-label - Label the result
|
|
|
896 |
-replace - Allow the label to be replaced
|
|
|
897 |
-reuse - Reuse the import directory
|
|
|
898 |
-workspace=path - Path and name of alternate workspace
|
| 299 |
dpurdie |
899 |
-[no]delete - Deletes workspace after use. Default:yes
|
| 267 |
dpurdie |
900 |
|
|
|
901 |
=head2 ARGUMENTS
|
|
|
902 |
|
| 299 |
dpurdie |
903 |
The command takes one argument: The URL of the desired package.
|
| 267 |
dpurdie |
904 |
This may be be:
|
|
|
905 |
|
|
|
906 |
=over
|
|
|
907 |
|
|
|
908 |
=item * A full URL
|
|
|
909 |
|
|
|
910 |
Complete with protocol and path information.
|
|
|
911 |
|
|
|
912 |
=item * A simple URL
|
|
|
913 |
|
|
|
914 |
JATS will prepend the site-specific repository location to the user provided URL
|
|
|
915 |
|
|
|
916 |
=back
|
|
|
917 |
|
|
|
918 |
=head2 OPTIONS
|
|
|
919 |
|
|
|
920 |
=over
|
|
|
921 |
|
|
|
922 |
=item -help[=n]
|
|
|
923 |
|
|
|
924 |
Print a help message and exit. The level of help may be either 1, 2 or 3.
|
|
|
925 |
|
|
|
926 |
This option may be specified multiple times to increment the help level, or
|
|
|
927 |
the help level may be directly specified as a number.
|
|
|
928 |
|
|
|
929 |
=item -verbose[=n]
|
|
|
930 |
|
|
|
931 |
This option will increase the level of verbosity of the utility.
|
|
|
932 |
|
|
|
933 |
If an argument is provided, then it will be used to set the level, otherwise the
|
|
|
934 |
existing level will be incremented. This option may be specified multiple times.
|
|
|
935 |
|
|
|
936 |
|
|
|
937 |
=item -package=name
|
|
|
938 |
|
| 299 |
dpurdie |
939 |
Either this option or a bare URL on the command line must be provided. It
|
|
|
940 |
specifies the repository and package to be used as a basis for the work.
|
| 267 |
dpurdie |
941 |
|
|
|
942 |
=item -dir=path
|
|
|
943 |
|
|
|
944 |
This option is mandatory. It specifies the path to a local directory that
|
|
|
945 |
contains a version of the software to be checked in.
|
|
|
946 |
|
|
|
947 |
=item -label=name
|
|
|
948 |
|
| 299 |
dpurdie |
949 |
The resulting software version will be labeled with this tag, if it is provided.
|
| 267 |
dpurdie |
950 |
|
|
|
951 |
=item -replace
|
|
|
952 |
|
|
|
953 |
This option, if provided, allows the label to be replaced.
|
|
|
954 |
|
|
|
955 |
=item -reuse
|
|
|
956 |
|
|
|
957 |
This option can be used to speed the creation of multiple versions in a scripted
|
| 299 |
dpurdie |
958 |
environment. The option allows the utility to reuse the workspace if it exists.
|
| 267 |
dpurdie |
959 |
|
| 299 |
dpurdie |
960 |
=item -workspace=path
|
| 267 |
dpurdie |
961 |
|
|
|
962 |
This option specifies an alternate workspace directory to create and use. The
|
| 297 |
dpurdie |
963 |
default directory is "SvnImportDir" within the users current directory.
|
| 267 |
dpurdie |
964 |
|
| 299 |
dpurdie |
965 |
=item [no]delete
|
|
|
966 |
|
|
|
967 |
This option control the deletion of the workspace directory. By default he
|
|
|
968 |
directory will be deleted, unless re-use is also used.
|
|
|
969 |
|
| 267 |
dpurdie |
970 |
=back
|
|
|
971 |
|
|
|
972 |
=head2 DESCRIPTION
|
|
|
973 |
|
|
|
974 |
Import a new version of a package to the trunk of the package. The utility
|
|
|
975 |
will only import changed files so that file history is preserved within the
|
|
|
976 |
repository.
|
|
|
977 |
|
|
|
978 |
This utility is used import software from another version control system
|
|
|
979 |
The utility will:
|
|
|
980 |
|
|
|
981 |
=over
|
|
|
982 |
|
| 299 |
dpurdie |
983 |
=item * Create a Work Space based on the current package version
|
| 267 |
dpurdie |
984 |
|
| 299 |
dpurdie |
985 |
The 'trunk' of the named package will be used as the base for the workspace.
|
| 267 |
dpurdie |
986 |
|
|
|
987 |
=item * Update files and directories
|
|
|
988 |
|
|
|
989 |
Determines the files and directories that have been added and deleted and
|
|
|
990 |
update the Workspace to reflect the new structure.
|
|
|
991 |
|
|
|
992 |
=item * Check in the new version
|
|
|
993 |
|
|
|
994 |
=item * Label the new version
|
|
|
995 |
|
|
|
996 |
=back
|
|
|
997 |
|
| 299 |
dpurdie |
998 |
The utility can optionally perform other operations including:
|
|
|
999 |
|
|
|
1000 |
=over
|
|
|
1001 |
|
|
|
1002 |
=item * Import directly to a branch. This does not affect the 'trunk'.
|
|
|
1003 |
|
|
|
1004 |
=item * Import directly to a tag. This does not affect the 'trunk'
|
|
|
1005 |
|
|
|
1006 |
=back
|
|
|
1007 |
|
| 267 |
dpurdie |
1008 |
=cut
|
|
|
1009 |
|