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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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;
-
-		#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'
-		unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
-			die_error('404 Not Found', "File or directory for given base does not exist");
-		}
-		$type = $2;
-		$hash = $3;
 	} else {
 		die_error('404 Not Found', "Not enough information to find object");
 	}
 
-	print $cgi->redirect(-uri => href(action=>$type, -full=>1,
-	                                  hash=>$hash, hash_base=>$hash_base,
-	                                  file_name=>$file_name),
+	die_error('404 Not Found', "Object not found")
+		unless $type;
+
+	print $cgi->redirect(-uri => href(action=>$type, -full=>1, -replay=>1),
 	                     -status => '302 Found');
 }
 
-- 
1.5.4.3.453.gc1ad83

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux