git-remote: exit with non-zero status after detecting error in "rm".
[gitweb.git] / git-svn.perl
index d162114e26d64ff6a8a63dd8ff5d795c476868d4..484b0576a8cdea3b0d2063ce73c8b8cb11a18f7c 100755 (executable)
@@ -77,11 +77,12 @@ BEGIN
                   \$Git::SVN::_repack_flags,
                %remote_opts );
 
-my ($_trunk, $_tags, $_branches);
+my ($_trunk, $_tags, $_branches, $_stdlayout);
 my %icv;
 my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared,
                   'trunk|T=s' => \$_trunk, 'tags|t=s' => \$_tags,
                   'branches|b=s' => \$_branches, 'prefix=s' => \$_prefix,
+                  'stdlayout|s' => \$_stdlayout,
                   'minimize-url|m' => \$Git::SVN::_minimize_url,
                  'no-metadata' => sub { $icv{noMetadata} = 1 },
                  'use-svm-props' => sub { $icv{useSvmProps} = 1 },
@@ -123,7 +124,8 @@ BEGIN
                        "Set an SVN repository to a git tree-ish",
                        { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ],
        'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings",
-                       { 'revision|r=i' => \$_revision } ],
+                       { 'revision|r=i' => \$_revision
+                       } ],
        'multi-fetch' => [ \&cmd_multi_fetch,
                           "Deprecated alias for $0 fetch --all",
                           { 'revision|r=s' => \$_revision, %fc_opts } ],
@@ -143,10 +145,10 @@ BEGIN
                          'non-recursive' => \$Git::SVN::Log::non_recursive,
                          'authors-file|A=s' => \$_authors,
                          'color' => \$Git::SVN::Log::color,
-                         'pager=s' => \$Git::SVN::Log::pager,
+                         'pager=s' => \$Git::SVN::Log::pager
                        } ],
        'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish",
