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;
$_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,
{ '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,
my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
read_repo_config(\%opts);
+Getopt::Long::Configure('pass_through') if $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,
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$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
print $fd ' ' x 21, join(', ', map { length $_ > 1 ?
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")) {
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);
}
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);
+ my ($url, $rev, $uuid) = cmt_metadata($_);
+ 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 $_) {
+ close $fh; # break the pipe
+ return ($url, $rev, $uuid, $gs);
+ }
+ }
+ }
unshift @$refs, $_ if $refs;
}
- close $fh; # break the pipe
- ($url, $rev, $uuid);
+ command_close_pipe($fh, $ctx);
+ (undef, undef, undef, undef);
}
package Git::SVN;
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 {
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
# 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";
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]);
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;