11 } elsif ( @ARGV == 2 ) {
15 die "Usage blameview [<rev>] <filename>";
18 Gtk2
::Rc
->parse_string(<<'EOS');
19 style "treeview_style"
21 GtkTreeView::vertical-separator = 0
23 class "GtkTreeView" style "treeview_style"
26 my $window = Gtk2
::Window
->new('toplevel');
27 $window->signal_connect(destroy
=> sub { Gtk2
->main_quit });
28 my $scrolled_window = Gtk2
::ScrolledWindow
->new;
29 $window->add($scrolled_window);
30 my $fileview = Gtk2
::SimpleList
->new(
32 'CommitInfo' => 'text',
36 $scrolled_window->add($fileview);
37 $fileview->get_column(0)->set_spacing(0);
38 $fileview->set_size_request(1024, 768);
39 $fileview->set_rules_hint(1);
40 $fileview->signal_connect (row_activated
=> sub {
41 my ($sl, $path, $column) = @_;
42 my $row_ref = $sl->get_row_data_from_path ($path);
43 system("blameview @$row_ref[0] $fn");
44 # $row_ref is now an array ref to the double-clicked row's data.
48 open($fh, '-|', "git cat-file blob $hash:$fn")
49 or die "unable to open $fn: $!";
53 $fileview->{data
}->[$.] = ['HEAD', '?', "$fn:$.", $_];
57 open($blame, '-|', qw(git blame --incremental --), $fn, $hash)
58 or die "cannot start git-blame $fn";
60 Glib
::IO
->add_watch(fileno($blame), 'in', \
&read_blame_line
);
68 sub flush_blame_line
{
71 return unless defined $attr;
73 my ($commit, $s_lno, $lno, $cnt) =
74 @
{$attr}{qw(COMMIT S_LNO LNO CNT)};
76 my ($filename, $author, $author_time, $author_tz) =
77 @
{$commitinfo{$commit}}{qw(FILENAME AUTHOR AUTHOR-TIME AUTHOR-TZ)};
78 my $info = $author . ' ' . format_time
($author_time, $author_tz);
80 for(my $i = 0; $i < $cnt; $i++) {
81 @
{$fileview->{data
}->[$lno+$i-1]}[0,1,2] =
82 (substr($commit, 0, 8), $info,
83 $filename . ':' . ($s_lno+$i));
91 my $r = sysread($blame, $buf, 1024, length($buf));
92 die "I/O error" unless defined $r;
95 flush_blame_line
($current);
100 while ($buf =~ s/([^\n]*)\n//) {
103 if (($commit, $s_lno, $lno, $cnt) =
104 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+) (\d+)$/)) {
105 flush_blame_line
($current);
115 # extended attribute values
116 if ($line =~ /^(author|author-mail|author-time|author-tz|committer|committer-mail|committer-time|committer-tz|summary|filename) (.*)$/) {
117 my $commit = $current->{COMMIT
};
118 $commitinfo{$commit}{uc($1)} = $2;
129 my $minutes = $tz < 0 ?
0-$tz : $tz;
130 $minutes = ($minutes / 100)*60 + ($minutes % 100);
131 $minutes = $tz < 0 ?
0-$minutes : $minutes;
132 $time += $minutes * 60;
133 my @t = gmtime($time);
134 return sprintf('%04d-%02d-%02d %02d:%02d:%02d %s',
135 $t[5] + 1900, @t[4,3,2,1,0], $tz);