Code

fix documentation for git-commit --no-verify
[git.git] / git-svn.perl
index b28c5bbc7238120d1d98445f1bf0f116dd7a0b8a..56f17002d1647d5a0e0c59a78a60bd96496dcf1b 100755 (executable)
@@ -70,7 +70,7 @@ my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
        $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
        $_merge, $_strategy, $_dry_run, $_ignore_nodate, $_non_recursive,
        $_username, $_config_dir, $_no_auth_cache,
-       $_pager, $_color);
+       $_pager, $_color, $_prefix);
 my (@_branch_from, %tree_map, %users, %rusers, %equiv);
 my ($_svn_can_do_switch);
 my @repo_path_split_cache;
@@ -102,7 +102,7 @@ my %cmt_opts = ( 'edit|e' => \$_edit,
 );
 
 my %cmd = (
-       fetch => [ \&fetch, "Download new revisions from SVN",
+       fetch => [ \&cmd_fetch, "Download new revisions from SVN",
                        { 'revision|r=s' => \$_revision, %fc_opts } ],
        init => [ \&init, "Initialize a repo for tracking" .
                          " (requires URL argument)",
@@ -134,6 +134,7 @@ my %cmd = (
                         'username=s' => \$_username,
                         'config-dir=s' => \$_config_dir,
                         'no-auth-cache' => \$_no_auth_cache,
+                        'prefix=s' => \$_prefix,
                        } ],
        'multi-fetch' => [ \&multi_fetch,
                        'Fetch multiple trees (like git-svnimport)',
@@ -293,6 +294,10 @@ sub init {
        setup_git_svn();
 }
 
+sub cmd_fetch {
+       fetch_child_id($GIT_SVN, @_);
+}
+
 sub fetch {
        check_upgrade_needed();
        $SVN_URL ||= file_to_s("$GIT_SVN_DIR/info/url");
@@ -532,7 +537,7 @@ sub show_ignore {
        my $repo;
        $SVN ||= libsvn_connect($SVN_URL);
        my $r = defined $_revision ? $_revision : $SVN->get_latest_revnum;
-       libsvn_traverse_ignore(\*STDOUT, $SVN->{svn_path}, $r);
+       libsvn_traverse_ignore(\*STDOUT, '', $r);
 }
 
 sub graft_branches {
@@ -571,31 +576,29 @@ sub graft_branches {
 
 sub multi_init {
        my $url = shift;
-       $_trunk ||= 'trunk';
-       $_trunk =~ s#/+$##;
-       $url =~ s#/+$## if $url;
-       if ($_trunk !~ m#^[a-z\+]+://#) {
-               $_trunk = '/' . $_trunk if ($_trunk !~ m#^/#);
-               unless ($url) {
-                       print STDERR "E: '$_trunk' is not a complete URL ",
-                               "and a separate URL is not specified\n";
-                       exit 1;
-               }
-               $_trunk = $url . $_trunk;
+       unless (defined $_trunk || defined $_branches || defined $_tags) {
+               usage(1);
        }
-       my $ch_id;
-       if ($GIT_SVN eq 'git-svn') {
-               $ch_id = 1;
-               $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
-       }
-       init_vars();
-       unless (-d $GIT_SVN_DIR) {
-               print "GIT_SVN_ID set to 'trunk' for $_trunk\n" if $ch_id;
-               init($_trunk);
-               command_noisy('repo-config', 'svn.trunk', $_trunk);
+       if (defined $_trunk) {
+               my $trunk_url = complete_svn_url($url, $_trunk);
+               my $ch_id;
+               if ($GIT_SVN eq 'git-svn') {
+                       $ch_id = 1;
+                       $GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
+               }
+               init_vars();
+               unless (-d $GIT_SVN_DIR) {
+                       if ($ch_id) {
+                               print "GIT_SVN_ID set to 'trunk' for ",
+                                     "$trunk_url ($_trunk)\n";
+                       }
+                       init($trunk_url);
+                       command_noisy('repo-config', 'svn.trunk', $trunk_url);
+               }
        }
-       complete_url_ls_init($url, $_branches, '--branches/-b', '');
-       complete_url_ls_init($url, $_tags, '--tags/-t', 'tags/');
+       $_prefix = '' unless defined $_prefix;
+       complete_url_ls_init($url, $_branches, '--branches/-b', $_prefix);
+       complete_url_ls_init($url, $_tags, '--tags/-t', $_prefix . 'tags/');
 }
 
 sub multi_fetch {
@@ -839,7 +842,6 @@ sub fetch_child_id {
        my $ref = "$GIT_DIR/refs/remotes/$id";
        defined(my $pid = open my $fh, '-|') or croak $!;
        if (!$pid) {
-               $_repack = undef;
                $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
                init_vars();
                fetch(@_);
@@ -847,7 +849,7 @@ sub fetch_child_id {
        }
        while (<$fh>) {
                print $_;
-               check_repack() if (/^r\d+ = $sha1/);
+               check_repack() if (/^r\d+ = $sha1/o);
        }
        close $fh or croak $?;
 }
@@ -872,29 +874,34 @@ sub rec_fetch {
        }
 }
 
+sub complete_svn_url {
+       my ($url, $path) = @_;
+       $path =~ s#/+$##;
+       $url =~ s#/+$## if $url;
+       if ($path !~ m#^[a-z\+]+://#) {
+               $path = '/' . $path if ($path !~ m#^/#);
+               if (!defined $url || $url !~ m#^[a-z\+]+://#) {
+                       fatal("E: '$path' is not a complete URL ",
+                             "and a separate URL is not specified\n");
+               }
+               $path = $url . $path;
+       }
+       return $path;
+}
+
 sub complete_url_ls_init {
-       my ($url, $var, $switch, $pfx) = @_;
-       unless ($var) {
+       my ($url, $path, $switch, $pfx) = @_;
+       unless ($path) {
                print STDERR "W: $switch not specified\n";
                return;
        }
-       $var =~ s#/+$##;
-       if ($var !~ m#^[a-z\+]+://#) {
-               $var = '/' . $var if ($var !~ m#^/#);
-               unless ($url) {
-                       print STDERR "E: '$var' is not a complete URL ",
-                               "and a separate URL is not specified\n";
-                       exit 1;
-               }
-               $var = $url . $var;
-       }
-       my @ls = libsvn_ls_fullurl($var);
-       my $old = $GIT_SVN;
+       my $full_url = complete_svn_url($url, $path);
+       my @ls = libsvn_ls_fullurl($full_url);
        defined(my $pid = fork) or croak $!;
        if (!$pid) {
-               foreach my $u (map { "$var/$_" } (grep m!/$!, @ls)) {
+               foreach my $u (map { "$full_url/$_" } (grep m!/$!, @ls)) {
                        $u =~ s#/+$##;
-                       if ($u !~ m!\Q$var\E/(.+)$!) {
+                       if ($u !~ m!\Q$full_url\E/(.+)$!) {
                                print STDERR "W: Unrecognized URL: $u\n";
                                die "This should never happen\n";
                        }
@@ -912,7 +919,7 @@ sub complete_url_ls_init {
        waitpid $pid, 0;
        croak $? if $?;
        my ($n) = ($switch =~ /^--(\w+)/);
-       command_noisy('repo-config', "svn.$n", $var);
+       command_noisy('repo-config', "svn.$n", $full_url);
 }
 
 sub common_prefix {
@@ -1079,7 +1086,7 @@ sub graft_merge_msg {
        my ($grafts, $l_map, $u, $p, @re) = @_;
 
        my $x = $l_map->{$u}->{$p};
-       my $rl = rev_list_raw($x);
+       my $rl = rev_list_raw("refs/remotes/$x");
        while (my $c = next_rev_list_entry($rl)) {
                foreach my $re (@re) {
                        my (@br) = ($c->{m} =~ /$re/g);
@@ -1405,7 +1412,6 @@ sub git_commit {
 
        # this output is read via pipe, do not change:
        print "r$log_msg->{revision} = $commit\n";
-       check_repack();
        return $commit;
 }