X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=git-svn.perl;h=90f3bc18b959fb38b410c69d14eda30ba084dfd9;hb=af068d274245be9aedc58e6835c2e43329639974;hp=326e89fe037561c1ad72d91c7783bf2a0f603826;hpb=27ebd6e0443bdd795869f598ecebc9eadd64a26c;p=git.git diff --git a/git-svn.perl b/git-svn.perl index 326e89fe0..90f3bc18b 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -33,7 +33,7 @@ use Carp qw/croak/; use IO::File qw//; use File::Basename qw/dirname basename/; use File::Path qw/mkpath/; -use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev pass_through/; +use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use IPC::Open3; use Git; @@ -56,7 +56,7 @@ my ($_stdin, $_help, $_edit, $_message, $_file, $_template, $_shared, $_version, $_fetch_all, - $_merge, $_strategy, $_dry_run, + $_merge, $_strategy, $_dry_run, $_local, $_prefix, $_no_checkout, $_verbose); $Git::SVN::_follow_parent = 1; my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, @@ -145,6 +145,7 @@ my %cmd = ( { 'merge|m|M' => \$_merge, 'verbose|v' => \$_verbose, 'strategy|s=s' => \$_strategy, + 'local|l' => \$_local, 'fetch-all|all' => \$_fetch_all, %fc_opts } ], 'commit-diff' => [ \&cmd_commit_diff, @@ -167,13 +168,14 @@ for (my $i = 0; $i < @ARGV; $i++) { my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd); read_repo_config(\%opts); +Getopt::Long::Configure('pass_through') if ($cmd && $cmd eq 'log'); my $rv = GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version, 'minimize-connections' => \$Git::SVN::Migration::_minimize, 'id|i=s' => \$Git::SVN::default_ref_id, 'svn-remote|remote|R=s' => sub { $Git::SVN::no_reuse_existing = 1; $Git::SVN::default_repo_id = $_[1] }); -exit 1 if (!$rv && $cmd ne 'log'); +exit 1 if (!$rv && $cmd && $cmd ne 'log'); usage(0) if $_help; version() if $_version; @@ -228,6 +230,8 @@ Usage: $0 [options] [arguments]\n next if /^multi-/; # don't show deprecated commands print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n"; foreach (keys %{$cmd{$_}->[2]}) { + # mixed-case options are for .git/config only + next if /[A-Z]/ && /^[a-z]+$/i; # prints out arguments as they should be passed: my $x = s#[:=]s$## ? '' : s#[:=]i$## ? '' : ''; print $fd ' ' x 21, join(', ', map { length $_ > 1 ? @@ -359,13 +363,12 @@ sub cmd_dcommit { my $head = shift; $head ||= 'HEAD'; my @refs; - my ($url, $rev, $uuid) = working_head_info($head, \@refs); - my $c = $refs[-1]; - unless (defined $url && defined $rev && defined $uuid) { + my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs); + unless ($gs) { die "Unable to determine upstream SVN information from ", "$head history\n"; } - my $gs = Git::SVN->find_by_url($url); + my $c = $refs[-1]; my $last_rev; foreach my $d (@refs) { if (!verify_ref("$d~1")) { @@ -427,25 +430,25 @@ sub cmd_dcommit { sub cmd_rebase { command_noisy(qw/update-index --refresh/); - my $url = (working_head_info('HEAD'))[0]; - if (!defined $url) { + my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); + unless ($gs) { die "Unable to determine upstream SVN information from ", "working tree history\n"; } - - my $gs = Git::SVN->find_by_url($url); if (command(qw/diff-index HEAD --/)) { print STDERR "Cannot rebase with uncommited changes:\n"; command_noisy('status'); exit 1; } - $_fetch_all ? $gs->fetch_all : $gs->fetch; + unless ($_local) { + $_fetch_all ? $gs->fetch_all : $gs->fetch; + } command_noisy(rebase_cmd(), $gs->refname); } sub cmd_show_ignore { - my $url = (::working_head_info('HEAD'))[0]; - my $gs = Git::SVN->find_by_url($url) || Git::SVN->new; + my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); + $gs ||= Git::SVN->new; my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum); $gs->traverse_ignore(\*STDOUT, $gs->{path}, $r); } @@ -767,16 +770,23 @@ sub cmt_metadata { sub working_head_info { my ($head, $refs) = @_; - my ($url, $rev, $uuid); my ($fh, $ctx) = command_output_pipe('rev-list', $head); - while (<$fh>) { - chomp; - ($url, $rev, $uuid) = cmt_metadata($_); - last if (defined $url && defined $rev && defined $uuid); - unshift @$refs, $_ if $refs; + while (my $hash = <$fh>) { + chomp($hash); + my ($url, $rev, $uuid) = cmt_metadata($hash); + if (defined $url && defined $rev) { + if (my $gs = Git::SVN->find_by_url($url)) { + my $c = $gs->rev_db_get($rev); + if ($c && $c eq $hash) { + close $fh; # break the pipe + return ($url, $rev, $uuid, $gs); + } + } + } + unshift @$refs, $hash if $refs; } - close $fh; # break the pipe - ($url, $rev, $uuid); + command_close_pipe($fh, $ctx); + (undef, undef, undef, undef); } package Git::SVN; @@ -1324,8 +1334,10 @@ sub rel_path { my ($self) = @_; my $repos_root = $self->ra->{repos_root}; return $self->{path} if ($self->{url} eq $repos_root); - die "BUG: rel_path failed! repos_root: $repos_root, Ra URL: ", - $self->ra->{url}, " path: $self->{path}, URL: $self->{url}\n"; + my $url = $self->{url} . + (length $self->{path} ? "/$self->{path}" : $self->{path}); + $url =~ s!^\Q$repos_root\E(?:/+|$)!!g; + $url; } sub traverse_ignore { @@ -1670,7 +1682,10 @@ sub find_parent_branch { } my ($r0, $parent) = $gs->find_rev_before($r, 1); if (!defined $r0 || !defined $parent) { - $gs->fetch(0, $r); + my ($base, $head) = parse_revision_argument(0, $r); + if ($base <= $r) { + $gs->fetch($base, $r); + } ($r0, $parent) = $gs->last_rev_commit; } if (defined $r0 && defined $parent) { @@ -1851,11 +1866,14 @@ sub make_log_entry { } elsif ($self->use_svnsync_props) { my $full_url = $self->svnsync->{url}; $full_url .= "/$self->{path}" if length $self->{path}; + remove_username($full_url); my $uuid = $self->svnsync->{uuid}; $log_entry{metadata} = "$full_url\@$rev $uuid"; $email ||= "$author\@$uuid" } else { - $log_entry{metadata} = $self->metadata_url. "\@$rev " . + my $url = $self->metadata_url; + remove_username($url); + $log_entry{metadata} = "$url\@$rev " . $self->ra->get_uuid; $email ||= "$author\@" . $self->ra->get_uuid; } @@ -2835,8 +2853,7 @@ package Git::SVN::Ra; use vars qw/@ISA $config_dir $_log_window_size/; use strict; use warnings; -my ($can_do_switch); -my $RA; +my ($can_do_switch, %ignored_err, $RA); BEGIN { # enforce temporary pool usage for some simple functions @@ -3148,6 +3165,8 @@ sub match_globs { my $p = $1; my $pathname = $g->{path}->full_path($p); next if $exists->{$pathname}; + next if ($self->check_path($pathname, $r) != + $SVN::Node::dir); $exists->{$pathname} = Git::SVN->init( $self->{url}, $pathname, undef, $g->{ref}->full_path($p), 1); @@ -3208,9 +3227,16 @@ sub skip_unknown_revs { # 175007 - http(s):// (this repo required authorization, too...) # More codes may be discovered later... if ($errno == 175007 || $errno == 175002 || $errno == 160013) { - warn "W: Ignoring error from SVN, path probably ", - "does not exist: ($errno): ", - $err->expanded_message,"\n"; + my $err_key = $err->expanded_message; + # revision numbers change every time, filter them out + $err_key =~ s/\d+/\0/g; + $err_key = "$errno\0$err_key"; + unless ($ignored_err{$err_key}) { + warn "W: Ignoring error from SVN, path probably ", + "does not exist: ($errno): ", + $err->expanded_message,"\n"; + $ignored_err{$err_key} = 1; + } return; } die "Error from SVN, ($errno): ", $err->expanded_message,"\n"; @@ -3245,12 +3271,19 @@ my $l_fmt; sub cmt_showable { my ($c) = @_; return 1 if defined $c->{r}; + + # big commit message got truncated by the 16k pretty buffer in rev-list if ($c->{l} && $c->{l}->[-1] eq "...\n" && $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) { + @{$c->{l}} = (); my @log = command(qw/cat-file commit/, $c->{c}); - shift @log while ($log[0] ne "\n"); + + # shift off the headers + shift @log while ($log[0] ne ''); shift @log; - @{$c->{l}} = grep !/^git-svn-id: /, @log; + + # TODO: make $c->{l} not have a trailing newline in the future + @{$c->{l}} = map { "$_\n" } grep !/^git-svn-id: /, @log; (undef, $c->{r}, undef) = ::extract_metadata( (grep(/^git-svn-id: /, @log))[-1]); @@ -3304,8 +3337,8 @@ sub git_svn_log_cmd { last; } - my $url = (::working_head_info($head))[0]; - my $gs = Git::SVN->find_by_url($url) || Git::SVN->_new; + my ($url, $rev, $uuid, $gs) = ::working_head_info($head); + $gs ||= Git::SVN->_new; my @cmd = (qw/log --abbrev-commit --pretty=raw --default/, $gs->refname); push @cmd, '-r' unless $non_recursive;