Subversion Repositories DevTools

Rev

Rev 369 | Rev 381 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 369 Rev 379
Line 19... Line 19...
19
use strict;
19
use strict;
20
use warnings;
20
use warnings;
21
use JatsError;
21
use JatsError;
22
use JatsSvn qw(:All);
22
use JatsSvn qw(:All);
23
use JatsLocateFiles;
23
use JatsLocateFiles;
-
 
24
use JatsProperties;
-
 
25
 
24
 
26
 
25
use Pod::Usage;                                 # required for help support
27
use Pod::Usage;                                 # required for help support
26
use Getopt::Long qw(:config require_order);     # Stop on non-option
28
use Getopt::Long qw(:config require_order);     # Stop on non-option
27
use Cwd;
29
use Cwd;
28
use File::Path;
30
use File::Path;
Line 336... Line 338...
336
#
338
#
337
# Returns         : 
339
# Returns         : 
338
#
340
#
339
sub DeletePackage
341
sub DeletePackage
340
{
342
{
-
 
343
    my $opt_error = 0;
341
    #
344
    #
342
    #   Parse more options
345
    #   Parse more options
343
    #
346
    #
344
    GetOptions (
347
    GetOptions (
345
                "help:+"        => \$opt_help,
348
                "help:+"        => \$opt_help,
346
                "manual:3"      => \$opt_help,
349
                "manual:3"      => \$opt_help,
-
 
350
                "error!"       => \$opt_error,
347
                ) || Error ("Invalid command line" );
351
                ) || Error ("Invalid command line" );
348
 
352
 
349
    #
353
    #
350
    #   Subcommand specific help
354
    #   Subcommand specific help
351
    #
355
    #
Line 362... Line 366...
362
    #       Create
366
    #       Create
363
    #       Import
367
    #       Import
364
    #       Label
368
    #       Label
365
    #
369
    #
366
    my $uref = NewSessionByUrl ( $ARGV[0] );
370
    my $uref = NewSessionByUrl ( $ARGV[0] );
367
    $uref->SvnValidatePackageRoot();
371
    $uref->SvnValidatePackageRoot(!$opt_error);
368
    $uref->SvnDelete (
372
    $uref->SvnDelete (
369
                      'target'      => $uref->Full,
373
                      'target'      => $uref->Full,
370
                      'comment'   => ['Deleted by user command','jats svn delete-package'],
374
                      'comment'   => [$uref->Path().": Delete Pakage",'Deleted by user command','jats svn delete-package'],
371
                      'noerror'     => 0,
375
                      'noerror'   => !$opt_error,
372
                      );
376
                      );
373
    $opr_done = 1;
377
    $opr_done = 1;
374
}
378
}
375
 
379
 
376
#-------------------------------------------------------------------------------
380
#-------------------------------------------------------------------------------
Line 494... Line 498...
494
    my $opt_label;
498
    my $opt_label;
495
    my $opt_replace = 0;
499
    my $opt_replace = 0;
496
    my $opt_reuse;
500
    my $opt_reuse;
497
    my $opt_workdir = "SvnImportDir";
501
    my $opt_workdir = "SvnImportDir";
498
    my $opt_delete = 1;
502
    my $opt_delete = 1;
-
 
503
    my $opt_author;
-
 
504
    my $opt_date;
-
 
505
    my $opt_log = '';
-
 
506
    my $opt_branch;
-
 
507
    my $opt_datafile;
499
 
508
 
500
    #
509
    #
501
    #   Other globals
510
    #   Other globals
502
    #
511
    #
503
    my $url_label;
512
    my $url_label;
-
 
513
    my $url_branch;
504
 
514
 
505
    #
515
    #
506
    #   Configuration options
516
    #   Configuration options
507
    #
517
    #
