threads / patch / 5646

patch, 6 partsgitweb: Link to tree instead of snapshot in shortlog

Subject: [PATCH 2/6] gitweb: Link to tree instead of snapshot in shortlog

## tl;dr

12 messages between Sep 22, 2006 and Sep 23, 2006. Diffs are folded; open one to read it.

replies: 11people: 3as markdown or json

Petr Baudis· Sep 22, 2006, 01:19 UTC · lore

[PATCH 1/6] gitweb: More per-view navigation bar links

Navigation bars in various views were empty or missed important items that should have been there, e.g. getting a snapshot in tree view or log of ancestry in commit view...

This feeble patch attempts to consolidate that.
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |   42 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 38 insertions(+), 4 deletions(-)
Show changes to gitweb/gitweb.perl +38 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0d2ff82..87df7bb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2444,6 +2444,9 @@ sub git_blame2 {
 		$cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
 		        "blob") .
 		" | " .
+		$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
+			"history") .
+		" | " .
 		$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
 		        "head");
 	git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
@@ -2510,6 +2513,9 @@ sub git_blame {
 		$cgi->a({-href => href(action=>"blob", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
 		        "blob") .
 		" | " .
+		$cgi->a({-href => href(action=>"history", hash=>$hash, hash_base=>$hash_base, file_name=>$file_name)},
+			"history") .
+		" | " .
 		$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
 		        "head");
 	git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
@@ -2685,6 +2691,10 @@ sub git_blob {
 					" | ";
 			}
 			$formats_nav .=
+				$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
+				                       hash=>$hash, file_name=>$file_name)},
+				        "history") .
+				" | " .
 				$cgi->a({-href => href(action=>"blob_plain",
 				                       hash=>$hash, file_name=>$file_name)},
 				        "plain") .
