From 512b620bd9fef7f170562ecad835e37479f051ce Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 3 Apr 2007 01:57:08 -0700 Subject: git-svn: bail out on incorrect command-line options "git svn log" is the only command that needs the pass-through option in Getopt::Long; otherwise we will bail out and let the user know something is wrong. Also, avoid printing out unaccepted mixed-case options (that are reserved for the command-line) such as --useSvmProps in the usage() function. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index d307d430f..6216cade0 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; @@ -168,6 +168,7 @@ 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 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, @@ -229,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 ? -- cgit v1.2.1 From 13c823fb520eaf1cded520213cf0ae4c3268208d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 8 Apr 2007 00:59:19 -0700 Subject: git-svn: dcommit/rebase confused by patches with git-svn-id: lines When patches are merged from another git-svn managed branch, they will have the git-svn-id: metadata line in them (generated by git-format-patch). When doing rebase or dcommit via git-svn, this would cause git-svn to find the wrong upstream branch. We now verify that the commit is consistent with the value in the .rev_db file. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 6216cade0..e4079fb76 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -363,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")) { @@ -431,16 +430,11 @@ 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); - unless ($gs) { - die "Unable to determine remote information from URL: $url\n"; - } if (command(qw/diff-index HEAD --/)) { print STDERR "Cannot rebase with uncommited changes:\n"; command_noisy('status'); @@ -453,8 +447,8 @@ sub cmd_rebase { } 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); } @@ -776,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); + 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; @@ -3321,8 +3322,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; -- cgit v1.2.1 From c16d08713e2d7f5c440f7649ceb68f838b4b8bea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 8 Apr 2007 00:59:22 -0700 Subject: git-svn: fix log command to avoid infinite loop on long commit messages This bug has been around since the the conversion to use the Git.pm library back in October or November. Eventually I'd like "git rev-list/log" to have the option to not truncate overly long messages. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- git-svn.perl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index e4079fb76..ac44f60b8 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -3263,12 +3263,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]); -- cgit v1.2.1