508
    my $result = GetOptions (
518
    my $result = GetOptions (
509
                    "help:+"        => \$opt_help,
519
                    'help:+'        => \$opt_help,
510
                    "manual:3"      => \$opt_help,
520
                    'manual:3'      => \$opt_help,
511
                    "verbose:+"     => \$opt_verbose,
521
                    'verbose:+'     => \$opt_verbose,
512
                    "package=s"     => \$opt_package,
522
                    'package=s'     => \$opt_package,
513
                    "dir=s"         => \$opt_dir,
523
                    'dir=s'         => \$opt_dir,
514
                    "label=s"       => \$opt_label,
524
                    'label=s'       => \$opt_label,
-
 
525
                    'branch=s'      => \$opt_branch,
515
                    "replace"       => \$opt_replace,
526
                    'replace'       => \$opt_replace,
516
                    "reuse"         => \$opt_reuse,
527
                    'reuse'         => \$opt_reuse,
517
                    "workspace=s"   => \$opt_workdir,
528
                    'workspace=s'   => \$opt_workdir,
518
                    "delete!"       => \$opt_delete,
529
                    'delete!'       => \$opt_delete,
-
 
530
                    'author=s'      => \$opt_author,
-
 
531
                    'date=s'        => \$opt_date,
-
 
532
                    'log=s'         => \$opt_log,
-
 
533
                    'datafile=s'    => \$opt_datafile,
519
 
534
 
520
                    #
535
                    #
521
                    #   Update documentation at the end of the file
536
                    #   Update documentation at the end of the file
522
                    #
537
                    #
523
                    ) || Error ("Invalid command line" );
538
                    ) || Error ("Invalid command line" );
Line 525... Line 540...
525
    #
540
    #
526
    #   Insert defaults
541
    #   Insert defaults
527
    #   User can specify base package via -package or a non-options argument
542
    #   User can specify base package via -package or a non-options argument
528
    #
543
    #
529
    $opt_package = $ARGV[0] unless ( $opt_package );
544
    $opt_package = $ARGV[0] unless ( $opt_package );
-
 
545
    unlink $opt_datafile if ( defined $opt_datafile );
530
                    
546
                    
531
    #
547
    #
532
    #   Subcommand specific help
548
    #   Subcommand specific help
533
    #
549
    #
534
    SubCommandHelp( $opt_help, "Import directory to a Package")
550
    SubCommandHelp( $opt_help, "Import directory to a Package")
Line 563... Line 579...
563
                        'available' => 1,
579
                        'available' => 1,
564
                        ) unless ( $opt_replace );
580
                        ) unless ( $opt_replace );
565
    }
581
    }
566
 
582
 
567
    #
583
    #
-
 
584
    #   Validate the required branch
-
 
585
    #   It will be created if it doesn't exist
-
 
586
    #
-
 
587
    if ( $opt_branch )
-
 
588
    {
-
 
589
        $opt_branch = SvnIsaSimpleLabel($opt_branch);
-
 
590
        $url_branch = $svn->BranchName( $opt_branch, 'branches' );
-
 
591
        $svn->SvnValidateTarget (
-
 
592
                        'target' => $url_branch,
-
 
593
                        'create' => 1,
-
 
594
                        );
-
 
595
    }
-
 
596
 
-
 
597
    #
568
    #   Create a workspace based on the users package
598
    #   Create a workspace based on the users package
569
    #   Allow the workspace to be reused to speed up multiple
599
    #   Allow the workspace to be reused to speed up multiple
570
    #   operations
600
    #   operations
571
    #
601
    #
572
    unless ( $opt_reuse && -d $opt_workdir )
602
    unless ( $opt_reuse && -d $opt_workdir )
Line 580... Line 610...
580
                            'cmd'    => 'SvnImporter',
610
                            'cmd'    => 'SvnImporter',
581
                            'target' => $svn->Full,
611
                            'target' => $svn->Full,
582
                            'require' => 1,
612
                            'require' => 1,
583
                            );
613
                            );
584
 
614
 
-
 
615
        my $url_co = $opt_branch ? $url_branch : $svn->Full . '/trunk';
585
        $svn->SvnCo ( $svn->Full . '/trunk', $opt_workdir );