@@ -2720,6 +2730,9 @@ sub git_blob {
 }
 
 sub git_tree {
+	my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
+	my $have_snapshot = (defined $ctype && defined $suffix);
+
 	if (!defined $hash) {
 		$hash = git_get_head_hash($project);
 		if (defined $file_name) {
@@ -2743,7 +2756,23 @@ sub git_tree {
 	my $base = "";
 	my ($have_blame) = gitweb_check_feature('blame');
 	if (defined $hash_base && (my %co = parse_commit($hash_base))) {
-		git_print_page_nav('tree','', $hash_base);
+		my @views_nav = ();
+		if (defined $file_name) {
+			push @views_nav,
+				$cgi->a({-href => href(action=>"history", hash_base=>$hash_base,
+				                       hash=>$hash, file_name=>$file_name)},
+				        "history"),
+				$cgi->a({-href => href(action=>"tree",
+				                       hash_base=>"HEAD", file_name=>$file_name)},
+				        "head");
+		}
+		if ($have_snapshot) {
+			# FIXME: Should be available when we have no hash base as well.
+			push @views_nav,
+				$cgi->a({-href => href(action=>"snapshot")},
+					"snapshot");
+		}
+		git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
 		git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
 	} else {
 		undef $hash_base;
@@ -2888,17 +2917,22 @@ sub git_commit {
 	my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
 	my $have_snapshot = (defined $ctype && defined $suffix);
 
-	my $formats_nav = '';
+	my @views_nav = ();
 	if (defined $file_name && defined $co{'parent'}) {
 		my $parent = $co{'parent'};
-		$formats_nav .=
+		push @views_nav,
 			$cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)},
 			        "blame");
 	}
+	if (defined $co{'parent'}) {
+		push @views_nav,
+			$cgi->a({-href => href(action=>"shortlog", hash=>$hash)}, "shortlog"),
+			$cgi->a({-href => href(action=>"log", hash=>$hash)}, "log");
+	}
 	git_header_html(undef, $expires);
 	git_print_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
 	                   $hash, $co{'tree'}, $hash,
-	                   $formats_nav);
+	                   join (' | ', @views_nav));
 
 	if (defined $co{'parent'}) {
 		git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
Petr Baudis· Sep 22, 2006, 01:19 UTC · re: Petr Baudis · lore
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |    9 ++-------
 1 files changed, 2 insertions(+), 7 deletions(-)
Show changes to gitweb/gitweb.perl +2 −7
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 87df7bb..1b1653a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1976,9 +1976,6 @@ sub git_shortlog_body {
 	# uses global variable $project
 	my ($revlist, $from, $to, $refs, $extra) = @_;
 
-	my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
-	my $have_snapshot = (defined $ctype && defined $suffix);
-
 	$from = 0 unless defined $from;
 	$to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
 
@@ -2004,10 +2001,8 @@ sub git_shortlog_body {
 		print "</td>\n" .
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
-		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
-		if ($have_snapshot) {
-			print " | " .  $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
-		}
+		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") . " | " .
+		      $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree");
 		print "</td>\n" .
 		      "</tr>\n";
 	}
Petr Baudis· Sep 22, 2006, 01:19 UTC · re: Petr Baudis · lore

[PATCH 3/6] gitweb: Link to latest tree from the head line in heads list

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Show changes to gitweb/gitweb.perl +2 −1
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1b1653a..0a91394 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2164,7 +2164,8 @@ sub git_heads_body {
 		      "</td>\n" .
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(action=>"shortlog", hash=>$tag{'name'})}, "shortlog") . " | " .
-		      $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") .
+		      $cgi->a({-href => href(action=>"log", hash=>$tag{'name'})}, "log") . " | " .
+		      $cgi->a({-href => href(action=>"tree", hash=>$tag{'name'}, hash_base=>$tag{'name'})}, "tree") .
 		      "</td>\n" .
 		      "</tr>";
 	}
Petr Baudis· Sep 22, 2006, 01:19 UTC · re: Petr Baudis · lore

[PATCH 4/6] gitweb: Link to associated tree from a particular log item in full log view

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Show changes to gitweb/gitweb.perl +2 −0
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0a91394..45a5fbf 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2873,6 +2873,8 @@ sub git_log {
 		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") .
 		      " | " .
 		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
+		      " | " .
+		      $cgi->a({-href => href(action=>"tree", hash=>$commit), hash_base=>$commit}, "tree") .
 		      "<br/>\n" .
 		      "</div>\n" .
 		      "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
Junio C Hamano· Sep 22, 2006, 04:18 UTC · re: Petr Baudis · lore

Re: [PATCH 4/6] gitweb: Link to associated tree from a particular log item in full log view

I presume you are running this version at repo.or.cz, but

(1) go to http://repo.or.cz/?p=stgit.git;a=log (2) pick "tree" of one of the commits (3) go browser-back, then pick "tree" from the top navbar

The resulting tree view of (2) lacks navbar while (3) looks much saner.

You do not have the tree object name available in git_log to generate an URL with both h and hb, and getting to it is an extra work.

This would fix this particular breakage.
Show changes to gitweb/gitweb.perl +3 −3
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 34ef3fc..8c0fdf3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2732,9 +2732,9 @@ sub git_tree {
 			my $base = $hash_base || $hash;
 			$hash = git_get_hash_by_path($base, $file_name, "tree");
 		}
-		if (!defined $hash_base) {
-			$hash_base = $hash;
-		}
+	}
+	if (!defined $hash_base) {
+		$hash_base = $hash;
 	}
 	$/ = "\0";
 	open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
Petr Baudis· Sep 22, 2006, 23:13 UTC · re: Junio C Hamano · lore

Re: [PATCH 4/6] gitweb: Link to associated tree from a particular log item in full log view

Dear diary, on Fri, Sep 22, 2006 at 06:18:09AM CEST, I got a letter where Junio C Hamano <junkio@cox.net> said that...

Show 8 quoted lines
> I presume you are running this version at repo.or.cz, but
> 
> (1) go to http://repo.or.cz/?p=stgit.git;a=log
> (2) pick "tree" of one of the commits
> (3) go browser-back, then pick "tree" from the top navbar
> 
> The resulting tree view of (2) lacks navbar while (3) looks much
> saner.
Oops. It's trivial typo:
Show changes to gitweb/gitweb.perl +1 −1
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d2366c7..c5f3810 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2880,7 +2880,7 @@ sub git_log {
 		      " | " .
 		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
 		      " | " .
-		      $cgi->a({-href => href(action=>"tree", hash=>$commit), hash_base=>$commit}, "tree") .
+		      $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
 		      "<br/>\n" .
 		      "</div>\n" .
 		      "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .

> You do not have the tree object name available in git_log to
> generate an URL with both h and hb, and getting to it is an
> extra work.

Well using commit hash as a tree id works just fine...

> This would fix this particular breakage.

My knowledge of gitweb.perl innards isn't good enough for me to safely
ack/nak a change such deep down the chain.
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
Junio C Hamano· Sep 23, 2006, 00:44 UTC · re: Petr Baudis · lore

Re: [PATCH 4/6] gitweb: Link to associated tree from a particular log item in full log view

Petr Baudis <pasky@suse.cz> writes:
Show 21 quoted lines
> Oops. It's trivial typo:
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index d2366c7..c5f3810 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -2880,7 +2880,7 @@ sub git_log {
>  		      " | " .
>  		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
>  		      " | " .
> -		      $cgi->a({-href => href(action=>"tree", hash=>$commit), hash_base=>$commit}, "tree") .
> +		      $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
>  		      "<br/>\n" .
>  		      "</div>\n" .
>  		      "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
>
>> You do not have the tree object name available in git_log to
>> generate an URL with both h and hb, and getting to it is an
>> extra work.
>
> Well using commit hash as a tree id works just fine...

I agree that change is much safer. Will apply with an appropriate log message and attribution. No need to resend.

Jakub Narebski· Sep 23, 2006, 08:59 UTC · re: Junio C Hamano · lore

Re: [PATCH 4/6] gitweb: Link to associated tree from a particular log item in full log view

Junio C Hamano wrote:
Show 26 quoted lines
> Petr Baudis <pasky@suse.cz> writes:
> 
>> Oops. It's trivial typo:
>>
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index d2366c7..c5f3810 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -2880,7 +2880,7 @@ sub git_log {
>>                    " | " .
>>                    $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
>>                    " | " .
>> -                  $cgi->a({-href => href(action=>"tree", hash=>$commit), hash_base=>$commit}, "tree") .
>> +                  $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
>>                    "<br/>\n" .
>>                    "</div>\n" .
>>                    "<i>" . esc_html($co{'author_name'}) .  " [$ad{'rfc2822'}]</i><br/>\n" .
>>
>>> You do not have the tree object name available in git_log to
>>> generate an URL with both h and hb, and getting to it is an
>>> extra work.
>>
>> Well using commit hash as a tree id works just fine...
> 
> I agree that change is much safer.  Will apply with an
> appropriate log message and attribution.  No need to resend.

I think that hash_base without hash should be enough. But I'm not sure if it is. Well, commit hash is tree-ish...

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Petr Baudis· Sep 22, 2006, 01:19 UTC · re: Petr Baudis · lore

[PATCH 5/6] gitweb: Rename "plain" labels to "raw"

I don't have much preference either way and as far as I'm concerned, it may go the other way as well. Consistency is what is important.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to gitweb/gitweb.perl +4 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 45a5fbf..7b44c28 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2693,14 +2693,14 @@ sub git_blob {
 				" | " .
 				$cgi->a({-href => href(action=>"blob_plain",
 				                       hash=>$hash, file_name=>$file_name)},
-				        "plain") .
+				        "raw") .
 				" | " .
 				$cgi->a({-href => href(action=>"blob",
 				                       hash_base=>"HEAD", file_name=>$file_name)},
 				        "head");
 		} else {
 			$formats_nav .=
-				$cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "plain");
+				$cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw");
 		}
 		git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
 		git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
@@ -3109,7 +3109,7 @@ sub git_blobdiff {
 			                       hash=>$hash, hash_parent=>$hash_parent,
 			                       hash_base=>$hash_base, hash_parent_base=>$hash_parent_base,
 			                       file_name=>$file_name, file_parent=>$file_parent)},
-			        "plain");
+			        "raw");
 		git_header_html(undef, $expires);
 		if (defined $hash_base && (my %co = parse_commit($hash_base))) {
 			git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
@@ -3212,7 +3212,7 @@ sub git_commitdiff {
 		my $formats_nav =
 			$cgi->a({-href => href(action=>"commitdiff_plain",
 			                       hash=>$hash, hash_parent=>$hash_parent)},
-			        "plain");
+			        "raw");
 
 		git_header_html(undef, $expires);
 		git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
Jakub Narebski· Sep 22, 2006, 09:04 UTC · re: Petr Baudis · lore

Re: [PATCH 5/6] gitweb: Rename "plain" labels to "raw"

Petr Baudis wrote:
> I don't have much preference either way and as far as I'm concerned, it may
> go the other way as well. Consistency is what is important.

"raw" link was introduced in 25b7c18ecd9779158cb1c02572396bab22c6e0cf by Luben Tuikov. I'd rather use "plain"...

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Petr Baudis· Sep 22, 2006, 23:09 UTC · re: Jakub Narebski · lore

Re: [PATCH 5/6] gitweb: Rename "plain" labels to "raw"

Dear diary, on Fri, Sep 22, 2006 at 11:04:49AM CEST, I got a letter where Jakub Narebski <jnareb@gmail.com> said that...

Show 7 quoted lines
> Petr Baudis wrote:
> 
> > I don't have much preference either way and as far as I'm concerned, it may
> > go the other way as well. Consistency is what is important.
> 
> "raw" link was introduced in 25b7c18ecd9779158cb1c02572396bab22c6e0cf
> by Luben Tuikov. I'd rather use "plain"...

I kind of like "raw" more because it's IMHO more obvious what it exactly is (it could also mean some stripped-down HTML or whatever otherwise) and is more appropriate for things that actually are not plaintext, like pictures.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
Petr Baudis· Sep 22, 2006, 01:19 UTC · re: Petr Baudis · lore

[PATCH 6/6] gitweb: Relabel "head" as "HEAD"

"head" is a reference in refs/heads/, while those labels mean HEAD, the latest revision of the default branch.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
 gitweb/gitweb.perl |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to gitweb/gitweb.perl +4 −4
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 7b44c28..9c3546f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2444,7 +2444,7 @@ sub git_blame2 {
 			"history") .
 		" | " .
 		$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
-		        "head");
+		        "HEAD");
 	git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
 	git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
 	git_print_page_path($file_name, $ftype, $hash_base);
@@ -2513,7 +2513,7 @@ sub git_blame {
 			"history") .
 		" | " .
 		$cgi->a({-href => href(action=>"blame", file_name=>$file_name)},
-		        "head");
+		        "HEAD");
 	git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
 	git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
 	git_print_page_path($file_name, 'blob', $hash_base);
@@ -2697,7 +2697,7 @@ sub git_blob {
 				" | " .
 				$cgi->a({-href => href(action=>"blob",
 				                       hash_base=>"HEAD", file_name=>$file_name)},
-				        "head");
+				        "HEAD");
 		} else {
 			$formats_nav .=
 				$cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw");
@@ -2760,7 +2760,7 @@ sub git_tree {
 				        "history"),
 				$cgi->a({-href => href(action=>"tree",
 				                       hash_base=>"HEAD", file_name=>$file_name)},
-				        "head");
+				        "HEAD"),
 		}
 		if ($have_snapshot) {
 			# FIXME: Should be available when we have no hash base as well.

← back to recent threads