git-svn: --branch-all-refs / -B support
[git.git] / contrib / git-svn / git-svn.perl
index 8bc3d69..c91160d 100755 (executable)
@@ -33,12 +33,14 @@ use POSIX qw/strftime/;
 my $sha1 = qr/[a-f\d]{40}/;
 my $sha1_short = qr/[a-f\d]{4,40}/;
 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
-       $_find_copies_harder, $_l, $_version, $_upgrade, $_authors);
+       $_find_copies_harder, $_l, $_cp_similarity,
+       $_version, $_upgrade, $_authors, $_branch_all_refs);
 my (@_branch_from, %tree_map, %users);
 my ($_svn_co_url_revs, $_svn_pg_peg_revs);
 
 my %fc_opts = ( 'no-ignore-externals' => \$_no_ignore_ext,
                'branch|b=s' => \@_branch_from,
+               'branch-all-refs|B' => \$_branch_all_refs,
                'authors-file|A=s' => \$_authors );
 
 # yes, 'native' sets "\n".  Patches to fix this for non-*nix systems welcome:
@@ -55,6 +57,7 @@ my %cmd = (
                                'rmdir' => \$_rmdir,
                                'find-copies-harder' => \$_find_copies_harder,
                                'l=i' => \$_l,
+                               'copy-similarity|C=i'=> \$_cp_similarity,
                                %fc_opts,
                        } ],
        'show-ignore' => [ \&show_ignore, "Show svn:ignore listings", { } ],
@@ -106,6 +109,7 @@ usage(0) if $_help;
 version() if $_version;
 usage(1) unless defined $cmd;
 load_authors() if $_authors;
+load_all_refs() if $_branch_all_refs;
 svn_compat_check();
 $cmd{$cmd}->[0]->(@ARGV);
 exit 0;
@@ -309,9 +313,16 @@ sub commit {
        }
        chomp @revs;
 
-       fetch();
-       chdir $SVN_WC or croak $!;
+       chdir $SVN_WC or croak "Unable to chdir $SVN_WC: $!\n";
        my $info = svn_info('.');
+       my $fetched = fetch();
+       if ($info->{Revision} != $fetched->{revision}) {
+               print STDERR "There are new revisions that were fetched ",
+                               "and need to be merged (or acknowledged) ",
+                               "before committing.\n";
+               exit 1;
+       }
+       $info = svn_info('.');
        read_uuid($info);
        my $svn_current_rev =  $info->{'Last Changed Rev'};
        foreach my $c (@revs) {
@@ -573,7 +584,12 @@ sub svn_checkout_tree {
        my $pid = open my $diff_fh, '-|';
        defined $pid or croak $!;
        if ($pid == 0) {
-               my @diff_tree = qw(git-diff-tree -z -r -C);
+               my @diff_tree = qw(git-diff-tree -z -r);
+               if ($_cp_similarity) {
+                       push @diff_tree, "-C$_cp_similarity";
+               } else {
+                       push @diff_tree, '-C';
+               }
                push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
                push @diff_tree, "-l$_l" if defined $_l;
                exec(@diff_tree, $from, $treeish) or croak $!;
@@ -1224,6 +1240,17 @@ sub map_tree_joins {
        }
 }
 
+sub load_all_refs {
+       if (@_branch_from) {
+               print STDERR '--branch|-b parameters are ignored when ',
+                       "--branch-all-refs|-B is passed\n";
+       }
+
+       # don't worry about rev-list on non-commit objects/tags,
+       # it shouldn't blow up if a ref is a blob or tree...
+       chomp(@_branch_from = `git-rev-parse --symbolic --all`);
+}
+
 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
 sub load_authors {
        open my $authors, '<', $_authors or die "Can't open $_authors $!\n";