Skip to content

Instantly share code, notes, and snippets.

@tantalor
Created March 12, 2011 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tantalor/866994 to your computer and use it in GitHub Desktop.
Save tantalor/866994 to your computer and use it in GitHub Desktop.
Combines svn blame and diff.
#!/usr/bin/perl
use strict;
use List::Util 'max';
my ($from, $to) = @ARGV
or die "usage: $0 OLD-URL[\@OLDREV] NEW-URL[\@NEWREV]\n";
my @diff = `svn diff $from $to` or die;
my @blame = map {/^\s*(\d+)/} `svn blame $to` or die;
my $pad = max map {length} @blame;
for (my $diff_ln = 0; $diff_ln < @diff; $diff_ln++) {
if (my ($to_ln) = $diff[$diff_ln] =~ /@@ -\d+,\d+ \+(\d+),\d+ @@/) {
$diff_ln++;
for (my $off_ln = 0; $diff[$diff_ln] && $diff[$diff_ln+1] !~ /@@/; $diff_ln++) {
if ($diff[$diff_ln] =~ /^\+(.*)$/) {
printf "%${pad}d: %s\n", $blame[$to_ln+$off_ln], $1;
}
$off_ln++ unless $diff[$diff_ln] =~ /^-/;
}
print "\n" if $diff_ln < @diff;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment