Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
311 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;
379 dpurdie 24
use JatsProperties;
311 dpurdie 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;
387 dpurdie 32
use Encode;
311 dpurdie 33
 
34
my $VERSION = "1.0.0";                          # Update this
35
 
36
#
37
#   Options
38
#
39
my $opt_debug   = $ENV{'GBE_DEBUG'};            # Allow global debug
40
my $opt_verbose = $ENV{'GBE_VERBOSE'};          # Allow global verbose
41
my $opt_help = 0;
42
 
43
#
44
#   Globals
45
#
46
my $opr_done;                                   # User has done something
47
 
48
#-------------------------------------------------------------------------------
49
# Function        : Mainline Entry Point
50
#
51
# Description     :
52
#
53
# Inputs          :
54
#
55
my $result = GetOptions (
56
                "help:+"        => \$opt_help,              # flag, multiple use allowed
57
                "manual:3"      => \$opt_help,              # flag
58
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
59
 
60
                );
61
 
62
                #
63
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
64
                #
65
 
66
#
67
#   Process help and manual options
68
#
69
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
70
pod2usage(-verbose => 1) if ($opt_help == 2 );
71
pod2usage(-verbose => 2) if ($opt_help > 2);
72
 
73
#
74
#   Configure the error reporting process now that we have the user options
75
#
76
ErrorConfig( 'name'    =>'SVN',
77
             'verbose' => $opt_verbose,
78
            );
79
 
80
#
369 dpurdie 81
#   Reconfigure the options parser to allow subcommands to parse options
311 dpurdie 82
#
83
Getopt::Long::Configure('permute');
84
 
85
#
86
#   Process command
87
#   First command line argument is a subversion command
88
#
89
my $cmd = shift @ARGV || "help";
90
CreatePackage()                        if ( $cmd =~ m/^create/ );
2048 dpurdie 91
CreateBranch()                         if ( $cmd =~ m/^branch/ );
92
SwitchBranch()                         if ( $cmd =~ m/^switch/ );
385 dpurdie 93
DeleteBranch()                         if ( $cmd =~ m/^delete-branch/ );
311 dpurdie 94
DeletePackage()                        if ( $cmd =~ m/^delete-package/ );
95
ImportPackage()                        if ( $cmd =~ m/^import/ );
96
SvnRepoCmd($cmd, @ARGV)                if ( $cmd eq 'ls' );
363 dpurdie 97
TestSvn()                              if ($cmd eq 'test');
369 dpurdie 98
ShowPaths()                            if ( $cmd =~ m/^path/ );
99
ShowTag()                              if ( $cmd =~ m/^tag/ );
100
ShowUrl()                              if ( $cmd =~ m/^url/ );
311 dpurdie 101
 
102
pod2usage(-verbose => 0, -message => "No valid operations specified") unless ( $opr_done );
103
exit 0;
104
 
