Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH] gitweb: show age and author in blame output
Date: Tue, 29 Aug 2006 02:07:03 -0700	[thread overview]
Message-ID: <7v64gboqq0.fsf@assigned-by-dhcp.cox.net> (raw)

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 <junkio@cox.net>
---
 gitweb/gitweb.css  |    6 ++++++
 gitweb/gitweb.perl |   27 +++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index eb9fc38..f3211c2 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -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;
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5c82d3f..0265a82 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -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";
-- 
1.4.2.g39ee

                 reply	other threads:[~2006-08-29  9:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v64gboqq0.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=jnareb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox