gitweb: show age and author in blame output
PATCH 1/1 gitweb: show age and author in blame output
The commit object name link on each link uses "title", which shows the author and age of the particular line when hovered over.
The background of these links are painted on darker color as they become older and the links on younger lines are shown on lighter background.
Signed-off-by Junio C Hamano <[email protected]>
--- gitweb/gitweb.css | 6 ++++++ gitweb/gitweb.perl | 27 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-)
gitweb/gitweb.css +6 -0
@@ -215,6 +215,12 @@ td.sha1 { font-family: monospace; } +table.blame td.age-week { color: #0000ff; background-color: #ffffff; } +table.blame td.age-month { color: #0000ff; background-color: #ddddee; } +table.blame td.age-season { color: #0000ff; background-color: #bbbbdd; } +table.blame td.age-year { color: #0000ff; background-color: #9999cc; } +table.blame td.age-old { color: #0000ff; background-color: #7777bb; } + td.error { color: red; background-color: yellow;
gitweb/gitweb.perl +23 -4
@@ -2171,12 +2171,26 @@ sub git_tag { } sub flush_blame_lines { - my ($color, $file_name, @line) = @_; + my ($color, $file_name, $now, @line) = @_; my $full_rev = shift @line; + + my ($author, $timestamp, $zone) = + ($line[0] =~ + /^[0-9a-f]{40}\s\((.*?)\s+(\d+)\s([-+\d]{5})\s+\d+\)/); + my $age = $now - $timestamp; + my $ago = age_string($age); + my $pop = 'title="' . esc_html("$author, $ago") . '"'; + my $agegroup = + (($age < 60*60*24*7) ? "age-week" : + ($age < 60*60*24*30) ? "age-month" : + ($age < 60*60*24*120) ? "age-season" : + ($age < 60*60*24*360) ? "age-year" : "age-old"); + my $rev = substr($full_rev, 0, 8); my $cnt = scalar @line; my $this = 0; + for (@line) { $this++; unless (/^[0-9a-fA-F]{40}.*?(\d+)\)\s(.*)/) {
@@ -2188,11 +2202,12 @@ sub flush_blame_lines { print "<tr class=\"$color\">\n"; if ($this == 1) { + my $cls = "class=\"sha1 $agegroup\""; if (1 < $cnt) { - print "<td class=\"sha1\" rowspan=\"$cnt\">"; + print "<td $cls $pop rowspan=\"$cnt\">"; } else { - print "<td class=\"sha1\">"; + print "<td $cls $pop>"; } print $cgi->a({-href => href(action=>"commit", hash=>$full_rev,
@@ -2228,7 +2243,8 @@ sub git_blame2 { if ($ftype !~ "blob") { die_error("400 Bad Request", "Object is not a blob"); } - open ($fd, "-|", git_cmd(), "blame", '-l', $file_name, $hash_base) + open ($fd, "-|", git_cmd(), "blame", '-l', '-t', + $file_name, $hash_base) or die_error(undef, "Open git-blame failed"); git_header_html(); my $formats_nav =
@@ -2242,6 +2258,7 @@ sub git_blame2 { git_print_page_path($file_name, $ftype, $hash_base); my @rev_color = (qw(light2 dark2)); my $num_colors = scalar(@rev_color); + my $now = time(); my $current_color = 0; my @current_group = (); print <<HTML;
@@ -2260,6 +2277,7 @@ HTML $current_color = ++$current_color % $num_colors; flush_blame_lines($rev_color[$current_color], $file_name, + $now, @current_group); } else {
@@ -2273,6 +2291,7 @@ HTML $current_color = ++$current_color % $num_colors; flush_blame_lines($rev_color[$current_color], $file_name, + $now, @current_group); } print "</table>\n";
Signature · 1 line
1.4.2.g39ee