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

[PATCH 2/3] gitweb: Simplify object type detection in git_object()

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 7, 2008, 21:03 UTC
Message-ID
<1204923800-5923-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1204923800-5923-1-git-send-email-jnareb@gmail.com>
Taken from commit 7f9778b19b07601ae8134fc4ff23b7bf7cac28bd by Gerrit Pape
  "gitweb: choose appropriate view for file type if a= parameter missing"

Contrary to previous version it does not find 'h' (hash) parameter value if it is not set, and only 'hb' (hash_base) and 'f' (file_name) parameters are provided, resulting perhaps in slightly less efficient URLs, but also one which more closely follow what was requested.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   34 ++++++----------------------------
 1 files changed, 6 insertions(+), 28 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a76c4ac..f507a5a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4768,42 +4768,20 @@ sub git_object {
 
 	# - hash or hash_base alone
 	if ($hash || ($hash_base && !defined $file_name)) {
-		my $object_id = $hash || $hash_base;
-
-		my $git_command = git_cmd_str();
-		open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
-			or die_error('404 Not Found', "Object does not exist");
-		$type = <$fd>;
-		chomp $type;
-		close $fd
-			or die_error('404 Not Found', "Object does not exist");
+		$type = git_get_type($hash || $hash_base);
 
 	# - hash_base and file_name
 	} elsif ($hash_base && defined $file_name) {
-		$file_name =~ s,/+$,,;
+		$type = git_get_type("$hash_base:$file_name");
 
-		system(git_cmd(), "cat-file", '-e', $hash_base) == 0
-			or die_error('404 Not Found', "Base object does not exist");
-
-		# here errors should not hapen
-		open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name
-			or die_error(undef, "Open git-ls-tree failed");
-		my $line = <$fd>;
-		close $fd;
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 4 in “gitweb: Improved treatment of links with unknown object type”
  1. 0/3 gitweb: Improved treatment of links with unknown object typeJakub Narebski, Mar 7, 2008
  2. 1/3 gitweb: Redirect to appropriate view if 'a=' parameter is missingJakub Narebski, Mar 7, 2008
  3. 2/3 gitweb: Simplify object type detection in git_object()Jakub Narebski, Mar 7, 2008
  4. 3/3 gitweb: Make 'object' action implicit by using no action URLJakub Narebski, Mar 7, 2008

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.