diff options
author | Steven Grimm <koreth@midwinter.com> | 2008-05-10 22:11:18 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-05-11 10:12:19 -0700 |
commit | 4be403815321976bc2ee4c6677799abb06b153aa (patch) | |
tree | c0aa1a96147c96619aae8d4e1d93e0817091d2ec /git-svn.perl | |
parent | f4e9f786f737e55fd4ea06dbb25b14dd32b872c1 (diff) | |
download | git-4be403815321976bc2ee4c6677799abb06b153aa.tar.gz |
Add svn-compatible "blame" output format to git-svn
git-svn blame produced output in the format of git blame; in environments
where there are scripts that read the output of svn blame, it's useful
to be able to use them with the output of git-svn. The git-compatible
format is still available using the new "--git-format" option.
This also fixes a bug in the initial git-svn blame implementation; it was
bombing out on uncommitted local changes.
Signed-off-by: Steven Grimm <koreth@midwinter.com>
Acked-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-svn.perl')
-rwxr-xr-x | git-svn.perl | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/git-svn.perl b/git-svn.perl index 413e0b1db6..2c53f39aef 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -65,7 +65,8 @@ my ($_stdin, $_help, $_edit, $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_merge, $_strategy, $_dry_run, $_local, - $_prefix, $_no_checkout, $_url, $_verbose); + $_prefix, $_no_checkout, $_url, $_verbose, + $_git_format); $Git::SVN::_follow_parent = 1; my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, 'config-dir=s' => \$Git::SVN::Ra::config_dir, @@ -188,7 +189,7 @@ my %cmd = ( { 'url' => \$_url, } ], 'blame' => [ \&Git::SVN::Log::cmd_blame, "Show what revision and author last modified each line of a file", - {} ], + { 'git-format' => \$_git_format } ], ); my $cmd; @@ -225,7 +226,7 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) { my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd); read_repo_config(\%opts); -Getopt::Long::Configure('pass_through') if ($cmd && $cmd eq 'log'); +Getopt::Long::Configure('pass_through') if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')); 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, @@ -4468,19 +4469,51 @@ out: } sub cmd_blame { - my $path = shift; + my $path = pop; config_pager(); run_pager(); - my ($fh, $ctx) = command_output_pipe('blame', @_, $path); - while (my $line = <$fh>) { - if ($line =~ /^\^?([[:xdigit:]]+)\s/) { - my (undef, $rev, undef) = ::cmt_metadata($1); - $rev = sprintf('%-10s', $rev); - $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/; + my ($fh, $ctx, $rev); + + if ($_git_format) { + ($fh, $ctx) = command_output_pipe('blame', @_, $path); + while (my $line = <$fh>) { + if ($line =~ /^\^?([[:xdigit:]]+)\s/) { + # Uncommitted edits show up as a rev ID of + # all zeros, which we can't look up with + # cmt_metadata + if ($1 !~ /^0+$/) { + (undef, $rev, undef) = + ::cmt_metadata($1); + $rev = '0' if (!$rev); + } else { + $rev = '0'; + } + $rev = sprintf('%-10s', $rev); + $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/; + } + print $line; + } + } else { + ($fh, $ctx) = command_output_pipe('blame', '-p', @_, 'HEAD', + '--', $path); + my ($sha1); + my %authors; + while (my $line = <$fh>) { + if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) { + $sha1 = $1; + (undef, $rev, undef) = ::cmt_metadata($1); + $rev = '0' if (!$rev); + } + elsif ($line =~ /^author (.*)/) { + $authors{$rev} = $1; + $authors{$rev} =~ s/\s/_/g; + } + elsif ($line =~ /^\t(.*)$/) { + printf("%6s %10s %s\n", $rev, $authors{$rev}, $1); + } } - print $line; } command_close_pipe($fh, $ctx); } |