Junio C Hamano <junkio@xxxxxxx> writes: > Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes: > >> On Sun, 28 Jan 2007, Junio C Hamano wrote: >>> >>> I think it is sensible to do the attached on top of your patch. >> >> Ack. >> >> I see you committed this, which is nice, but now Shawn's butt-ugly thing >> doesn't work any more, and my mad perl skillz are sadly lacking. > > Do you mean the perl-Gtk one by Jeff King? This on top of the "final" by Jeff should minimally restore it, in addition to fixing a few problems. * filename/linenumber is updated from the blame. * gmtime output is relative to year 1900. I've annotated revision.c with -C and it was fun to watch;-). --- diff --git a/jk.perl b/jk.perl index 6a4ac9f..c4d9d57 100644 --- a/jk.perl +++ b/jk.perl @@ -41,32 +41,63 @@ $window->show_all; Gtk2->main; exit 0; +my %commitinfo = (); + +sub flush_blame_line { + my ($attr) = @_; + + return unless defined $attr; + + my ($commit, $s_lno, $lno, $cnt) = + @{$attr}{qw(COMMIT S_LNO LNO CNT)}; + + my ($filename, $author, $author_time, $author_tz) = + @{$commitinfo{$commit}}{qw(FILENAME AUTHOR AUTHOR-TIME AUTHOR-TZ)}; + my $info = $author . ' ' . format_time($author_time, $author_tz); + + for(my $i = 0; $i < $cnt; $i++) { + @{$fileview->{data}->[$lno+$i-1]}[0,1,2] = + (substr($commit, 0, 8), $info, + $filename . ':' . ($s_lno+$i)); + } +} + my $buf; +my $current; sub read_blame_line { - my $r = sysread(STDIN, $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"; - my $info = commitinfo($3); - for(my $i = 0; $i < $2; $i++) { - @{$fileview->{data}->[$1+$i]}[0,1] = - (substr($3, 0, 8), $info, $4 . ':' . ($5+$i+1)); - } - } - return 1; -} -sub commitinfo { - my $hash = shift; - open(my $fh, '-|', qw(git rev-list -1 --pretty=raw), $hash) - or die "unable to open git-rev-list: $!"; - while(<$fh>) { - chomp; - next unless /^author (.*) <.*> (\d+) ([+-]\d+)/; - return $1 . ' ' . format_time($2, $3); - } + my $r = sysread(STDIN, $buf, 1024, length($buf)); + die "I/O error" unless defined $r; + + if ($r == 0) { + flush_blame_line($current); + $current = undef; + return 0; + } + + while ($buf =~ s/([^\n]*)\n//) { + my $line = $1; + + if (($commit, $s_lno, $lno, $cnt) = + ($line =~ /^([0-9a-f]{40}) (\d+) (\d+) (\d+)$/)) { + flush_blame_line($current); + $current = +{ + COMMIT => $1, + S_LNO => $2, + LNO => $3, + CNT => $4, + }; + next; + } + + # extended attribute values + if ($line =~ /^(author|author-mail|author-time|author-tz|committer|committer-mail|committer-time|committer-tz|summary|filename) (.*)$/) { + my $commit = $current->{COMMIT}; + $commitinfo{$commit}{uc($1)} = $2; + next; + } + } + return 1; } sub format_time { @@ -78,5 +109,6 @@ sub format_time { $minutes = $tz < 0 ? 0-$minutes : $minutes; $time += $minutes * 60; my @t = gmtime($time); - return sprintf('%04d-%02d-%02d %02d:%02d:%02d %s', @t[5,4,3,2,1,0], $tz); + return sprintf('%04d-%02d-%02d %02d:%02d:%02d %s', + $t[5] + 1900, @t[4,3,2,1,0], $tz); } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html