6 my $fn = shift or die "require filename to blame";
8 Gtk2
::Rc
->parse_string(<<'EOS');
11 GtkTreeView::vertical-separator = 0
13 class "GtkTreeView" style "treeview_style"
16 my $window = Gtk2
::Window
->new('toplevel');
17 $window->signal_connect(destroy
=> sub { Gtk2
->main_quit });
18 my $scrolled_window = Gtk2
::ScrolledWindow
->new;
19 $window->add($scrolled_window);
20 my $fileview = Gtk2
::SimpleList
->new(
22 'CommitInfo' => 'text',
26 $scrolled_window->add($fileview);
27 $fileview->get_column(0)->set_spacing(0);
28 $fileview->set_size_request(1024, 768);
29 $fileview->set_rules_hint(1);
32 open($fh, '-|', "git cat-file blob HEAD:$fn")
33 or die "unable to open $fn: $!";
36 $fileview->{data
}->[$.] = ['HEAD', '?', "$fn:$.", $_];
40 open($blame, '-|', qw(git blame --incremental --), $fn)
41 or die "cannot start git-blame $fn";
43 Glib
::IO
->add_watch(fileno($blame), 'in', \
&read_blame_line
);
51 sub flush_blame_line
{
54 return unless defined $attr;
56 my ($commit, $s_lno, $lno, $cnt) =
57 @
{$attr}{qw(COMMIT S_LNO LNO CNT)};
59 my ($filename, $author, $author_time, $author_tz) =
60 @
{$commitinfo{$commit}}{qw(FILENAME AUTHOR AUTHOR-TIME AUTHOR-TZ)};
61 my $info = $author . ' ' . format_time
($author_time, $author_tz);
63 for(my $i = 0; $i < $cnt; $i++) {
64 @
{$fileview->{data
}->[$lno+$i-1]}[0,1,2] =
65 (substr($commit, 0, 8), $info,
66 $filename . ':' . ($s_lno+$i));
74 my $r = sysread($blame, $buf, 1024, length($buf));
75 die "I/O error" unless defined $r;
78 flush_blame_line
($current);
83 while ($buf =~ s/([^\n]*)\n//) {
86 if (($commit, $s_lno, $lno, $cnt) =
87 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+) (\d+)$/)) {
88 flush_blame_line
($current);
98 # extended attribute values
99 if ($line =~ /^(author|author-mail|author-time|author-tz|committer|committer-mail|committer-time|committer-tz|summary|filename) (.*)$/) {
100 my $commit = $current->{COMMIT
};
101 $commitinfo{$commit}{uc($1)} = $2;
112 my $minutes = $tz < 0 ?
0-$tz : $tz;
113 $minutes = ($minutes / 100)*60 + ($minutes % 100);
114 $minutes = $tz < 0 ?
0-$minutes : $minutes;
115 $time += $minutes * 60;
116 my @t = gmtime($time);
117 return sprintf('%04d-%02d-%02d %02d:%02d:%02d %s',
118 $t[5] + 1900, @t[4,3,2,1,0], $tz);