[PATCH] gitweb: Extra columns in blame

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds extra columns to blame output, containing
line author and creation date. These columns are by default hidden by
display: none but by clicking on the expansion "button" you can display
them (and hide again). I think seeing this information without tooltips
fishing can give much better overview of the content evolution.

This patch depends on the interactive blame patch (but can be factored out;
the common required parts are just the blame.js infrastructure).

Signed-off-by: Petr Baudis <pasky@xxxxxxx>
---

 gitweb/blame.js    |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 gitweb/gitweb.css  |    5 +++++
 gitweb/gitweb.perl |   23 +++++++++++++++++++----
 3 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/gitweb/blame.js b/gitweb/blame.js
index 88b6499..438bc9c 100644
--- a/gitweb/blame.js
+++ b/gitweb/blame.js
@@ -1,4 +1,41 @@
 // Copyright (C) 2007, Fredrik Kuivinen <frekui@xxxxxxxxx>
+// Copyright (C) 2007, Petr Baudis <pasky@xxxxxxx>
+
+
+// blame extra columns
+
+// I would like to note here that JavaScript is utterly stupid.
+function findStyleRule(styleName) {
+	for (i = 0; i < document.styleSheets.length; i++) { 
+		for (j = 0; j < document.styleSheets[i].cssRules.length; j++) {
+			var rule = document.styleSheets[i].cssRules[j];
+			if (rule.selectorText == styleName) {
+				return rule;
+			}
+		}     
+	}
+}
+var extra_column_rule;
+
+var extra_columns = 0;
+function extra_blame_columns() {
+	if (!extra_column_rule)
+		extra_column_rule = findStyleRule("th.extra_column, td.extra_column");
+
+	if (!extra_columns) {
+		document.getElementById("columns_expander").innerHTML = "[-]";
+		extra_column_rule.style.cssText = extra_column_rule.style.cssText.replace("none", "table-cell");
+		extra_columns = 1;
+	} else {
+		document.getElementById("columns_expander").innerHTML = "[+]";
+		extra_column_rule.style.cssText = extra_column_rule.style.cssText.replace("table-cell", "none");
+		extra_columns = 0;
+	}
+}
+
+
+// blame_interactive
+
 
 var DEBUG = 0;
 function debug(str)
@@ -72,14 +109,20 @@ function handleLine(commit)
             zeroPad(date.getUTCSeconds());
         tr.firstChild.title = commit.author + ', ' + dateStr + ' ' + timeStr;
         var shaAnchor = tr.firstChild.firstChild;
+	var authorField = tr.firstChild.nextSibling;
+	var dateField = tr.firstChild.nextSibling.nextSibling;
         if (i == 0) {
             shaAnchor.href = baseUrl + ';a=commit;h=' + commit.sha1;
             shaAnchor.innerHTML = commit.sha1.substr(0, 8);
+	    authorField.innerHTML = commit.author;
+	    dateField.innerHTML = dateStr + ' ' + timeStr;
         } else {
             shaAnchor.innerHTML = '';
+            authorField.innerHTML = '';
+            dateField.innerHTML = '';
         }
 
-        var lineAnchor = tr.firstChild.nextSibling.firstChild;
+        var lineAnchor = tr.firstChild.nextSibling.nextSibling.nextSibling.firstChild;
         lineAnchor.href = baseUrl + ';a=blame;hb=' + commit.sha1 +
             ';f=' + commit.filename + '#l' + commit.srcline;
         resline++;
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index 9f0822f..b76e839 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -488,3 +488,8 @@ span.match {
 div.binary {
 	font-style: italic;
 }
+
+/* This selector is hardcoded in gitweb.perl */
+th.extra_column, td.extra_column {
+	display: none;
+}
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index cc671b1..2dc7be8 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3671,9 +3671,14 @@ sub git_blame_incremental {
 	my $last_rev;
 	print "<script type=\"text/javascript\" src=\"$blamejs\"></script>\n";
 	print <<HTML;
+
 <div class="page_body">
 <table class="blame">
-<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
+<tr><th>Commit&nbsp;<a href="javascript:extra_blame_columns()" id="columns_expander">[+]</a></th>
+<th class="extra_column">Author</th>
+<th class="extra_column">Date</th>
+<th>Line</th>
+<th>Data</th></tr>
 HTML
 	my %metainfo = ();
 	my $linenr = 0;
@@ -3682,6 +3687,8 @@ HTML
 		$linenr += 1;
 		print "<tr id=\"l$linenr\" class=\"light2\">";
 		print '<td class="sha1"><a href=""></a></td>';
+		print "<td class=\"extra_column\"></td>";
+		print "<td class=\"extra_column\"></td>";
 		print "<td class=\"linenr\"><a class=\"linenr\" href=\"\">$linenr</a></td><td class=\"pre\">" . esc_html($_) . "</td>\n";
 		print "</tr>\n"
 	}
@@ -3738,10 +3745,16 @@ sub git_blame2 {
 	my $num_colors = scalar(@rev_color);
 	my $current_color = 0;
 	my $last_rev;
+	print "<script type=\"text/javascript\" src=\"$blamejs\"></script>\n";
 	print <<HTML;
+
 <div class="page_body">
 <table class="blame">
-<tr><th>Commit</th><th>Line</th><th>Data</th></tr>
+<tr><th>Commit&nbsp;<a href="javascript:extra_blame_columns()" id="columns_expander">[+]</a></th>
+<th class="extra_column">Author</th>
+<th class="extra_column">Date</th>
+<th>Line</th>
+<th>Data</th></tr>
 HTML
 	my %metainfo = ();
 	while (1) {
@@ -3771,15 +3784,17 @@ HTML
 		}
 		print "<tr class=\"$rev_color[$current_color]\">\n";
 		if ($group_size) {
+			my $rowspan = $group_size > 1 ? " rowspan=\"$group_size\"" : "";
 			print "<td class=\"sha1\"";
 			print " title=\"". esc_html($author) . ", $date\"";
-			print " rowspan=\"$group_size\"" if ($group_size > 1);
-			print ">";
+			print "$rowspan>";
 			print $cgi->a({-href => href(action=>"commit",
 			                             hash=>$full_rev,
 			                             file_name=>$file_name)},
 			              esc_html($rev));
 			print "</td>\n";
+			print "<td class=\"extra_column\" $rowspan>". esc_html($author) . "</td>";
+			print "<td class=\"extra_column\" $rowspan>". $date . "</td>";
 		}
 		open (my $dd, "-|", git_cmd(), "rev-parse", "$full_rev^")
 			or die_error(undef, "Open git-rev-parse failed");

-
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux