Re: More precise tag following
From: Jeff King <hidden>
Date: 2016-06-15 22:42:51
On Sat, Jan 27, 2007 at 09:22:50AM -0800, Linus Torvalds wrote:
Here's a patch. Use "git blame --incremental filename" to get the blame output in a nicely parseable format that you can now write a simple graphical viewer for.
And here's a (very hackish) incremental viewer using perl/gtk (you will
need the Gtk2 perl module installed). It doesn't take any options, and it
just shows the blame output (no lookup of committer/date).
It needs much work (and cleanup) to be useful, but I think it proves
your point: in the time it takes me to actually start looking through
the output, the blame has finished without me noticing!
-Peff
-- >8 --
#!/usr/bin/perl
use Gtk2 -init;
use Gtk2::SimpleList;
my $fn = shift or die "require filename to blame";
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect(destroy => sub { Gtk2->main_quit });
my $scrolled_window = Gtk2::ScrolledWindow->new;
$window->add($scrolled_window);
my $fileview = Gtk2::SimpleList->new(
'Commit' => 'text',
'FileLine' => 'text',
'Data' => 'text'
);
$scrolled_window->add($fileview);
$fileview->get_column(0)->set_spacing(0);
$fileview->set_size_request(1024, 768);
open(my $fh, '<', $fn)
or die "unable to open $fn: $!";
while(<$fh>) {
chomp;
$fileview->{data}->[$.] = ['HEAD', "$fn:$.", $_];
}
open(my $blame, '-|', qw(git blame --incremental), $fn)
or die "unable to open git blame: $!";
Glib::IO->add_watch(fileno($blame), 'in', \&read_blame_line);
$window->show_all;
Gtk2->main;
exit 0;
my $buf;
sub read_blame_line {
my $r = sysread($blame, $buf, 1024, length($buf));
return 0 unless $r;
while($buf =~ s/([^\n]*)\n//) {
my $line = $1;
$line =~ /^(\d+) (\d+) ([0-9a-f]+):(.*):(\d+)$/
or die "bad blame output: $line";
for(my $i = 0; $i < $2; $i++) {
@{$fileview->{data}->[$1+$i]}[0,1] =
(substr($3, 0, 8), $4 . ':' . ($5+$i+1));
}
}
return 1;
}