-                       { } ],
+                       {} ],
        'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory",
                        { 'merge|m|M' => \$_merge,
                          'verbose|v' => \$_verbose,
@@ -292,7 +294,8 @@ sub init_subdir {
 sub cmd_clone {
        my ($url, $path) = @_;
        if (!defined $path &&
-           (defined $_trunk || defined $_branches || defined $_tags) &&
+           (defined $_trunk || defined $_branches || defined $_tags ||
+            defined $_stdlayout) &&
            $url !~ m#^[a-z\+]+://#) {
                $path = $url;
        }
@@ -302,6 +305,11 @@ sub cmd_clone {
 }
 
 sub cmd_init {
+       if (defined $_stdlayout) {
+               $_trunk = 'trunk' if (!defined $_trunk);
+               $_tags = 'tags' if (!defined $_tags);
+               $_branches = 'branches' if (!defined $_branches);
+       }
        if (defined $_trunk || defined $_branches || defined $_tags) {
                return cmd_multi_init(@_);
        }
@@ -370,12 +378,19 @@ sub cmd_dcommit {
        $head ||= 'HEAD';
        my @refs;
        my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
+       print "Committing to $url ...\n";
        unless ($gs) {
                die "Unable to determine upstream SVN information from ",
                    "$head history\n";
        }
        my $last_rev;
        my ($linear_refs, $parents) = linearize_history($gs, \@refs);
+       if ($_no_rebase && scalar(@$linear_refs) > 1) {
+               warn "Attempting to commit more than one change while ",
+                    "--no-rebase is enabled.\n",
+                    "If these changes depend on each other, re-running ",
+                    "without --no-rebase will be required."
+       }
        foreach my $d (@$linear_refs) {
                unless (defined $last_rev) {
                        (undef, $last_rev, undef) = cmt_metadata("$d~1");
@@ -387,6 +402,7 @@ sub cmd_dcommit {
                if ($_dry_run) {
                        print "diff-tree $d~1 $d\n";
                } else {
+                       my $cmt_rev;
                        my %ed_opts = ( r => $last_rev,
                                        log => get_commit_entry($d)->{log},
                                        ra => Git::SVN::Ra->new($gs->full_url),
@@ -394,42 +410,39 @@ sub cmd_dcommit {
                                        tree_b => $d,
                                        editor_cb => sub {
                                               print "Committed r$_[0]\n";
-                                              $last_rev = $_[0]; },
+                                              $cmt_rev = $_[0];
+                                       },
                                        svn_path => '');
                        if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
                                print "No changes\n$d~1 == $d\n";
                        } elsif ($parents->{$d} && @{$parents->{$d}}) {
-                               $gs->{inject_parents_dcommit}->{$last_rev} =
+                               $gs->{inject_parents_dcommit}->{$cmt_rev} =
                                                               $parents->{$d};
                        }
+                       $_fetch_all ? $gs->fetch_all : $gs->fetch;
+                       next if $_no_rebase;
+
+                       # we always want to rebase against the current HEAD,
+                       # not any head that was passed to us
+                       my @diff = command('diff-tree', 'HEAD',
+                                          $gs->refname, '--');
+                       my @finish;
+                       if (@diff) {
+                               @finish = rebase_cmd();
+                               print STDERR "W: HEAD and ", $gs->refname,
+                                            " differ, using @finish:\n",
+                                            "@diff";
+                       } else {
+                               print "No changes between current HEAD and ",
+                                     $gs->refname,
+                                     "\nResetting to the latest ",
+                                     $gs->refname, "\n";
+                               @finish = qw/reset --mixed/;
+                       }
+                       command_noisy(@finish, $gs->refname);
+                       $last_rev = $cmt_rev;
                }
        }
-       return if $_dry_run;
-       unless ($gs) {
-               warn "Could not determine fetch information for $url\n",
-                    "Will not attempt to fetch and rebase commits.\n",
-                    "This probably means you have useSvmProps and should\n",
-                    "now resync your SVN::Mirror repository.\n";
-               return;
-       }
-       $_fetch_all ? $gs->fetch_all : $gs->fetch;
-       unless ($_no_rebase) {
-               # we always want to rebase against the current HEAD, not any
-               # head that was passed to us
-               my @diff = command('diff-tree', 'HEAD', $gs->refname, '--');
-               my @finish;
-               if (@diff) {
-                       @finish = rebase_cmd();
-                       print STDERR "W: HEAD and ", $gs->refname, " differ, ",
-                                    "using @finish:\n", "@diff";
-               } else {
-                       print "No changes between current HEAD and ",
-                             $gs->refname, "\nResetting to the latest ",
-                             $gs->refname, "\n";
-                       @finish = qw/reset --mixed/;
-               }
-               command_noisy(@finish, $gs->refname);
-       }
 }
 
 sub cmd_find_rev {
@@ -799,7 +812,8 @@ sub cmt_metadata {
 
 sub working_head_info {
        my ($head, $refs) = @_;
-       my ($fh, $ctx) = command_output_pipe('log', $head);
+       my @args = ('log', '--no-color', '--first-parent');
+       my ($fh, $ctx) = command_output_pipe(@args, $head);
        my $hash;
        my %max;
        while (<$fh>) {
@@ -829,14 +843,9 @@ sub working_head_info {
 
 sub read_commit_parents {
        my ($parents, $c) = @_;
-       my ($fh, $ctx) = command_output_pipe(qw/cat-file commit/, $c);
-       while (<$fh>) {
-               chomp;
-               last if '';
-               /^parent ($sha1)/ or next;
-               push @{$parents->{$c}}, $1;
-       }
-       close $fh; # break the pipe
+       chomp(my $p = command_oneline(qw/rev-list --parents -1/, $c));
+       $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
+       @{$parents->{$c}} = split(/ /, $p);
 }
 
 sub linearize_history {
@@ -2064,7 +2073,7 @@ sub rebuild {
                return;
        }
        print "Rebuilding $db_path ...\n";
-       my ($log, $ctx) = command_output_pipe("log", $self->refname);
+       my ($log, $ctx) = command_output_pipe("log", '--no-color', $self->refname);
        my $latest;
        my $full_url = $self->full_url;
        remove_username($full_url);
@@ -3001,7 +3010,7 @@ package Git::SVN::Ra;
 use vars qw/@ISA $config_dir $_log_window_size/;
 use strict;
 use warnings;
-my ($can_do_switch, %ignored_err, $RA);
+my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
 
 BEGIN {
        # enforce temporary pool usage for some simple functions
@@ -3162,7 +3171,11 @@ sub gs_do_switch {
                        $self->{url} = $full_url;
                        $reparented = 1;
                } else {
+                       $_[0] = undef;
+                       $self = undef;
+                       $RA = undef;
                        $ra = Git::SVN::Ra->new($full_url);
+                       $ra_invalid = 1;
                }
        }
        $ra ||= $self;
@@ -3222,6 +3235,7 @@ sub gs_fetch_loop_common {
        my $inc = $_log_window_size;
        my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
        my $longest_path = longest_common_path($gsv, $globs);
+       my $ra_url = $self->{url};
        while (1) {
                my %revs;
                my $err;
@@ -3283,6 +3297,13 @@ sub gs_fetch_loop_common {
                                        "$g->{t}-maxRev";
                                Git::SVN::tmp_config($k, $r);
                        }
+                       if ($ra_invalid) {
+                               $_[0] = undef;
+                               $self = undef;
+                               $RA = undef;
+                               $self = Git::SVN::Ra->new($ra_url);
+                               $ra_invalid = undef;
+                       }
                }
                # pre-fill the .rev_db since it'll eventually get filled in
                # with '0' x40 if something new gets committed
@@ -3557,7 +3578,7 @@ sub config_pager {
 }
 
 sub run_pager {
-       return unless -t *STDOUT;
+       return unless -t *STDOUT && defined $pager;
        pipe my $rfd, my $wfd or return;
        defined(my $pid = fork) or ::fatal "Can't fork: $!\n";
        if (!$pid) {