git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] gitweb: Add '..' (up directory) to tree view if applicable

From
Jakub Narebski <jnareb@gmail.com>
Date
Oct 21, 2006, 15:54 UTC
Message-ID
<200610211754.44981.jnareb@gmail.com>
In-Reply-To
<200610211750.49188.jnareb@gmail.com>

Adds '..' (up directory) link at the top of "tree" view listing, if both $hash_base and $file_name are provided, and $file_name is not empty string.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This was meant to send as single patch...
 gitweb/gitweb.perl |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 126cf3c..c9e57f0 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2871,6 +2871,30 @@ sub git_tree {
 	print "<div class=\"page_body\">\n";
 	print "<table cellspacing=\"0\">\n";
 	my $alternate = 1;
+	# '..' (top directory) link if possible
+	if (defined $hash_base &&
+	    defined $file_name && $file_name =~ m![^/]+$!) {
+		if ($alternate) {
+			print "<tr class=\"dark\">\n";
+		} else {
+			print "<tr class=\"light\">\n";
+		}
+		$alternate ^= 1;
+
+		my $up = $file_name;
+		$up =~ s!/?[^/]+$!!;
+		undef $up unless $up;
+		# based on git_print_tree_entry
+		print '<td class="mode">' . mode_str('040000') . "</td>\n";
+		print '<td class="list">';
+		print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
+		                             file_name=>$up)},
+		              "..");
+		print "</td>\n";
+		print "<td class=\"link\"></td>\n";
+
+		print "</tr>\n";
+	}
 	foreach my $line (@entries) {
 		my %t = parse_ls_tree_line($line, -z => 1);
 
-- 
1.4.2.1
Previous: Jakub Narebski
Message 11 of 11 in “gitweb: Improving tree view (plus some cleanups)”
  1. 0/4 gitweb: Improving tree view (plus some cleanups)Jakub Narebski, Oct 21, 2006
  2. 1/4 gitweb: Whitespace cleanup - tabs are for indent, spaces are for align (2)Jakub Narebski, Oct 21, 2006
  3. Junio C HamanoOct 22, 2006
  4. Jakub NarebskiOct 22, 2006
  5. Linus TorvaldsOct 22, 2006
  6. Jakub NarebskiOct 22, 2006
  7. Junio C HamanoOct 22, 2006
  8. Luben TuikovOct 22, 2006
  9. 2/4 gitweb: Do not esc_html $basedir argument to git_print_tree_entryJakub Narebski, Oct 21, 2006
  10. 3/4 gitweb: Improve git_print_page_pathJakub Narebski, Oct 21, 2006
  11. 4/4 gitweb: Add '..' (up directory) to tree view if applicableJakub Narebski, Oct 21, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.