From: Jakub Narebski Date: Fri, 07 Mar 2008 21:03:19 GMT Subject: [PATCH 2/3] gitweb: Simplify object type detection in git_object() 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 --- 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;