616
        $svn->SvnCo ( $url_co, $opt_workdir );
586
        Error ("Cannot locate the created Workspace")
617
        Error ("Cannot locate the created Workspace")
587
            unless ( -d $opt_workdir );
618
            unless ( -d $opt_workdir );
588
    }
619
    }
589
    else
620
    else
590
    {
621
    {
Line 633... Line 664...
633
    #DebugDumpData( 'WS', \%ws );
664
    #DebugDumpData( 'WS', \%ws );
634
    #DebugDumpData( 'DIR', \%dir );
665
    #DebugDumpData( 'DIR', \%dir );
635
    #DebugDumpData( 'COMMON', \%common );
666
    #DebugDumpData( 'COMMON', \%common );
636
 
667
 
637
    #
668
    #
-
 
669
    #   Need to consider the case where a file has been replaced with a directory
-
 
670
    #   and visa-versa. Delete files and directories first.
-
 
671
    #
-
 
672
    #
-
 
673
    #   Remove files
-
 
674
    #   Sort in reverse. This will ensure that we process directory
-
 
675
    #   contents before directories
-
 
676
    #
-
 
677
    my @rm_files = reverse sort keys %ws;
-
 
678
    if ( @rm_files )
-
 
679
    {
-
 
680
        foreach my $file ( @rm_files  )
-
 
681
        {
-
 
682
            Verbose ("Removing $file");
-
 
683
            unlink "$opt_workdir/$file";
-
 
684
        }
-
 
685
 
-
 
686
        #
-
 
687
        #   Inform Subversion about the removed files
-
 
688
        #
-
 
689
        my $base = 0;
-
 
690
        my $num = $#rm_files;
-
 
691
        Message ("Update the workspace: Removed " . ($num + 1) . " Files");
-
 
692
 
-
 
693
        while ( $base <= $num )
-
 
694
        {
-
 
695
            my $end = $base + 200;
-
 
696
            $end = $num if ( $end > $num );
-
 
697
 
-
 
698
            $svn->SvnCmd ( 'delete', map ("$opt_workdir/$_@", @rm_files[$base .. $end] ),
-
 
699
                            { 'error' => 'Deleting files from workspace' } );
-
 
700
            
-
 
701
            $base = $end + 1;
-
 
702
        }
-
 
703
    }
-
 
704
    
-
 
705
    #
638
    #   Add New Files
706
    #   Add New Files
639
    #   Won't add empty directories at this point
707
    #   Won't add empty directories at this point
640
    #
708
    #
641
    #   Process by sorted list
709
    #   Process by sorted list
642
    #   This will ensure we process parent directories first
710
    #   This will ensure we process parent directories first
643
    #
711
    #
644
    my @added = sort keys %dir;
712
    my @added = sort keys %dir;
645
 
-
 
646
    if ( @added )
713
    if ( @added )
647
    {
714
    {
648
        foreach my $file ( @added  )
715
        foreach my $file ( @added  )
649
        {
716
        {
650
            my $src = "$opt_dir/$file";
717
            my $src = "$opt_dir/$file";
651
            my $target = "$opt_workdir/$file";
718
            my $target = "$opt_workdir/$file";
652
 
719
 
653
            if ( -d $src )
720
            if ( -d $src )
654
            {
721
            {
-
 
722
                Verbose ("Adding directory: $file");
655
                mkdir ( $target ) unless (-d $target);
723
                mkdir ( $target ) unless (-d $target);
656
            }
724
            }
657
            else
725
            else
658
            {
726
            {
659
 
727
 
Line 674... Line 742...
674
        #   time.
742
        #   time.
675
        #
743
        #
676
 
744
 
677
        my $base = 0;
745
        my $base = 0;
678
        my $num = $#added;
746
        my $num = $#added;
679
        Message ("Update the workspace: Added $num files");
747
        Message ("Update the workspace: Added " . (1 + $num) . " files");
680
 
748
 
681
        while ( $base <= $num )
749
        while ( $base <= $num )
682
        {
750
        {
683
            my $end = $base + 200;
751
            my $end = $base + 200;
684
            $end = $num if ( $end > $num );
752
            $end = $num if ( $end > $num );
685
 
753
 
686
            $svn->SvnCmd ( 'add'
754
            $svn->SvnCmd ( 'add'
687
                            , '--depth=empty'
755
                            , '--depth=empty'
688
                            , '--parents'
756
                            , '--parents'
689
                            , map ("$opt_workdir/$_", @added[$base .. $end] ),
757
                            , map ("$opt_workdir/$_@", @added[$base .. $end] ),
690
                            { 'error' => 'Adding files to workspace' } );
758
                            { 'error' => 'Adding files to workspace' } );
691
 
759
 
692
            $base = $end + 1;
760
            $base = $end + 1;
693
        }
761
        }
694
    }
762
    }
695
 
763
 
696
    #
764
    #
697
    #   Remove files
-
 
698
    #   Don't really need to delete the files as the svn delete
-
 
699
    #   command will do this too. Just do it anyway
-
 
700
    #
-
 
701
    my @rm_files = sort keys %ws;
-
 
702
    if ( @rm_files )
-
 
703
    {
-
 
704
        foreach my $file ( @rm_files  )
-
 
705
        {
-
 
706
            Verbose ("Removing $file");
-
 
707
            unlink "$opt_workdir/$file";
-
 
708
        }
-
 
709
 
-
 
710
        #
-
 
711
        #   Inform Subversion about the removed files
-
 
712
        #
-
 
713
        my $base = 0;
-
 
714
        my $num = $#rm_files;
-
 
715
        Message ("Update the workspace: Removed $num Files");
-
 
716
 
-
 
717
        while ( $base <= $num )
-
 
718
        {
-
 
719
            my $end = $base + 200;
-
 
720
            $end = $num if ( $end > $num );
-
 
721
 
-
 
722
            $svn->SvnCmd ( 'delete', map ("$opt_workdir/$_", @rm_files[$base .. $end] ),
-
 
723
                            { 'error' => 'Deleting files from workspace' } );
-
 
724
            
-
 
725
 
-
 
726
            $base = $end + 1;
-
 
727
        }
-
 
728
    }
-
 
729
 
-
 
730
    #
-
 
731
    #   The common files may have changed
765
    #   The common files may have changed
732
    #   Simply copy them all in and let subversion figure it out
766
    #   Simply copy them all in and let subversion figure it out
733
    #
767
    #
734
    foreach my $file ( sort keys %common  )
768
    foreach my $file ( sort keys %common  )
735
    {
769
    {
Line 753... Line 787...
753
    #
787
    #
754
    #   Commit the workspace
788
    #   Commit the workspace
755
    #   This will go back onto the trunk
789
    #   This will go back onto the trunk
756
    #
790
    #
757
    $svn = NewSessionByWS( $opt_workdir );
791
    $svn = NewSessionByWS( $opt_workdir );
-
 
792
    my $pkgPath = $svn->Path();
-
 
793
    my $ciComment = "$pkgPath: Checkin by Svn Import";
-
 
794
    $ciComment .= "\n" . $opt_log if ( $opt_log );
-
 
795
    $ciComment =~ s~\r\n~\n~g;
758
    $svn->SvnCi ('comment' => "Checkin by Svn Import" );
796
    $svn->SvnCi ('comment' => $ciComment, 'allowSame' => 1 );
759
    Message ("Repository Ref: " . $svn->RmRef);
797
    Message ("Repository Ref: " . $svn->RmRef);
-
 
798
    $svn->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
-
 
799
    $svn->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
760
 
800
 
761
    #
801
    #
762
    #   Label the result
802
    #   Label the result
763
    #   The workspace will have been updated, so we can use it as the base for
803
    #   The workspace will have been updated, so we can use it as the base for
764
    #   the labeling process
804
    #   the labeling process
Line 767... Line 807...
767
    {
807
    {
768
        $svn->SvnCopyWs (
808
        $svn->SvnCopyWs (
769
                       target => $url_label,
809
                       target => $url_label,
770
                       'noswitch' => 1,
810
                       'noswitch' => 1,
771
                       'replace' => $opt_replace,
811
                       'replace' => $opt_replace,
772
                       'comment' => 'Created by Jats Svn Import',
812
                       'comment' => "$pkgPath: Tagged by Jats Svn Import",
773
                       );
813
                       );
774
        Message ("Repository Ref: " . $svn->RmRef);
814
        Message ("Repository Ref: " . $svn->RmRef);
-
 
815
        $svn->setRepoProperty('svn:author', $opt_author) if (defined ($opt_author));
-
 
816
        $svn->setRepoProperty('svn:date', $opt_date) if (defined ($opt_date));
775
    }
817
    }
776
 
818
 
777
    #
819
    #
778
    #   Clean up
820
    #   Clean up
779
    #
821
    #
780
    if ( $opt_delete && ! $opt_reuse )
822
    if ( $opt_delete && ! $opt_reuse )
781
    {
823
    {
782
        Message ("Delete Workspace");
824
        Message ("Delete Workspace");
783
        rmtree( $opt_workdir );
825
        rmtree( $opt_workdir );
784
    }
826
    }
-
 
827
 
785
    
828
    #
-
 
829
    #   Automation data transfer
-
 
830
    #
-
 
831
    if ( defined $opt_datafile )
-
 
832
    {
-
 
833
        my $data = JatsProperties::New();
-
 
834
 
-
 
835
        $data->setProperty('Command'        , 'ImportPackage');
-
 
836
        $data->setProperty('Label'          , $opt_label);
-
 
837
        $data->setProperty('subversion.tag' , $svn->RmRef);
-
 
838
 
-
 
839
        $data->Dump('InfoFile') if ($opt_verbose);
-
 
840
        $data->store( $opt_datafile );
-
 
841
    }
-
 
842
 
786
    $opr_done = 1;
843
    $opr_done = 1;
787
}
844
}
788
 
845
 
789
#-------------------------------------------------------------------------------
846
#-------------------------------------------------------------------------------
790
# Function        : SubCommandHelp
847
# Function        : SubCommandHelp
Line 1205... Line 1262...
1205
 Command Options
1262
 Command Options
1206
    -help[=n]               - Command specific help, [n=1,2,3]
1263
    -help[=n]               - Command specific help, [n=1,2,3]
1207
    -verbose[=n]            - Verbose operation
1264
    -verbose[=n]            - Verbose operation
1208
    -package=name           - Name of source package
1265
    -package=name           - Name of source package
1209
    -dir=path               - Path to new version
1266
    -dir=path               - Path to new version
1210
    -label                  - Label the result
1267
    -label=label            - Label the result
-
 
1268
    -branch=branchName      - Base import on a branch
1211
    -replace                - Allow the label to be replaced
1269
    -replace                - Allow the label to be replaced
1212
    -reuse                  - Reuse the import directory
1270
    -reuse                  - Reuse the import directory
1213
    -workspace=path         - Path and name of alternate workspace
1271
    -workspace=path         - Path and name of alternate workspace
1214
    -[no]delete             - Deletes workspace after use. Default:yes
1272
    -[no]delete             - Deletes workspace after use. Default:yes
-
 
1273
    -author=name            - Force author of changes
-
 
1274
    -date=dateString        - Force date of changes
-
 
1275
    -log=text               - Append text to the commit message
-
 
1276
    -datafile=path          - Export tag data for automation
-
 
1277
 
1215
 
1278
 
1216
=head2 ARGUMENTS
1279
=head2 ARGUMENTS
1217
 
1280
 
1218
The command takes one argument: The URL of the desired package.
1281
The command takes one argument: The URL of the desired package.
1219
This may be be:
1282
This may be be:
Line 1261... Line 1324...
1261
 
1324
 
1262
=item -label=name
1325
=item -label=name
1263
 
1326
 
1264
The resulting software version will be labeled with this tag, if it is provided.
1327
The resulting software version will be labeled with this tag, if it is provided.
1265
 
1328
 
-
 
1329
=item -branch=branchName
-
 
1330
 
-
 
1331
This option will cause the importation to be referenced to the named branch.
-
 
1332
If the branch does not exist it will be created. If it does exist then it will
-
 
1333
be used.
-
 
1334
 
-
 
1335
If this option is not specified, then the importation will be based on the 'trunk'.
-
 
1336
 
-
 
1337
If the Workspace is provided, then it will be used independently of this option.
-
 
1338
 
1266
=item -replace
1339
=item -replace
1267
 
1340
 
1268
This option, if provided, allows the label to be replaced.
1341
This option, if provided, allows the label to be replaced.
1269
 
1342
 
1270
=item -reuse
1343
=item -reuse
Line 1280... Line 1353...
1280
=item [no]delete
1353
=item [no]delete
1281
 
1354
 
1282
This option control the deletion of the workspace directory. By default the
1355
This option control the deletion of the workspace directory. By default the
1283
directory will be deleted, unless re-use is also used.
1356
directory will be deleted, unless re-use is also used.
1284
 
1357
 
-
 
1358
=item -author=name
-
 
1359
 
-
 
1360
This option will force the author of changes as recorded in the repository.
-
 
1361
The repoistory must be configured to allow such changes.
-
 
1362
 
-
 
1363
This option may not work for non-admin users.
-
 
1364
 
-
 
1365
=item -date=dateString
-
 
1366
 
-
 
1367
This option will force the date of the changes as recorded in the repository.
-
 
1368
The repoistory must be configured to allow such changes.
-
 
1369
The dateString is in a restricted ISO 8601 format: ie 2009-02-12T00:44:04.921324Z
-
 
1370
 
-
 
1371
This option may not work for non-admin users.
-
 
1372
 
-
 
1373
=item -log=text
-
 
1374
 
-
 
1375
This option will append the specified text to the commit message.
-
 
1376
The first line of the commit message is fixed by the import tool.
-
 
1377
 
-
 
1378
=item -datafile=path
-
 
1379
 
-
 
1380
This option will cause the utility to create a data file to record the import
-
 
1381
tag. It is used for automation of the import process.
-
 
1382
 
1285
=back
1383
=back
1286
 
1384
 
1287
=head2 DESCRIPTION
1385
=head2 DESCRIPTION
1288
 
1386
 
1289
Import a new version of a package to the trunk of the package. The utility
1387
Import a new version of a package to the trunk of the package. The utility
Line 1297... Line 1395...
1297
 
1395
 
1298
=item *
1396
=item *
1299
 
1397
 
1300
Create a Work Space based on the current package version
1398
Create a Work Space based on the current package version
1301
 
1399
 
1302
The 'trunk' of the named package will be used as the base for the workspace.
1400
The 'trunk' of the named package will be used as the base for the workspace,
-
 
1401
unless modified with the -branch option.
1303
 
1402
 
1304
=item *
1403
=item *
1305
 
1404
 
1306
Update files and directories
1405
Update files and directories
1307
 
1406
 
Line 1316... Line 1415...
1316
 
1415
 
1317
Label the new version
1416
Label the new version
1318
 
1417
 
1319
=back
1418
=back
1320
 
1419
 
1321
The utility can optionally perform other operations including:
-
 
1322
 
-
 
1323
=over
-
 
1324
 
-
 
1325
=item *
-
 
1326
 
-
 
1327
Import directly to a branch. This does not affect the 'trunk'.
-
 
1328
 
-
 
1329
=item *
-
 
1330
 
-
 
1331
Import directly to a tag. This does not affect the 'trunk'
-
 
1332
 
-
 
1333
=back
-
 
1334
 
-
 
1335
=cut
1420
=cut
1336
 
1421