Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
executable file 67 lines (62 sloc) 2.059 kB
#!/usr/bin/perl -w
sub parse_hunk_header {
my ($line) = @_;
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
$line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
$o_cnt = 1 unless defined $o_cnt;
$n_cnt = 1 unless defined $n_cnt;
return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
}
sub get_blame_prefix {
my ($line) = @_;
$line =~ /^([0-9a-f]+\s+(\S+\s+)?\([^\)]+\))/ or die "bad blame output: $line";
return $1;
}
my ($oldrev, $newrev) = @ARGV;
open($diff, '-|', 'git', '--no-pager', 'diff', $oldrev, $newrev) or die;
my ($pre, $post);
my $filename;
while (<$diff>) {
if (m{^diff --git ./(.*) ./\1$}) {
close $pre if defined $pre;
close $post if defined $post;
print;
$prefilename = "./" . $1;
$postfilename = "./" . $1;
$delete = $create = 0;
} elsif (m{^new file}) {
$create = 1;
$prefilename = '/dev/null';
} elsif (m{^deleted file}) {
$delete = 1;
$postfilename = '/dev/null';
} elsif (m{^--- $prefilename$}) {
# ignore
print;
} elsif (m{^\+\+\+ $postfilename$}) {
# ignore
print;
} elsif (m{^@@ }) {
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt)
= parse_hunk_header($_);
my $o_end = $o_ofs + $o_cnt - 1;
my $n_end = $n_ofs + $n_cnt - 1;
if (!$create) {
open($pre, '-|', 'git', 'blame', '-M', "-L$o_ofs,$o_end",
"-l",
$oldrev, '--', $prefilename) or die;
}
if (!$delete) {
open($post, '-|', 'git', 'blame', '-M', "-L$n_ofs,$n_end",
"-l",
$newrev, '--', $postfilename) or die;
}
} elsif (m{^ }) {
print get_blame_prefix(scalar <$pre>), "\t", $_;
scalar <$post>; # discard
} elsif (m{^\-}) {
print get_blame_prefix(scalar <$pre>), "\t", $_;
} elsif (m{^\+}) {
print get_blame_prefix(scalar <$post>), "\t", $_;
}
}
Jump to Line
Something went wrong with that request. Please try again.