gitweb: Improved treatment of links with unknown object type
cover gitweb: Improved treatment of links with unknown object type
This series of patches make gitweb URLs without a= parameter to use 'object' view, which finds type of requested onject and redirects (HTTP redirect) to proper view, instead of just displaying this view. git_object() in turn is simplified to use git_get_type() subroutine, as was used for URLs without a=. As 'object' view is just internal implementation use no a= parameter instead of a=object for gitweb URLs for which type of object (and therefore view to be used) is not known.
I guess that this series of patches can be squashed into single commit, but I think that having them split into parts makes reviewing them easier; it also makes possible to drop indivisual commits, for example dropping second commit would leave gitweb with modified finding type of an object.
Shortlog:
=========
Jakub Narebski (3):
gitweb: Redirect to appropriate view if 'a=' parameter is missing
gitweb: Simplify object type detection in git_object()
gitweb: Make 'object' action implicit by using no action URL
Diffstat:
=========
gitweb/gitweb.perl | 45 +++++++++++---------------------------------- 1 files changed, 11 insertions(+), 34 deletions(-)
This series removes more than adds mainly thanks to second patch in the series which simplifies git_object() type detection code.
Signature · 3 lines
Jakub Narebski ShadeHawk on #git Poland
PATCH 1/3 gitweb: Redirect to appropriate view if 'a=' parameter is missing
Instead of finding the type of object specified by 'h', or 'hb' and 'f' parameters and substituting it for action (view), as it was done since commit 7f9778b by Gerrit Pape, use 'object' view which would find type and REDIRECT to URL with 'a' parameter filled in.
This way user will have URL with action filled in the browser history, or when adding bookmark. This hopefully would make server get less requests without 'a' parameter set, thus reducing a bit load on server.
Note that the code to find object type in git_object() subroutine is a bit more complicated than was used for URL without 'a=' parameter.
---
The fact that using 'object' view changes a bit behavior is addressed in second commit in this series, where git_commit() is made to do what dispatch for URL without a=, but with h= or hb= and f= did before.
gitweb/gitweb.perl | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +3 -4
@@ -564,10 +564,9 @@ my %actions = ( ); if (!defined $action) { - if (defined $hash) { - $action = git_get_type($hash); - } elsif (defined $hash_base && defined $file_name) { - $action = git_get_type("$hash_base:$file_name"); + if (defined $hash || + (defined $hash_base && defined $file_name)) { + $action = 'object'; } elsif (defined $project) { $action = 'summary'; } else {
Signature · 1 line
1.5.4.3.453.gc1ad83
PATCH 2/3 gitweb: Simplify object type detection in git_object()
In reply to Jakub NarebskiTaken 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.
--- gitweb/gitweb.perl | 34 ++++++---------------------------- 1 files changed, 6 insertions(+), 28 deletions(-)
gitweb/gitweb.perl +2 -18
@@ -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;
PATCH 3/3 gitweb: Make 'object' action implicit by using no action URL
In reply to Jakub NarebskiIn format_log_line_html() subroutine gitweb makes (shortened) SHA-1 of an object into hyperlink, as a very simple comittags support. Usually, but not always this link is to 'commit' object.
In git_print_tree_entry() subroutine gitweb provides link to the target of symbolic link, for easier navigation, if it looks like it leads inside tree. Gitweb doesn't know if it leads to directory ('tree' object), or an ordinary file ('blob' object), or if it is broken. (It cn also in rare cases lead to submodule, which now will result in the 'commit' view).
Both of those cases used generic 'object' action to find correct view on request, only when link were followed. Now we make use of the fact that gitweb tries to find correct action if none provided; it uses 'object' action if action is not provided, but project and either hash or hash_base and filename are.
---
Hmmmm... isn't this commit message too long for such a simple change?
gitweb/gitweb.perl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +2 -2
@@ -1072,7 +1072,7 @@ sub format_log_line_html { if ($line =~ m/([0-9a-fA-F]{8,40})/) { my $hash_text = $1; my $link = - $cgi->a({-href => href(action=>"object", hash=>$hash_text), + $cgi->a({-href => href(hash=>$hash_text), -class => "text"}, $hash_text); $line =~ s/$hash_text/$link/; }
@@ -2912,7 +2912,7 @@ sub git_print_tree_entry { my $norm_target = normalize_link_target($link_target, $basedir, $hash_base); if (defined $norm_target) { print " -> " . - $cgi->a({-href => href(action=>"object", hash_base=>$hash_base, + $cgi->a({-href => href(hash_base=>$hash_base, file_name=>$norm_target), -title => $norm_target}, esc_path($link_target)); } else {
Signature · 1 line
1.5.4.3.453.gc1ad83