git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gitweb: Add "next" link to commitdiff view
@ 2006-10-22 22:37 Jakub Narebski
  2006-10-22 22:43 ` Jakub Narebski
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Jakub Narebski @ 2006-10-22 22:37 UTC (permalink / raw)
  To: git; +Cc: Junio Hamano

Add a kind of "next" view in the bottom part of navigation bar for
"commitdiff" view.

For commitdiff between two commits:
  (from: _commit_)
For commitdiff for one single parent commit:
  (parent: _commit_)
For commitdiff for one merge commit
  (merge: _commit_ _commit_ ...)
For commitdiff for root (parentless) commit
  (initial)
where _link_ denotes hyperlink. SHA1 is shortened to 7 characters on
display, everything is perhaps unnecessary esc_html on display.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---

Junio (and others), is it what you wanted? The idea was to change
"commitdiff" view only in minimal way, and preserve similarity
to "commit" format. 

SHA1 ids are printed in monospace (fixed width) font. BTW. should
we put '...' after shortened SHA1? Should those '...' be included
in link?


 gitweb/gitweb.perl |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c9e57f0..4241d5c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3280,6 +3280,51 @@ sub git_commitdiff {
 	if (!%co) {
 		die_error(undef, "Unknown commit object");
 	}
+
+	# we need to prepare $formats_nav before any parameter munging
+	my $formats_nav;
+	if ($format eq 'html') {
+		$formats_nav =
+			$cgi->a({-href => href(action=>"commitdiff_plain",
+			                       hash=>$hash, hash_parent=>$hash_parent)},
+			        "raw");
+
+		if (defined $hash_parent) {
+			# commitdiff with two commits given
+			my $hash_parent_short = $hash_parent;
+			if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
+				$hash_parent_short = substr($hash_parent, 0, 7);
+			}
+			$formats_nav .=
+				' (from: ' .
+				$cgi->a({-href => href(action=>"commitdiff",
+				                       hash=>$hash_parent)},
+				        esc_html($hash_parent_short)) .
+				')';
+		} elsif (!$co{'parent'}) {
+			# --root commitdiff
+			$formats_nav .= ' (initial)';
+		} elsif (scalar @{$co{'parents'}} == 1) {
+			# single parent commit
+			$formats_nav .=
+				' (parent: ' .
+				$cgi->a({-href => href(action=>"commitdiff",
+				                       hash=>$co{'parent'})},
+				        esc_html(substr($co{'parent'}, 0, 7))) .
+				')';
+		} else {
+			# merge commit
+			$formats_nav .=
+				' (merge: ' .
+				join(' ', map {
+					$cgi->a({-href => href(action=>"commitdiff",
+					                       hash=>$_)},
+					        esc_html(substr($_, 0, 7)));
+				} @{$co{'parents'}} ) .
+				')';
+		}
+	}
+
 	if (!defined $hash_parent) {
 		$hash_parent = $co{'parent'} || '--root';
 	}
@@ -3317,10 +3362,6 @@ sub git_commitdiff {
 	if ($format eq 'html') {
 		my $refs = git_get_references();
 		my $ref = format_ref_marker($refs, $co{'id'});
-		my $formats_nav =
-			$cgi->a({-href => href(action=>"commitdiff_plain",
-			                       hash=>$hash, hash_parent=>$hash_parent)},
-			        "raw");
 
 		git_header_html(undef, $expires);
 		git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
-- 
1.4.2.1

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2006-10-29  2:10 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-22 22:37 [PATCH] gitweb: Add "next" link to commitdiff view Jakub Narebski
2006-10-22 22:43 ` Jakub Narebski
2006-10-22 23:16 ` Junio C Hamano
2006-10-22 23:41   ` Jakub Narebski
2006-10-23 22:08   ` [PATCH 2/1] gitweb: Use fixed string for "next" link in " Jakub Narebski
2006-10-23 23:21     ` Petr Baudis
2006-10-24  9:04       ` [PATCH 2/1 (amend)] " Jakub Narebski
2006-10-24  9:17         ` Junio C Hamano
2006-10-24  9:28           ` Jakub Narebski
2006-10-24 11:49     ` [PATCH 2/1] " Petr Baudis
2006-10-24 11:59       ` Jakub Narebski
2006-10-24 15:27         ` Petr Baudis
2006-10-24 17:17       ` Junio C Hamano
2006-10-24 17:26         ` Petr Baudis
2006-10-24 18:27           ` Junio C Hamano
2006-10-24 18:37             ` Jakub Narebski
2006-10-28 16:10 ` [PATCH] gitweb: Add "next" link to " Jakub Narebski
2006-10-28 19:00   ` Junio C Hamano
2006-10-29  1:50   ` Luben Tuikov
2006-10-29  1:58     ` Jakub Narebski
2006-10-29  2:04       ` Luben Tuikov
2006-10-29  2:10         ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).