105
#-------------------------------------------------------------------------------
369 dpurdie 106
# Function        : ShowPaths
107
#
108
# Description     : Show PATHS
109
#
2048 dpurdie 110
# Inputs          :
369 dpurdie 111
#
2048 dpurdie 112
# Returns         :
369 dpurdie 113
#
114
sub ShowPaths
115
{
116
    #
117
    #   Parse more options
118
    #
119
    GetOptions (
120
                "help:+"        => \$opt_help,
121
                "manual:3"      => \$opt_help,
122
                ) || Error ("Invalid command line" );
123
 
124
    #
125
    #   Subcommand specific help
126
    #
127
    SubCommandHelp( $opt_help, "Subversion Paths") if ($opt_help || $#ARGV >= 0);
128
 
129
    #
130
    #   Display known PATHS
131
    #
132
    my ( $pSVN_URLS, $pSVN_URLS_LIST) = SvnPaths();
133
    print ("Configured SubVersion Repository Paths\n");
134
    print sprintf("    %-20s %s\n", 'Tag', 'URL Prefix');
135
 
136
    foreach my $key ( @{$pSVN_URLS_LIST} )
137
    {
138
        print sprintf("    %-20s %s\n", $key || 'Default', $pSVN_URLS->{$key} );
139
    }
140
 
141
    $opr_done = 1;
142
}
143
 
144
#-------------------------------------------------------------------------------
145
# Function        : ShowTag
146
#
147
# Description     : Convert a URL into a TAG
148
#                   Convert the current workspace info into a TAG
149
#
150
# Inputs          : url                     - Url to convert (optional)
151
#                   Options
152
#                       -help[=n]           - Show help
153
#                       -man                - Show manual
154
#                       -url=url            - Convert URL
155
#                       -path=path          - Convert Workspace
156
#
157
# Returns         : Nothing
158
#
159
sub ShowTag
160
{
161
    my $opt_path;
162
    my $opt_url;
163
 
164
    #
165
    #   Parse more options
166
    #
167
    GetOptions (
168
                "help:+"        => \$opt_help,
169
                "manual:3"      => \$opt_help,
170
                "path:s"        => \$opt_path,
171
                "url:s"         => \$opt_url,
172
                ) || Error ("Invalid command line" );
173
 
174
    #
175
    #   Subcommand specific help
176
    #
177
    SubCommandHelp( $opt_help, "Url to Tag") if ($opt_help);
178
 
179
    #
180
    #   Bare argument is a URL
181
    #   If no arguments provided assume a path of the current directory
182
    #
183
    $opt_url = shift (@ARGV) if ( $#ARGV == 0 );
184
    $opt_path = '.' unless ( defined $opt_path || defined $opt_url );
185
 
186
    #
187
    #   Sanity Tests
188
    #
189
    Error ("Cannot specify both a URL and a PATH")
190
            if ( defined $opt_url && defined $opt_path );
191
    Warning ("Too many arguments") if ( $#ARGV >= 0 );
192
 
193
    #   Do all the hard work
194
    #
195
    my $uref;
196
    if ( $opt_url )
197
    {
198
        $uref = NewSessionByUrl ( $opt_url );
199
        $uref->CalcRmReference($uref->Full());
200
    }
201
    else
202
    {
203
        $uref = NewSessionByWS($opt_path, 0, 1);
204
        my $ws_root = $uref->SvnLocateWsRoot(1);
205
        $uref->CalcRmReference($uref->FullWs());
206
    }
207
 
1348 dpurdie 208
    Message ("Tag is  : " . $uref->RmRef() );
209
    Message ("Vcs Tag : " . $uref->SvnTag  );
2048 dpurdie 210
 
369 dpurdie 211
    $opr_done = 1;
212
}
213
#-------------------------------------------------------------------------------
214
# Function        : ShowUrl
215
#
216
# Description     : Convert a TAG into a URL
217
#                   Show the current workspace URL
218
#
219
# Inputs          : tag                     - Tag to convert (optional)
220
#                   Options
221
#                       -help[=n]           - Show help
222
#                       -man                - Show manual
223
#                       -tag=tag            - Convert TAG
224
#                       -path=path          - Convert Workspace
225
#
226
# Returns         : Nothing
227
#
228
sub ShowUrl
229
{
230
    my $opt_path;
231
    my $opt_tag;
232
 
233
    #
234
    #   Parse more options
235
    #
236
    GetOptions (
237
                "help:+"        => \$opt_help,
238
                "manual:3"      => \$opt_help,
239
                "path:s"        => \$opt_path,
240
                "tag:s"         => \$opt_tag,
241
                ) || Error ("Invalid command line" );
242
 
243
    #
244
    #   Subcommand specific help
245
    #
246
    SubCommandHelp( $opt_help, "Tag to Url") if ($opt_help);
247
 
248
    #
249
    #   Bare argument is a TAG
250
    #   If no arguments provided assume a path of the current directory
251
    #
252
    $opt_tag = shift (@ARGV) if ( $#ARGV == 0 );
253
    $opt_path = '.' unless ( defined $opt_path || defined $opt_tag );
254
 
255
    #
256
    #   Sanity Tests
257
    #
258
    Error ("Cannot specify both a TAG and a PATH")
259
            if ( defined $opt_tag && defined $opt_path );
260
    Warning ("Too many arguments") if ( $#ARGV >= 0 );
261
 
262
    #   Do all the hard work
263
    #
264
    my $uref;
265
    my $url;
266
    if ( $opt_tag )
267
    {
2424 dpurdie 268
        my $path = $opt_tag;
269
        my $label;
270
 
271
        $path =~ s~^SVN::~~;
272
        if ( $path =~ m~(.+)::(.+)~ )
273
        {
274
            $path = $1;
275
            $label = $2;
276
        }
277
        $url = SvnPath2Url($path);
278
        if ( $label && $label =~ m~^\d+$~ )
279
        {
280
            $url .= '@' . $label;
281
        }
282
        elsif ( $label )
283
        {
284
            $url =~ m~(.+)(/(tags|branches|trunk)(/|$|@))~;
285
            $url = $1 . '/tags/'. $label;
286
        }
369 dpurdie 287
    }
288
    else
289
    {
290
        $uref = NewSessionByWS($opt_path, 0, 1);
291
        my $ws_root = $uref->SvnLocateWsRoot(1);
292
        $url = $uref->FullWsRev();
293
    }
294
 
295
    Message ("Url: $url");
296
    $opr_done = 1;
297
}
298
 
299
#-------------------------------------------------------------------------------
363 dpurdie 300
# Function        : TestSvn
301
#
302
# Description     : Test access to subversion
303
#
304
# Inputs          : None
305
#
306
# Returns         :
307
#
308
sub TestSvn
309
{
310
    #
311
    #   Parse more options
312
    #
313
    GetOptions (
314
                "help:+"        => \$opt_help,
315
                "manual:3"      => \$opt_help,
316
                ) || Error ("Invalid command line" );
317
 
318
    #
319
    #   Subcommand specific help
320
    #
321
    SubCommandHelp( $opt_help, "Test Subversion") if ($opt_help || $#ARGV >= 0);
322
 
323
    SvnUserCmd( '--version');
324
    $opr_done = 1;
325
}
326
#-------------------------------------------------------------------------------
311 dpurdie 327
# Function        : SvnRepoCmd
328
#
329
# Description     : Execute a SVN command, where the first argument
330
#                   is a repository specifier
331
#
332
# Inputs          : $cmd
333
#                   $repo_url
334
#                   @opts
335
#
2048 dpurdie 336
# Returns         :
311 dpurdie 337
#
338
sub SvnRepoCmd
339
{
340
    my ( $cmd, $repo_url, @opts ) = @_;
341
    my $uref = NewSessionByUrl ( $repo_url );
342
 
343
    SvnUserCmd( $cmd,
344
            $uref->Full,
345
            @opts,
346
            { 'credentials' => 1 });
2048 dpurdie 347
 
311 dpurdie 348
    $opr_done = 1;
349
}
350
 
351
#-------------------------------------------------------------------------------
352
# Function        : DeletePackage
353
#
354
# Description     : Delete a Package structure within a Repository
355
#                   Intended for test usage
356
#
357
# Inputs          : URL                 - Url to Repo + Package Base
358
#
2048 dpurdie 359
# Returns         :
311 dpurdie 360
#
361
sub DeletePackage
362
{
379 dpurdie 363
    my $opt_error = 0;
311 dpurdie 364
    #
365
    #   Parse more options
366
    #
367
    GetOptions (
368
                "help:+"        => \$opt_help,
369
                "manual:3"      => \$opt_help,
379 dpurdie 370
                "error!"       => \$opt_error,
311 dpurdie 371
                ) || Error ("Invalid command line" );
372
 
373
    #
374
    #   Subcommand specific help
375
    #
376
    SubCommandHelp( $opt_help, "Delete a Package") if ($opt_help || $#ARGV < 0);
377
 
378
    #
379
    #   Sanity Tests
380
    #
381
    Message ("Delete Entire Package Tree" );
382
    Warning ("Too many arguments: @ARGV") if ( $#ARGV >= 1 );
383
 
384
    #
385
    #   Do all the hard work
386
    #       Create
387
    #       Import
388
    #       Label
389
    #
390
    my $uref = NewSessionByUrl ( $ARGV[0] );
379 dpurdie 391
    $uref->SvnValidatePackageRoot(!$opt_error);
311 dpurdie 392
    $uref->SvnDelete (
393
                      'target'      => $uref->Full,
385 dpurdie 394
                      'comment'   => [$uref->Path().": Delete Package",'Deleted by user command: jats svn delete-package'],
379 dpurdie 395
                      'noerror'   => !$opt_error,
311 dpurdie 396
                      );
397
    $opr_done = 1;
398
}
399
 
400
#-------------------------------------------------------------------------------
401
# Function        : CreatePackage
402
#
403
# Description     : Create a Package structure within a Repository
404
#                   Optionally Import Data
405
#                   Optionally Tag the import
406
#                   Optionally Tag the import on a branch
407
#
408
# Inputs          : URL                 - Url to Repo + Package Base
409
#                   Options             - Command modifiers
410
#                       -import=path    - Import named directory
411
#                       -label=name     - Label the result
412
#                       -tag=name       - Import to Tag Only
413
#                       -branch=name    - Import to Branch only
414
#                       -new            - Must be new package
415
#                       -replace        - Replace existing
416
#
2048 dpurdie 417
# Returns         :
311 dpurdie 418
#
419
sub CreatePackage
420
{
421
    my $opt_import;
422
    my $opt_tag;
423
    my $opt_branch;
424
    my $opt_trunk;
425
    my $opt_new;
426
    my $opt_label;
427
    my $opt_replace;
428
    my $pname;
429
    my $type;
385 dpurdie 430
    my $opt_author;
431
    my $opt_date;
311 dpurdie 432
    Message ("Create New Package Version" );
433
 
434
    #
435
    #   Parse more options
436
    #
437
    GetOptions (
438
                "help:+"        => \$opt_help,
439
                "manual:3"      => \$opt_help,
440
                "verbose:+"     => \$opt_verbose,
441
                "import=s"      => \$opt_import,
442
                "new"           => \$opt_new,
443
                "branch=s"      => \$opt_branch,
444
                "trunk"         => \$opt_trunk,
1347 dpurdie 445
                "tags=s"        => \$opt_tag,
311 dpurdie 446
                "label=s"       => \$opt_label,
447
                "replace"       => \$opt_replace,
385 dpurdie 448
                'author=s'      => \$opt_author,
449
                'date=s'        => \$opt_date,
311 dpurdie 450
 
451
                ) || Error ("Invalid command line" );
452
 
453
    #
454
    #   Subcommand specific help
455
    #
456
    SubCommandHelp( $opt_help, "Create a Package Version") if ($opt_help || $#ARGV < 0);
2048 dpurdie 457
 
311 dpurdie 458
    #
369 dpurdie 459
    #   Alter the error reporting parameters
311 dpurdie 460
    #
461
    ErrorConfig( 'verbose' => $opt_verbose );
462
 
463
    #
464
    #   Sanity Tests
465
    #
466
    my $count = 0;
467
    $count++ if ( $opt_trunk );
468
    $count++ if ( $opt_branch );
469
    $count++ if ( $opt_tag );
470
    Error ("Conflicting options: -trunk, -tag, -branch") if ( $count > 1 );
471
    Error ("Nothing imported to be labeled") if ( $count && !$opt_import );
472
    Error ("Import path does not exist: $opt_import") if ( $opt_import && ! -d $opt_import );
473
    Error ("Conflicting options: new and replace") if ( $opt_new && $opt_replace );
385 dpurdie 474
    Error ("Too many command line arguments") if ( exists $ARGV[1] );
311 dpurdie 475
 
1347 dpurdie 476
    $type = 'tags/' . $opt_tag          if ( $opt_tag);
477
    $type = 'branches/' . $opt_branch   if ( $opt_branch );
478
    $type = 'trunk'                     if ( $opt_trunk);
311 dpurdie 479
 
480
    #
481
    #   Do all the hard work
482
    #       Create
483
    #       Import
484
    #       Label
485
    #
486
    my $uref = NewSessionByUrl ( $ARGV[0] );
487
    $uref->SvnCreatePackage (
488
                      'import'  => $opt_import,
489
                      'label'   => $opt_label,
490
                      'type'    => $type,
491
                      'new'     => $opt_new,
492
                      'replace' => $opt_replace,
493
                      );
385 dpurdie 494
    #
495
    # Report RmPath as using a pegged version of a new package is a bit silly
496
    #
1356 dpurdie 497
#    Message ("Repository Ref: " . $uref->RmPath);
498
#    Message ("Vcs Tag       : " . $uref->SvnTag);
1270 dpurdie 499
    if ( $uref->{REVNO} )
500
    {
501
        $uref->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
502
        $uref->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
503
    }
311 dpurdie 504
    $opr_done = 1;
505
}
506
 
507
#-------------------------------------------------------------------------------
508
# Function        : ImportPackage
509
#
510
# Description     : Import a new version of a package
511
#                   Take great care to reuse file-versions that are already in
512
#                   the  package
513
#
369 dpurdie 514
#                   Intended to allow the importation of multiple
311 dpurdie 515
#                   versions of a package
516
#
2048 dpurdie 517
# Inputs          :
311 dpurdie 518
#
2048 dpurdie 519
# Returns         :
311 dpurdie 520
#
521
sub ImportPackage
522
{
523
    Message ("Import Package Version" );
524
 
525
    #
526
    #   Options
527
    #
528
    my $opt_package;
529
    my $opt_dir;
530
    my $opt_label;
531
    my $opt_replace = 0;
532
    my $opt_reuse;
533
    my $opt_workdir = "SvnImportDir";
534
    my $opt_delete = 1;
379 dpurdie 535
    my $opt_author;
536
    my $opt_date;
537
    my $opt_log = '';
538
    my $opt_branch;
539
    my $opt_datafile;
1348 dpurdie 540
    my $opt_printfiles;
2424 dpurdie 541
    my $opt_commit = 1;
311 dpurdie 542
 
543
    #
544
    #   Other globals
545
    #
546
    my $url_label;
379 dpurdie 547
    my $url_branch;
311 dpurdie 548
 
549
    #
550
    #   Configuration options
551
    #
552
    my $result = GetOptions (
379 dpurdie 553
                    'help:+'        => \$opt_help,
554
                    'manual:3'      => \$opt_help,
555
                    'verbose:+'     => \$opt_verbose,
556
                    'package=s'     => \$opt_package,
557
                    'dir=s'         => \$opt_dir,
558
                    'label=s'       => \$opt_label,
559
                    'branch=s'      => \$opt_branch,
560
                    'replace'       => \$opt_replace,
561
                    'reuse'         => \$opt_reuse,
562
                    'workspace=s'   => \$opt_workdir,
563
                    'delete!'       => \$opt_delete,
1348 dpurdie 564
                    'printfiles=i'  => \$opt_printfiles,
379 dpurdie 565
                    'author=s'      => \$opt_author,
566
                    'date=s'        => \$opt_date,
567
                    'log=s'         => \$opt_log,
568
                    'datafile=s'    => \$opt_datafile,
2424 dpurdie 569
                    'commit!'       => \$opt_commit,
311 dpurdie 570
 
571
                    #
572
                    #   Update documentation at the end of the file
573
                    #
574
                    ) || Error ("Invalid command line" );
575
 
576
    #
577
    #   Insert defaults
341 dpurdie 578
    #   User can specify base package via -package or a non-options argument
311 dpurdie 579
    #
580
    $opt_package = $ARGV[0] unless ( $opt_package );
379 dpurdie 581
    unlink $opt_datafile if ( defined $opt_datafile );
2048 dpurdie 582
 
311 dpurdie 583
    #
584
    #   Subcommand specific help
585
    #
586
    SubCommandHelp( $opt_help, "Import directory to a Package")
587
        if ($opt_help || ! $opt_package );
588
 
589
    #
369 dpurdie 590
    #   Alter the error reporting parameters
311 dpurdie 591
    #
592
    ErrorConfig( 'verbose' => $opt_verbose );
593
 
594
    #
595
    #   Configure the error reporting process now that we have the user options
596
    #
597
    Error ("No package URL specified") unless ( $opt_package );
598
    Error ("No base directory specified") unless ( $opt_dir );
599
    Error ("Invalid base directory: $opt_dir") unless ( -d $opt_dir );
2424 dpurdie 600
    Error ("Cannot label if not committing") if ( $opt_label && ! $opt_commit );
311 dpurdie 601
 
602
    #
603
    #   Create an SVN session
604
    #
605
    my $svn = NewSessionByUrl ( $opt_package );
606
 
607
    #
608
    #   Ensure that the required label is available
609
    #
610
    if ( $opt_label )
611
    {
612
        $opt_label = SvnIsaSimpleLabel ($opt_label);
613
        $url_label = $svn->BranchName( $opt_label, 'tags' );
614
        $svn->SvnValidateTarget (
615
                        'target' => $url_label,
616
                        'available' => 1,
617
                        ) unless ( $opt_replace );
618
    }
619
 
620
    #
379 dpurdie 621
    #   Validate the required branch
622
    #   It will be created if it doesn't exist
623
    #
624
    if ( $opt_branch )
625
    {
626
        $opt_branch = SvnIsaSimpleLabel($opt_branch);
627
        $url_branch = $svn->BranchName( $opt_branch, 'branches' );
385 dpurdie 628
        my $rv = $svn->SvnValidateTarget (
629
                        'cmd'    => 'SvnImporter. Create branch',
379 dpurdie 630
                        'target' => $url_branch,
631
                        'create' => 1,
632
                        );
385 dpurdie 633
        if ( $rv == 2 )
634
        {
635
            $svn->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
636
            $svn->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
637
        }
379 dpurdie 638
    }
639
 
640
    #
311 dpurdie 641
    #   Create a workspace based on the users package
642
    #   Allow the workspace to be reused to speed up multiple
643
    #   operations
644
    #
645
    unless ( $opt_reuse && -d $opt_workdir )
646
    {
647
        Message ("Creating Workspace");
648
        rmtree( $opt_workdir );
649
 
650
        $svn->SvnValidatePackageRoot ();
651
        #DebugDumpData( 'Svn', $svn );
652
        $svn->SvnValidateTarget (
653
                            'cmd'    => 'SvnImporter',
654
                            'target' => $svn->Full,
655
                            'require' => 1,
656
                            );
657
 
379 dpurdie 658
        my $url_co = $opt_branch ? $url_branch : $svn->Full . '/trunk';
1356 dpurdie 659
        $svn->SvnCo ( $url_co, $opt_workdir, 'print' => $opt_printfiles );
311 dpurdie 660
        Error ("Cannot locate the created Workspace")
661
            unless ( -d $opt_workdir );
662
    }
663
    else
664
    {
665
        Message ("Reusing Workspace");
666
    }
2048 dpurdie 667
 
311 dpurdie 668
    #
669
    #   Determine differences between the two folders
670
    #       Create structures for each directory
671
    #
672
    Message ("Determine Files in packages");
673
 
674
    my $search = JatsLocateFiles->new("--Recurse=1",
675
                                       "--DirsToo",
676
                                       "--FilterOutRe=/\.svn/",
677
                                       "--FilterOutRe=/\.svn\$",
678
                                       "--FilterOutRe=^/${opt_workdir}\$",
679
                                       "--FilterOutRe=^/${opt_workdir}/",
680
                                       );
681
    my @ws = $search->search($opt_workdir);
682
    my @dir = $search->search($opt_dir);
683
 
1270 dpurdie 684
    #
685
    #   Scan for a source file
686
    #   Trying to detect empty views
687
    #   Look for file, not directory
688
    #
689
    {
690
        my $fileFound = 0;
691
        foreach ( @dir )
692
        {
693
            next if ( m~/$~ );
694
            $fileFound++;
695
            last;
696
        }
697
 
698
        unless ( $fileFound )
699
        {
700
            Warning ("No source files found in source view");
701
            $opr_done = 1;
702
            return;
703
        }
704
    }
705
 
311 dpurdie 706
    #Information ("WS Results", @ws);
707
    #Information ("DIR Results", @dir);
1270 dpurdie 708
    #Information ("WS Results: ", scalar @ws);
709
    #Information ("DIR Results:", scalar @dir);
311 dpurdie 710
 
711
    #
712
    #   Create a hash the Workspace and the User dir
713
    #   The key will be file names
714
    #
715
    my %ws;  map ( $ws{$_} = 1 , @ws );
716
    my %dir; map ( $dir{$_} = 1 , @dir );
717
 
718
    #
719
    #   Create a hash of common elements
720
    #   Removing then from the other two
721
    #
722
    my %common;
723
    foreach ( keys %ws )
724
    {
725
        next unless ( exists $dir{$_} );
726
        $common{$_} = 1;
727
        delete $ws{$_};
728
        delete $dir{$_};
729
    }
730
 
731
    #DebugDumpData( 'WS', \%ws );
732
    #DebugDumpData( 'DIR', \%dir );
733
    #DebugDumpData( 'COMMON', \%common );
734
 
735
    #
379 dpurdie 736
    #   Need to consider the case where a file has been replaced with a directory
737
    #   and visa-versa. Delete files and directories first.
738
    #
739
    #
740
    #   Remove files
741
    #   Sort in reverse. This will ensure that we process directory
742
    #   contents before directories
743
    #
744
    my @rm_files = reverse sort keys %ws;
745
    if ( @rm_files )
746
    {
747
        foreach my $file ( @rm_files  )
748
        {
749
            Verbose ("Removing $file");
750
            unlink "$opt_workdir/$file";
751
        }
752
 
753
        #
754
        #   Inform Subversion about the removed files
755
        #
756
        my $base = 0;
757
        my $num = $#rm_files;
758
        Message ("Update the workspace: Removed " . ($num + 1) . " Files");
759
 
760
        while ( $base <= $num )
761
        {
762
            my $end = $base + 200;
763
            $end = $num if ( $end > $num );
764
 
765
            $svn->SvnCmd ( 'delete', map ("$opt_workdir/$_@", @rm_files[$base .. $end] ),
766
                            { 'error' => 'Deleting files from workspace' } );
2048 dpurdie 767
 
379 dpurdie 768
            $base = $end + 1;
769
        }
770
    }
2048 dpurdie 771
 
379 dpurdie 772
    #
311 dpurdie 773
    #   Add New Files
774
    #   Won't add empty directories at this point
775
    #
776
    #   Process by sorted list
777
    #   This will ensure we process parent directories first
778
    #
779
    my @added = sort keys %dir;
780
    if ( @added )
781
    {
782
        foreach my $file ( @added  )
783
        {
784
            my $src = "$opt_dir/$file";
785
            my $target = "$opt_workdir/$file";
786
 
787
            if ( -d $src )
788
            {
379 dpurdie 789
                Verbose ("Adding directory: $file");
311 dpurdie 790
                mkdir ( $target ) unless (-d $target);
791
            }
792
            else
793
            {
794
 
795
                my $path = dirname ( $target);
796
                mkdir ( $path ) unless (-d $path);
797
 
798
                Verbose ("Adding $file");
799
                unless (File::Copy::copy( $src, $target ))
800
                {
801
                    Error("Failed to transfer file [$file]: $!");
802
                }
803
            }
804
        }
805
 
806
        #
807
        #   Inform Subversion about the added files
808
        #   The command line does have a finite length, so add them 200 at a
809
        #   time.
810
        #
811
 
812
        my $base = 0;
813
        my $num = $#added;
379 dpurdie 814
        Message ("Update the workspace: Added " . (1 + $num) . " files");
311 dpurdie 815
 
816
        while ( $base <= $num )
817
        {
818
            my $end = $base + 200;
819
            $end = $num if ( $end > $num );
820
 
821
            $svn->SvnCmd ( 'add'
822
                            , '--depth=empty'
823
                            , '--parents'
379 dpurdie 824
                            , map ("$opt_workdir/$_@", @added[$base .. $end] ),
311 dpurdie 825
                            { 'error' => 'Adding files to workspace' } );
826
 
827
            $base = $end + 1;
828
        }
829
    }
830
 
831
    #
832
    #   The common files may have changed
833
    #   Simply copy them all in and let subversion figure it out
834
    #
835
    foreach my $file ( sort keys %common  )
836
    {
837
        my $src = "$opt_dir/$file";
838
        my $target = "$opt_workdir/$file";
839
 
840
        next if ( -d $src );
841
        if ( File::Compare::compare ($src, $target) )
842
        {
843
            Verbose ("Transfer $file");
844
            unlink $target;
845
            unless (File::Copy::copy( $src, $target ))
846
            {
847
                Error("Failed to transfer file [$file]: $!",
848
                      "Src: $src",
849
                      "Tgt: $target");
850
            }
851
        }
852
    }
853
 
854
    #
855
    #   Commit the workspace
856
    #   This will go back onto the trunk
857
    #
2424 dpurdie 858
    if ( $opt_commit )
859
    {
860
        $svn = NewSessionByWS( $opt_workdir );
861
        my $pkgPath = $svn->Path();
387 dpurdie 862
 
2424 dpurdie 863
        my $ciComment = "$pkgPath: Checkin by Svn Import";
864
        $ciComment .= "\n" . $opt_log if ( $opt_log );
865
        $ciComment =~ s~\r\n~\n~g;
866
        $ciComment =~ s~\r~\n~g;
867
        $ciComment = encode('UTF-8', $ciComment, Encode::FB_DEFAULT);
387 dpurdie 868
 
2424 dpurdie 869
        $svn->SvnCi ('comment' => $ciComment, 'allowSame' => 1 );
870
        Message ("Repository Ref: " . $svn->RmRef) unless( $opt_label );
379 dpurdie 871
        $svn->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
872
        $svn->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
2424 dpurdie 873
 
874
        #
875
        #   Label the result
876
        #   The workspace will have been updated, so we can use it as the base for
877
        #   the labeling process
878
        #
879
        if ( $opt_label )
880
        {
881
            $svn->SvnCopyWs (
882
                           target => $url_label,
883
                           'noswitch' => 1,
884
                           'replace' => $opt_replace,
885
                           'comment' => "$pkgPath: Tagged by Jats Svn Import",
886
                           );
887
            Message ("Repository Ref: " . $svn->RmRef);
888
            Message ("Vcs Tag       : " . $svn->SvnTag);
889
            $svn->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
890
            $svn->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
891
        }
311 dpurdie 892
    }
2424 dpurdie 893
    else
894
    {
895
        Message ("Workspace not commited","Workspace: $opt_workdir");
896
    }
311 dpurdie 897
 
898
    #
899
    #   Clean up
900
    #
2424 dpurdie 901
    if ( $opt_delete && ! $opt_reuse  && $opt_commit )
311 dpurdie 902
    {
903
        Message ("Delete Workspace");
904
        rmtree( $opt_workdir );
905
    }
379 dpurdie 906
 
907
    #
908
    #   Automation data transfer
909
    #
910
    if ( defined $opt_datafile )
911
    {
912
        my $data = JatsProperties::New();
913
 
914
        $data->setProperty('Command'        , 'ImportPackage');
915
        $data->setProperty('Label'          , $opt_label);
1347 dpurdie 916
        $data->setProperty('subversion.url' , $svn->RmRef);
917
        $data->setProperty('subversion.tag' , $svn->SvnTag);
379 dpurdie 918
 
919
        $data->Dump('InfoFile') if ($opt_verbose);
920
        $data->store( $opt_datafile );
921
    }
922
 
311 dpurdie 923
    $opr_done = 1;
924
}
925
 
926
#-------------------------------------------------------------------------------
385 dpurdie 927
# Function        : DeleteBranch
928
#
929
# Description     : Delete the branch that a workspace is based upon
930
#
2048 dpurdie 931
# Inputs          :
385 dpurdie 932
#
2048 dpurdie 933
# Returns         :
385 dpurdie 934
#
935
sub DeleteBranch
936
{
937
    my $opt_path;
938
    my $opt_error = 0;
939
    #
940
    #   Parse more options
941
    #
942
    GetOptions (
943
                "help:+"        => \$opt_help,
944
                "manual:3"      => \$opt_help,
945
                "path:s"        => \$opt_path,
946
                ) || Error ("Invalid command line" );
947
 
948
    #
949
    #   Subcommand specific help
950
    #
951
    SubCommandHelp( $opt_help, "Delete Branch") if ($opt_help);
952
 
953
    #
954
    #   Sanity Tests
955
    #
2071 dpurdie 956
    Message ("Delete Workspace Branchs" );
385 dpurdie 957
 
958
    #
959
    #   Do all the hard work
960
    #
961
    $opt_path = '.' unless ( defined $opt_path );
962
    my $uref = NewSessionByWS($opt_path, 0, 1);
963
    my $ws_root = $uref->SvnLocateWsRoot(1);
964
    my $ws_url = $uref->FullWs();
965
 
966
    #
2071 dpurdie 967
    #   What we do depends what aruments the user provided
385 dpurdie 968
    #
2071 dpurdie 969
    unless ( @ARGV )
970
    {
971
        #
972
        #   If no branch was specified - then display the workspace branch
973
        #
974
        Error ('The workspace is not based on a branch')
975
            unless ( $ws_url =~ m ~/branches/(.*)~ );
976
        Message('The workspace is based on the branch: '. $1);
977
    }
978
    else
979
    {
980
        #
981
        #   Delete all specified branches
982
        #
983
        foreach my $branch ( @ARGV )
984
        {
985
            Message ("Deleting: " . $branch );
986
            my $target = join( '/', $uref->FullPath(), 'branches', $branch);
987
            if ( $uref->SvnDelete (
988
                              'target'    => $target,
989
                              'comment'   => [$uref->Path().": Delete Branch",'Deleted by user command: jats svn delete-branch'],
990
                              'noerror'   => 1,
991
                              )
992
               )
993
            {
994
                Warning ("Branch deletion failed: $branch");
995
            }
996
        }
997
    }
385 dpurdie 998
    $opr_done = 1;
999
}
1000
 
2048 dpurdie 1001
#-------------------------------------------------------------------------------
1002
# Function        : CreateBranch
1003
#
1004
# Description     : Branch a workspace and then switch to the new branch
1005
#
1006
# Inputs          :
1007
#
1008
# Returns         :
1009
#
1010
sub CreateBranch
1011
{
1012
    my $opt_path;
1013
    my $opt_comment;
1014
    my $opt_switch = 1;
1015
    my $opt_branch;
385 dpurdie 1016
 
2048 dpurdie 1017
    #
1018
    #   Parse more options
1019
    #
1020
    GetOptions (
1021
                "help:+"        => \$opt_help,
1022
                "manual:3"      => \$opt_help,
1023
                "path:s"        => \$opt_path,
1024
                "switch!"       => \$opt_switch,
1025
                "comment:s"     => \$opt_comment,
1026
                ) || Error ("Invalid command line" );
1027
 
1028
    #
1029
    #   Subcommand specific help
1030
    #
1031
    SubCommandHelp( $opt_help, "Create Branch") if ($opt_help);
1032
 
1033
    #
1034
    #   Sanity Tests
1035
    #
1036
    Message ("Create Workspace Branch" );
1037
    Error ("Too many arguments: @ARGV") if ( $#ARGV > 0 );
1038
    Error ("Not enough arguments. No branch name specified") if ( $#ARGV < 0 );
1039
 
1040
    #
1041
    #   Sanity test the label
1042
    #
1043
    $opt_branch = SvnIsaSimpleLabel ($ARGV[0] );
1044
 
1045
    #
1046
    #   Do all the hard work
1047
    #
1048
    $opt_path = '.' unless ( defined $opt_path );
1049
    my $uref = NewSessionByWS($opt_path, 0, 1);
1050
    my $ws_root = $uref->SvnLocateWsRoot(1);
1051
    my $ws_url = $uref->Full();
1052
 
1053
    #
1054
    #   Use the verion of the branch that has been committed as the base of the
1055
    #   copy. If the user has modified files, then they won't be commited
1056
    #
1057
    #   This operation will be server-side only
1058
    #
1059
    Message ("Creating branch: $opt_branch");
1060
    my $repoLink = $uref->{InfoWs}{URL} . '@' . $uref->{InfoWs}{Revision};
1061
    $uref->{DEVBRANCH} =  join ('/', 'branches', $opt_branch);
1062
    my $branch_tag = $uref->SvnCopy (
1063
                'old' => $repoLink,
1064
                'new' => join ('/', $ws_url, $uref->{DEVBRANCH} ),
1065
                'comment' => $opt_comment ? $opt_comment : 'Created by Jats svn branch',
1066
                'replace' => 0,
1067
                );
1068
 
2053 dpurdie 1069
 
2048 dpurdie 1070
    if ( $opt_switch )
1071
    {
1072
        Verbose ("Switching to new branch: $opt_branch");
1073
        $branch_tag = SvnPath2Url($branch_tag);
2053 dpurdie 1074
        chdir ($ws_root) || Error ("Cannot cd to: " .$ws_root);
1075
        $uref->SvnSwitch ($branch_tag, $opt_path, '--Print', '--KeepWs' );
2048 dpurdie 1076
    }
1077
    else
1078
    {
1079
        Warning ("Using existing workspace, not the created branch");
1080
    }
1081
    Message ("Repository Ref: " . $uref->RmRef);
1082
    Message ("Vcs Tag       : " . $uref->SvnTag);
1083
 
1084
#    #
1085
#    #   The copy operation *should* be a server side operation only
1086
#    #   If the user has commited changes, but not yet updated the local
1087
#    #   workspace, then subversion will do a client side copy
1088
#    #   This is not good.
1089
#    #
1090
#    $uref->SvnCopyWs (
1091
#                   target => join ('/', $ws_url, 'branches', $opt_branch),
1092
#                   'allowLocalMods' => 1,
1093
#                   'noupdatecheck' => 1,
1094
#                   'noswitch' => ! $opt_switch,
1095
#                   'replace' => 0,
1096
#                   'comment' => $opt_comment ? $opt_comment : 'Created by Jats svn branch',
1097
#                   );
1098
#
1099
#    Message ("Repository Ref: " . $uref->RmRef);
1100
#    Message ("Vcs Tag       : " . $uref->SvnTag);
1101
 
1102
    $opr_done = 1;
1103
}
1104
 
385 dpurdie 1105
#-------------------------------------------------------------------------------
2048 dpurdie 1106
# Function        : SwitchBranch
1107
#
1108
# Description     : Switch to a specified branch
1109
#
1110
# Inputs          :
1111
#
1112
# Returns         :
1113
#
1114
sub SwitchBranch
1115
{
1116
    my $opt_path = '.';
1117
    my $opt_branch;
1118
 
1119
    #
1120
    #   Parse more options
1121
    #
1122
    GetOptions (
1123
                "help:+"        => \$opt_help,
1124
                "manual:3"      => \$opt_help,
1125
                "path:s"        => \$opt_path,
1126
                ) || Error ("Invalid command line" );
1127
 
1128
    #
1129
    #   Subcommand specific help
1130
    #
1131
    SubCommandHelp( $opt_help, "Switch Branch") if ($opt_help);
1132
    return ShowBranches($opt_path) if ( $#ARGV < 0 );
1133
 
1134
    #
1135
    #   Sanity Tests
1136
    #
1137
    Error ("Too many arguments: @ARGV") if ( $#ARGV > 0 );
1138
 
1139
    #
1140
    #   Calculate the target name
1141
    #       trunk is special
1142
    #       tags/... is special
1143
    $opt_branch = $ARGV[0];
1144
    if ( $opt_branch eq 'trunk' ) {
1145
    } elsif ( $opt_branch =~ m~tags/.+~ ) {
1146
    } else {
1147
        $opt_branch = join ('/', 'branches', $opt_branch);
1148
    }
1149
    Message ("Switching to new branch: $opt_branch");
1150
 
1151
    #
1152
    #   Do all the hard work
1153
    #
1154
    my $uref = NewSessionByWS($opt_path, 0, 1);
2053 dpurdie 1155
    my $ws_root = $uref->SvnLocateWsRoot(1);
2048 dpurdie 1156
    my $ws_url = $uref->Full();
1157
    my $branch_tag = join ('/', $ws_url, $opt_branch);
1158
 
1159
    #
1160
    #   Validate the branch
1161
    #
1162
    $uref->SvnValidateTarget (
1163
                        'cmd'    => 'svn switch',
1164
                        'target' => $branch_tag,
1165
                        'require' => 1,
1166
                        );
1167
 
2053 dpurdie 1168
    #
1169
    #   Must Change directory before we switch
1170
    #   Otherwise we will import chnages into the wrong place
1171
    #
1172
    chdir ($ws_root) || Error ("Cannot cd to: " . $ws_root);
1173
    $uref->SvnSwitch ($branch_tag, $opt_path, '--Print', '--KeepWs' );
2048 dpurdie 1174
    $opr_done = 1;
1175
}
1176
 
1177
#-------------------------------------------------------------------------------
1178
# Function        : ShowBranches
1179
#
1180
# Description     : Show branches in current workspace
1181
#                   Internal use only
1182
#
1183
# Inputs          : $opt_path           - Optional path
1184
#
1185
# Returns         :
1186
#
1187
sub ShowBranches
1188
{
1189
    my ($opt_path) = @_;
1190
 
1191
    my $uref = NewSessionByWS($opt_path, 0, 1);
1192
    my $ws_url = $uref->Full();
1193
 
1194
    #
1195
    #   Display the packages full URL - allow the user to manuallu look at more
1196
    #   List the bracnhes
1197
    #
1198
    Message ("Url: $ws_url", 'Available Branches');
1199
    SvnUserCmd( 'ls', join ('/', $ws_url, 'branches'), { 'credentials' => 1 });
1200
    $opr_done = 1;
1201
}
1202
#-------------------------------------------------------------------------------
311 dpurdie 1203
# Function        : SubCommandHelp
1204
#
1205
# Description     : Provide help on a subcommand
1206
#
1207
# Inputs          : $help_level             - Help Level 1,2,3
1208
#                   $topic                  - Topic Name
1209
#
1210
# Returns         : This function does not return
1211
#
1212
sub SubCommandHelp
1213
{
1214
    my ($help_level, $topic) = @_;
1215
    my @sections;
1216
    #
1217
    #   Spell out the section we want to display
1218
    #
1219
    #   Note:
1220
    #   Due to bug in pod2usage can't use 'head1' by itself
1221
    #   Each one needs a subsection.
1222
    #
1223
    push @sections, qw( NAME SYNOPSIS ) ;
1224
    push @sections, qw( ARGUMENTS OPTIONS ) if ( $help_level > 1 );
1225
    push @sections, qw( DESCRIPTION )       if ( $help_level > 2 );
1226
 
1227
    #
1228
    #   Extract section from the POD
1229
    #
1230
    pod2usage({-verbose => 99,
1231
               -noperldoc => 1,
1232
               -sections => $topic . '/' . join('|', @sections) } );
1233
}
1234
 
1235
#-------------------------------------------------------------------------------
1236
#   Documentation
1237
#   NOTE
1238
#
1239
#   Each subcommand MUST have
1240
#   head1 section as used by the subcommand
1241
#       This should be empty, as the contents will NOT be displayed
1242
#   head2 sections called
1243
#       NAME SYNOPSIS ARGUMENTS OPTIONS DESCRIPTION
1244
#
1245
#=head1 xxxxxx
1246
#=head2 NAME
1247
#=head2 SYNOPSIS
1248
#=head2 ARGUMENTS
1249
#=head2 OPTIONS
1250
#=head2 DESCRIPTION
1251
#
1252
 
1253
=pod
1254
 
361 dpurdie 1255
=for htmltoc    GENERAL::Subversion::
1256
 
311 dpurdie 1257
=head1 NAME
1258
 
1259
jats svn - Miscellaneous SubVersion Operations
1260
 
1261
=head1 SYNOPSIS
1262
 
1263
jats svn [options] command [command options]
1264
 
1265
 Options:
1266
    -help[=n]              - Help message, [n=1,2,3]
1267
    -man                   - Full documentation [-help=3]
1268
    -verbose[=n]           - Verbose command operation
1269
 
1270
 Common Command Options:
1271
    All command support suboptions to provide command specific help
1272
 
1273
    -help[=n]              - Help message, [n=1,2,3]
1274
    -man                   - Full documentation [-help=3]
1275
 
1276
 Commands are:
363 dpurdie 1277
    test                   - Test access to subversion
369 dpurdie 1278
    paths                  - Display Subversion tag to URL conversions
311 dpurdie 1279
    ls URL                 - List Repo contents for URL
369 dpurdie 1280
    tag [URL]              - Convert URL or Path to a Release Manager Tag
1281
    url [TAG]              - Convert TAG or Path to a Subversion URL
2048 dpurdie 1282
    create-package URL     - Create a new package at URL
311 dpurdie 1283
    delete-package URL     - Delete Package Subtree
2048 dpurdie 1284
    branch BRANCH          - Create a Development Branch
1285
    switch [BRANCH]        - Switch to a Development Branch
385 dpurdie 1286
    delete-branch          - Delete a Development Branch
311 dpurdie 1287
    import URL             - Import files to package at URL
1288
 
1289
 Use the command
1290
    jats svn command -h
1291
 for command specific help
1292
 
1293
=head1 OPTIONS
1294
 
1295
=over
1296
 
1297
=item B<-help[=n]>
1298
 
1299
Print a help message and exit. The level of help may be either 1, 2 or
1300
3 for a full manual.
1301
 
1302
This option may be specified multiple times to increment the help level, or
1303
the help level may be directly specified as a number.
1304
 
1305
=item B<-man>
1306
 
1307
This is the same as '-help=3'.
1308
The complete help is produced in a man page format.
1309
 
2071 dpurdie 1310
=item B<-verbose[=n]>
311 dpurdie 1311
 
1312
This option will increase the level of verbosity of the commands.
1313
 
1314
If an argument is provided, then it will be used to set the level, otherwise the
1315
existing level will be incremented. This option may be specified multiple times.
1316
 
1317
=back
1318
 
1319
=head1 DESCRIPTION
1320
 
1321
This program provides a number of useful Subversion based operations.
1322
 
363 dpurdie 1323
=head1 Test Subversion
1324
 
1325
=head2 NAME
1326
 
1327
Test Subversion
1328
 
1329
=head2 SYNOPSIS
1330
 
1331
    jats svn test
1332
 
1333
=head2 DESCRIPTION
1334
 
1335
This command will ensure that the subversion command line utility can be
1336
located. The command will report the version of the svn client found.
1337
 
369 dpurdie 1338
=head1 Subversion Paths
1339
 
1340
=head2 NAME
1341
 
1342
Subversion Paths
1343
 
1344
=head2 SYNOPSIS
1345
 
1346
    jats svn paths
1347
 
1348
=head2 DESCRIPTION
1349
 
1350
This command will display the base Tags and associated URLs that are used by
1351
JATS to convert a 'Subversion Tag' into a full URLs that will be used to access
1352
a physical repository.
1353
 
1354
The 'Tags' configuration is site-specific.
1355
 
311 dpurdie 1356
=head1 List Repository
1357
 
363 dpurdie 1358
=head2 NAME
1359
 
1360
List Repository
1361
 
1362
=head2 SYNOPSIS
1363
 
1364
    jats svn ls <URL>
1365
 
1366
=head2 DESCRIPTION
1367
 
311 dpurdie 1368
This command will take a URL and perform a 'svn' list operation. The URL will
1369
be expanded to include the site specific repository.
1370
 
369 dpurdie 1371
=head1 Url to Tag
1372
 
1373
=head2 NAME
1374
 
1375
Url to Tag
1376
 
1377
=head2 SYNOPSIS
1378
 
1379
    jats svn tag [Option] [tag]
1380
 
1381
 Options:
1382
    -help[=n]              - Help message, [n=1,2,3]
1383
    -man                   - Full documentation [-help=3]
1384
    -path=path             - Convert specified path
1385
    -url=url               - Convert specified URL
1386
 
1387
=head2 DESCRIPTION
1388
 
1389
This command will convert a URL or a PATH to a Subversion Tag that can
1390
be used within the remainder of the build system. If no PATH or URL is provided,
1391
then the command uses a path of the current directory.
1392
 
1393
The command will convert either a PATH or a URL. It will not do both.
1394
 
1395
The command will use the configured Subversion URL prefixes to create the Tag.
1396
 
1397
If a PATH is to be converted, then the PATH must address a Subversion workspace.
1398
The conversion will return a Tag to the root of the Workspace and Peg it to
1399
the last committed version. The command will not determine if the workspace
1400
contains modified files.
1401
 
1402
If a URL is to be converted, then the resultant value should be used with
1403
caution. The result is only as good as the provided URL and may not address
1404
the root of a package.
1405
 
1406
=head1 Tag to Url
1407
 
1408
=head2 NAME
1409
 
1410
Tag to Url
1411
 
1412
=head2 SYNOPSIS
1413
 
1414
    jats svn url [Option] [url]
1415
 
1416
 Options:
1417
    -help[=n]              - Help message, [n=1,2,3]
1418
    -man                   - Full documentation [-help=3]
1419
    -path=path             - Convert specified path
1420
    -url=url               - Convert specified URL
1421
 
1422
=head2 DESCRIPTION
1423
 
1424
This command will convert a TAG or a PATH to a full URL that can be used
1425
directly by Subversion. If no PATH or TAG is provided, then the command uses a
1426
path of the current directory.
1427
 
2424 dpurdie 1428
The command will convert either a TAG or a PATH. It will not do both.
369 dpurdie 1429
 
1430
The command will use the configured Subversion URL prefixes to expand the TAG.
1431
 
1432
If a PATH is to be converted, then the PATH must address a Subversion workspace.
1433
The conversion will return a URL to the root of the Workspace and Peg it to
1434
the last committed version. The command will not determine if the workspace
1435
contains modified files.
1436
 
1437
If a TAG is to be converted, then the resultant value should be used with
1438
caution. The result is only as good as the provided URL and may not address
1439
the root of a package.
1440
 
2424 dpurdie 1441
=head3 Examples
1442
 
1443
To display the URL of the current workspace
1444
 
1445
    jats svn url
1446
 
1447
To display the URL of a known workspace
1448
 
1449
    jats svn url -path=myWorkSpace
1450
 
1451
To convert a TAG from Release Manager or other JATS commands
1452
 
1453
    jats svn url AUPERASVN01/COTS
1454
    jats svn url SVN::AUPERASVN01/COTS/bouncycastle/trunk::bouncycastle_1.3.1.cots@502
1455
 
2048 dpurdie 1456
=head1 Create a Package Version
1457
 
1458
=head2 NAME
1459
 
1460
Create a Package Version
1461
 
1462
=head2 SYNOPSIS
1463
 
1464
jats svn [options] create-package URL [command options]
1465
 
1466
 Options:
1467
    -help[=n]               - Help message, [n=1,2,3]
1468
    -man                    - Full documentation [-help=3]
1469
    -verbose[=n]            - Verbose command operation
1470
 
1471
 Command Options
1472
    -help[=n]               - Provide command specific help
1473
    -new                    - Package must not exist
1474
    -replace                - Replace any existing versions
2354 dpurdie 1475
    -import=path            - Import directory tree
2048 dpurdie 1476
    -label=nnn              - Label imported package
1477
    -trunk                  - Import to trunk (default)
1478
    -tags=nnn               - Import to tags
1479
    -branch=nnn             - Import to branches
1480
 
1481
=head2 ARGUMENTS
1482
 
1483
The command takes one argument: The URL of the desired package.
1484
This may be be:
1485
 
1486
=over
1487
 
1488
=item * A full URL
1489
 
1490
Complete with protocol and path information.
1491
 
1492
=item * A simple URL
1493
 
1494
JATS will prepend the site-specific repository location to the user provided URL
1495
 
1496
=back
1497
 
1498
=head2 OPTIONS
1499
 
1500
=over
1501
 
1502
=item -help[=n]
1503
 
1504
Print a help message and exit. The level of help may be either 1, 2 or 3.
1505
 
1506
This option may be specified multiple times to increment the help level, or
1507
the help level may be directly specified as a number.
1508
 
1509
=item -new
1510
 
1511
This option specifies that the named package MUST not exist at all.
1512
 
1513
=item -replace
1514
 
1515
This option allows the program to replace any existing versions of the
1516
imported source. It will allow the deletion of any existing trunk, tags or
1517
branches.
1518
 
2354 dpurdie 1519
=item -import=path
2048 dpurdie 1520
 
1521
This option specifies the path of a subdirectory tree to import into the newly
1522
created package. In not provided, then only a package skeleton will be created.
1523
 
2354 dpurdie 1524
All files and directories below, but not including, the named path will be
1525
imported into the package.
1526
 
2048 dpurdie 1527
=item -label=nnn
1528
 
1529
This option specifies a label to place the imported source.
1530
 
1531
=item -trunk
1532
 
1533
This option specifies that imported source will be placed on the trunk of the
1534
package. This is the default mode of import.
1535
 
1536
The options -trunk, -tags and -branch are mutually exclusive.
1537
 
1538
=item -tags=nnn
1539
 
1540
This option specifies that imported source will be placed directly on the
1541
named tag of the package.
1542
 
1543
The options -trunk, -tags and -branch are mutually exclusive.
1544
 
1545
=item -branch=nnn
1546
 
1547
This option specifies that imported source will be placed directly on the
1548
named branch of the package.
1549
 
1550
The options -trunk, -tags and -branch are mutually exclusive.
1551
 
1552
=back
1553
 
1554
=head2 DESCRIPTION
1555
 
1556
This command will create a new package within a repository. It will ensure
1557
that the package contains the three required subdirectories: trunk, tags and
1558
branches.
1559
 
1560
The command will also ensure that packages are not placed at inappropriate
1561
locations within the repository. It is not correct to place a package within
1562
another package.
1563
 
1564
The command will, optionally, import a directory tree into the repository and,
1565
optionally, label the package.
1566
 
1567
The package body may be imported to the 'trunk' or to a branch or a tag.
1568
By default the data will be imported to the trunk and may be labeled (tagged).
1569
 
1570
Options allow the targets to be deleted if they exist or to ensure that they
1571
are not present.
1572
 
1573
The command does not attempt to merge file versions within the repository. It
1574
may result in multiple instances of a file within the repository. Use only for
1575
simple imports. Use the 'import' command for more sophisticated import requirements.
1576
 
2354 dpurdie 1577
=head3 Examples
1578
 
1579
To create a package skeleton in the Perth MREF_Package repository for a package
1580
called 'VIXmyPackage':
1581
 
1582
    jats svn create-package AUPERASVN01/MREF_Package/VIXmyPackage
1583
 
1584
To create a package skeleton in the Perth MREF_Package repository, import code
1585
into the trunk of the package and label (tag) it:
1586
 
1587
    jats svn create-package \
1588
           AUPERASVN01/MREF_Package/VIXmyPackage \
1589
           -import=VIXmyNewPackage \
1590
           -label=VIXmyPackage.WIP
1591
 
311 dpurdie 1592
=head1 Delete a Package
1593
 
1594
=head2 NAME
1595
 
1596
Delete a Package
1597
 
1598
=head2 SYNOPSIS
1599
 
1600
jats svn delete-package URL [options]
1601
 
1602
 Options:
1603
    -help[=n]              - Help message, [n=1,2,3]
1604
    -man                   - Full documentation [-help=3]
1605
    -verbose[=n]           - Verbose command operation
1606
 
1607
=head2 ARGUMENTS
1608
 
1609
The command takes one argument: The URL of the desired package.
1610
This may be be:
1611
 
1612
=over
1613
 
1614
=item * A full URL
1615
 
1616
Complete with protocol and path information.
1617
 
1618
=item * A simple URL
1619
 
1620
JATS will prepend the site-specific repository location to the user provided URL
1621
 
1622
=back
1623
 
1624
=head2 OPTIONS
1625
 
1626
This command has no significant options, other than the general help options.
1627
 
1628
=head2 DESCRIPTION
1629
 
1630
This command will delete a package from the repository. It will ensure
1631
that the package is a valid package, before it is deleted.
1632
 
1633
The command is intended to be used by test scripts, rather than users.
1634
 
2048 dpurdie 1635
=head1 Create Branch
385 dpurdie 1636
 
1637
=head2 NAME
1638
 
2048 dpurdie 1639
Create a Workspace Branch
385 dpurdie 1640
 
1641
=head2 SYNOPSIS
1642
 
2048 dpurdie 1643
jats svn branch branch-name [options]
385 dpurdie 1644
 
1645
 Options:
1646
    -help[=n]              - Help message, [n=1,2,3]
1647
    -man                   - Full documentation [-help=3]
1648
    -verbose[=n]           - Verbose command operation
1649
    -path=path             - Target workspace
2048 dpurdie 1650
    -[no]switch            - Switch to new branch(default)
1651
    -comment=text          - Comment to apply to the new branch
385 dpurdie 1652
 
1653
=head2 ARGUMENTS
1654
 
2048 dpurdie 1655
The command takes one argument. The name of the branch to be created.
385 dpurdie 1656
 
1657
=head2 OPTIONS
1658
 
1659
=over
1660
 
1661
=item B<-path=path>
1662
 
1663
This options specifies the path of the target workspace. If not provided the
1664
command will use the current directory.
1665
 
2048 dpurdie 1666
=item B<-[no]switch>
1667
 
1668
If enabled (the default) the workspace will be switched to the new branch at
1669
the end of the process.
1670
 
1671
=item B<-comment=text>
1672
 
1673
If present, the specified text will be used as a Subversion comment when the
1674
branch is created.
1675
 
1676
If not provided, then JATS will provide a basic comment.
1677
 
385 dpurdie 1678
=back
1679
 
1680
=head2 DESCRIPTION
1681
 
2048 dpurdie 1682
This command will create a named branch associated with the workspace in the
1683
specified path. It is intended to simplify the creation of Private or
385 dpurdie 1684
Development branches.
1685
 
2048 dpurdie 1686
If the named branch already exists, then the command will fail.
385 dpurdie 1687
 
2048 dpurdie 1688
The command performs a server-side copy. It will not commit any locally
1689
modified files. Nor will it inform you if there are any.
311 dpurdie 1690
 
2048 dpurdie 1691
By default, the user is 'switched' to the newly created branch.
1692
 
1693
=head1 Switch Branch
1694
 
311 dpurdie 1695
=head2 NAME
1696
 
2048 dpurdie 1697
Switch a Workspace Branch
311 dpurdie 1698
 
1699
=head2 SYNOPSIS
1700
 
2048 dpurdie 1701
jats svn switch [branch-name] [options]
311 dpurdie 1702
 
1703
 Options:
2048 dpurdie 1704
    -help[=n]              - Help message, [n=1,2,3]
1705
    -man                   - Full documentation [-help=3]
1706
    -verbose[=n]           - Verbose command operation
1707
    -path=path             - Target workspace
311 dpurdie 1708
 
1709
=head2 ARGUMENTS
1710
 
2048 dpurdie 1711
The command takes one optional argument. The name of the target branch.
311 dpurdie 1712
 
2048 dpurdie 1713
=head2 OPTIONS
1714
 
311 dpurdie 1715
=over
1716
 
2048 dpurdie 1717
=item B<-path=path>
311 dpurdie 1718
 
2048 dpurdie 1719
This options specifies the path of the target workspace. If not provided the
1720
command will use the current directory.
311 dpurdie 1721
 
2048 dpurdie 1722
=back
311 dpurdie 1723
 
2048 dpurdie 1724
=head2 DESCRIPTION
311 dpurdie 1725
 
2048 dpurdie 1726
This command will switch the users workspace to the named branch. This is
1727
identical to the Subversion switch command, except it is easier to user and
1728
has several validity checks and other enhancements.
311 dpurdie 1729
 
2048 dpurdie 1730
The command has two modes of operation:
311 dpurdie 1731
 
2048 dpurdie 1732
=over 4
311 dpurdie 1733
 
2048 dpurdie 1734
=item   1. Display a list of branched in the current package.
311 dpurdie 1735
 
2048 dpurdie 1736
If no branch is specified, then the utility will display a list of branches in
1737
the packages 'branches' directory.
311 dpurdie 1738
 
2048 dpurdie 1739
=item   2. Switch to the named branch.
311 dpurdie 1740
 
2048 dpurdie 1741
The named branch must exists otherwise the command will fail.
311 dpurdie 1742
 
2354 dpurdie 1743
There are two special variants of the branch name:
311 dpurdie 1744
 
2048 dpurdie 1745
=over 4
311 dpurdie 1746
 
2048 dpurdie 1747
=item trunk
311 dpurdie 1748
 
2048 dpurdie 1749
If the branch is named 'trunk' then it will refer to the packages truck
1356 dpurdie 1750
 
2048 dpurdie 1751
=item tags
1356 dpurdie 1752
 
2048 dpurdie 1753
If the branch name starts with 'tags/', then the command will refer to
1754
a tag within the package and not a branch.
1356 dpurdie 1755
 
2048 dpurdie 1756
=back
1356 dpurdie 1757
 
2048 dpurdie 1758
The command will add and remove unmodified files from the workspace during this
1759
operation.
311 dpurdie 1760
 
2048 dpurdie 1761
=back
311 dpurdie 1762
 
2048 dpurdie 1763
=head3 Examples
311 dpurdie 1764
 
2048 dpurdie 1765
To switch to the packages trunk
311 dpurdie 1766
 
2048 dpurdie 1767
    jats svn switch trunk
311 dpurdie 1768
 
2048 dpurdie 1769
To switch to the a branch called MyBranch
311 dpurdie 1770
 
2048 dpurdie 1771
    jats svn switch MyBranch
311 dpurdie 1772
 
2048 dpurdie 1773
To switch to a tagged version of the package
311 dpurdie 1774
 
2048 dpurdie 1775
    jats svn switch tags/MyPackage_1.0.0000.cr
311 dpurdie 1776
 
2048 dpurdie 1777
To display a list of available branches (not tags)
311 dpurdie 1778
 
2048 dpurdie 1779
    jats svn switch
311 dpurdie 1780
 
2048 dpurdie 1781
=head1 Delete Branch
311 dpurdie 1782
 
2048 dpurdie 1783
=head2 NAME
311 dpurdie 1784
 
2048 dpurdie 1785
Delete the Workspace Branch
311 dpurdie 1786
 
2048 dpurdie 1787
=head2 SYNOPSIS
311 dpurdie 1788
 
2071 dpurdie 1789
jats svn delete-branch [options] [branch-list]
311 dpurdie 1790
 
2048 dpurdie 1791
 Options:
1792
    -help[=n]              - Help message, [n=1,2,3]
1793
    -man                   - Full documentation [-help=3]
1794
    -verbose[=n]           - Verbose command operation
1795
    -path=path             - Target workspace
311 dpurdie 1796
 
2048 dpurdie 1797
=head2 ARGUMENTS
1798
 
2354 dpurdie 1799
The command may take zero or more arguments. If provided the arguments will be
2071 dpurdie 1800
branch names to be deleted.
2048 dpurdie 1801
 
1802
=head2 OPTIONS
1803
 
1804
=over
1805
 
1806
=item B<-path=path>
1807
 
1808
This options specifies the path of the target workspace. If not provided the
1809
command will use the current directory.
1810
 
1811
=back
1812
 
1813
=head2 DESCRIPTION
1814
 
2071 dpurdie 1815
This command can display the branch associated with the workspace or it can
1816
delete one or more branches. It is intended to simplify the deletion of Private
1817
or Development branches.
2048 dpurdie 1818
 
2071 dpurdie 1819
=over 4
1820
 
1821
=item 1 Arguments are provided
1822
 
1823
The command will delete all the named branches. If a named branch does not exist
1824
then the command will issue a warning message.
1825
 
1826
=item 2 No arguments provided
1827
 
1828
The command will display the branch associated with the workspace
1829
 
2048 dpurdie 1830
If the workspace is not linked to a 'branch' then the command will fail.
1831
 
2071 dpurdie 1832
=back
1833
 
311 dpurdie 1834
=head1 Import directory to a Package
1835
 
1836
=head2 NAME
1837
 
1838
Import directory to a Package
1839
 
1840
=head2 SYNOPSIS
1841
 
1842
jats svn [options] import URL [command options]
1843
 
1844
 Options:
1845
    -help[=n]               - Help message, [n=1,2,3]
1846
    -man                    - Full documentation [-help=3]
1847
    -verbose[=n]            - Verbose command operation
1848
 
1849
 Command Options
1850
    -help[=n]               - Command specific help, [n=1,2,3]
1851
    -verbose[=n]            - Verbose operation
1852
    -package=name           - Name of source package
1853
    -dir=path               - Path to new version
379 dpurdie 1854
    -label=label            - Label the result
1855
    -branch=branchName      - Base import on a branch
311 dpurdie 1856
    -replace                - Allow the label to be replaced
1857
    -reuse                  - Reuse the import directory
1858
    -workspace=path         - Path and name of alternate workspace
1859
    -[no]delete             - Deletes workspace after use. Default:yes
379 dpurdie 1860
    -author=name            - Force author of changes
1861
    -date=dateString        - Force date of changes
1862
    -log=text               - Append text to the commit message
1863
    -datafile=path          - Export tag data for automation
2424 dpurdie 1864
    -[no]commit             - Prevent chnages being commited. Default:Yes
1865
    -printfiles=n           - Control commit verbosity
311 dpurdie 1866
 
1867
=head2 ARGUMENTS
1868
 
1869
The command takes one argument: The URL of the desired package.
1870
This may be be:
1871
 
1872
=over
1873
 
1874
=item * A full URL
1875
 
1876
Complete with protocol and path information.
1877
 
1878
=item * A simple URL
1879
 
1880
JATS will prepend the site-specific repository location to the user provided URL
1881
 
1882
=back
1883
 
1884
=head2 OPTIONS
1885
 
1886
=over
1887
 
1888
=item -help[=n]
1889
 
1890
Print a help message and exit. The level of help may be either 1, 2 or 3.
1891
 
1892
This option may be specified multiple times to increment the help level, or
1893
the help level may be directly specified as a number.
1894
 
1895
=item -verbose[=n]
1896
 
1897
This option will increase the level of verbosity of the utility.
1898
 
1899
If an argument is provided, then it will be used to set the level, otherwise the
1900
existing level will be incremented. This option may be specified multiple times.
1901
 
1902
=item -package=name
1903
 
1904
Either this option or a bare URL on the command line must be provided. It
1905
specifies the repository and package to be used as a basis for the work.
1906
 
1907
=item -dir=path
1908
 
1909
This option is mandatory. It specifies the path to a local directory that
1910
contains a version of the software to be checked in.
1911
 
1912
=item -label=name
1913
 
1914
The resulting software version will be labeled with this tag, if it is provided.
1915
 
383 dpurdie 1916
A label name of TIMESTAMP will be treated in special manner. The name will be
1917
replaced with a unique name based on the users name and the current date time.
1918
 
379 dpurdie 1919
=item -branch=branchName
1920
 
1921
This option will cause the importation to be referenced to the named branch.
1922
If the branch does not exist it will be created. If it does exist then it will
1923
be used.
1924
 
1925
If this option is not specified, then the importation will be based on the 'trunk'.
1926
 
1927
If the Workspace is provided, then it will be used independently of this option.
1928
 
383 dpurdie 1929
A branchName of TIMESTAMP will be treated in special manner. The name will be
1930
replaced with a unique name based on the users name and the current date time.
1931
 
311 dpurdie 1932
=item -replace
1933
 
1934
This option, if provided, allows the label to be replaced.
1935
 
1936
=item -reuse
1937
 
1938
This option can be used to speed the creation of multiple versions in a scripted
1939
environment. The option allows the utility to reuse the workspace if it exists.
1940
 
1941
=item -workspace=path
1942
 
1943
This option specifies an alternate workspace directory to create and use. The
1944
default directory is "SvnImportDir" within the users current directory.
1945
 
1946
=item [no]delete
1947
 
341 dpurdie 1948
This option control the deletion of the workspace directory. By default the
311 dpurdie 1949
directory will be deleted, unless re-use is also used.
1950
 
379 dpurdie 1951
=item -author=name
1952
 
1953
This option will force the author of changes as recorded in the repository.
385 dpurdie 1954
The repository must be configured to allow such changes.
379 dpurdie 1955
 
1956
This option may not work for non-admin users.
1957
 
1958
=item -date=dateString
1959
 
1960
This option will force the date of the changes as recorded in the repository.
385 dpurdie 1961
The repository must be configured to allow such changes.
379 dpurdie 1962
The dateString is in a restricted ISO 8601 format: ie 2009-02-12T00:44:04.921324Z
1963
 
1964
This option may not work for non-admin users.
1965
 
1966
=item -log=text
1967
 
1968
This option will append the specified text to the commit message.
1969
The first line of the commit message is fixed by the import tool.
1970
 
1971
=item -datafile=path
1972
 
1973
This option will cause the utility to create a data file to record the import
1974
tag. It is used for automation of the import process.
1975
 
2424 dpurdie 1976
=item -[no]commit
1977
 
1978
This option will prevent the final workspace from being committed to the
1979
Repository. This allows inspection of the results.
1980
 
1981
The default operation is to commit and label the results of the import.
1982
 
1983
=item -printfiles=n
1984
 
1985
This option controls commit verbosity. The default operation is to display
1986
the files added and removed during the commit.
1987
 
1988
Suitable numbers are: None, 0 (No Display) and 1 (Full Display).
1989
 
311 dpurdie 1990
=back
1991
 
1992
=head2 DESCRIPTION
1993
 
1994
Import a new version of a package to the trunk of the package. The utility
1995
will only import changed files so that file history is preserved within the
1996
repository.
1997
 
1998
This utility is used import software from another version control system
1999
The utility will:
2000
 
2001
=over
2002
 
361 dpurdie 2003
=item *
311 dpurdie 2004
 
361 dpurdie 2005
Create a Work Space based on the current package version
2006
 
379 dpurdie 2007
The 'trunk' of the named package will be used as the base for the workspace,
2008
unless modified with the -branch option.
311 dpurdie 2009
 
361 dpurdie 2010
=item *
311 dpurdie 2011
 
361 dpurdie 2012
Update files and directories
2013
 
311 dpurdie 2014
Determines the files and directories that have been added and deleted and
2015
update the Workspace to reflect the new structure.
2016
 
361 dpurdie 2017
=item *
311 dpurdie 2018
 
361 dpurdie 2019
Check in the new version
311 dpurdie 2020
 
361 dpurdie 2021
=item *
2022
 
2023
Label the new version
2024
 
311 dpurdie 2025
=back
2026
 
2027
=cut
2028