Subject: [PATCH/RFC] gitweb: Provide links to individual commitdiffs in difftree for merges

From: Jakub Narebski <[email-masked]>
Date: Sun, 27 May 2007 01:50:22 +0200

Add to difftree / whatchanged table row with "1", "2", ... links to
'commitdiff' view for diff with n-th parent for merge commits, as a
table header.  This is visible in 'commit' and 'comitdiff' views.  It
is more important for 'commitdiff' view, as in 'commit' view commit
object header has 'diff' links to diff to n-th parent.

To save space links are shown as "n", where "n" is number of a parent,
and not as for example shortened (to 7 characters) sha1 of a parent
commit.  To make it easier to doscover what links is for, encompassing
<th> element has 'title' attribute explaining the link.

Signed-off-by: Jakub Narebski <[email-masked]>
---
This is my proposal on how to provide links to diffs to individual
parents in the 'commitdiff' view.  This is RFC: please comment if you
like the idea (or not), and what the layout should be, what this
should look like.  Should we add those links only for 'commitdiff'
view, for example?

Some complications in creating layout stem from the fact that "|" is
used as separator, instead of using table border, or cell borders to
separate columns. And we use "|" because in most other places we use
only one cell (column) for the whole series of links.

 gitweb/gitweb.css  |    5 +++++
 gitweb/gitweb.perl |   19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index 9f0822f..7908fe3 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -181,10 +181,15 @@ table.diff_tree {
 	font-family: monospace;
 }
 
+table.combined.diff_tree th {
+	text-align: center;
+}
+
 table.combined.diff_tree td {
 	padding-right: 24px;
 }
 
+table.combined.diff_tree th.link,
 table.combined.diff_tree td.link {
 	padding: 0px 2px;
 }
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c3921cb..999353d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2380,6 +2380,25 @@ sub git_difftree_body {
 	print "<table class=\"" .
 	      (@parents > 1 ? "combined " : "") .
 	      "diff_tree\">\n";
+
+	if (@parents > 1) { #combined diff
+		# table header for combined diff
+		print "<tr>\n" .
+		      ($action eq 'commitdiff' ? "<th></th><th></th>\n"
+		                               : "<th></th>\n");
+		for (my $i = 0; $i < @parents; $i++) {
+			my $par = $parents[$i];
+			print "<th title=\"commitdiff to parent number " .
+			      ($i+1) . ": " .
+			      substr($par,0,7) . "\">" .
+			      $cgi->a({-href => href(action=>"commitdiff",
+			                             hash=>$hash, hash_parent=>$par)},
+			              $i+1) .
+			      "&nbsp;</th>\n";
+		}
+		print "</tr>\n";
+	}
+
 	my $alternate = 1;
 	my $patchno = 0;
 	foreach my $line (@{$difftree}) {
-- 
1.5.2