Skip to content

Commit b02bd7a

Browse files
Oblomovgitster
authored andcommitted
gitweb: generate project/action/hash URLs
When generating path info URLs, reduce the number of CGI parameters by embedding action and hash_parent:filename or hash in the path. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Acked-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d8c2882 commit b02bd7a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

gitweb/gitweb.perl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,14 +731,41 @@ (%)
731731

732732
my ($use_pathinfo) = gitweb_check_feature('pathinfo');
733733
if ($use_pathinfo) {
734-
# use PATH_INFO for project name
734+
# try to put as many parameters as possible in PATH_INFO:
735+
# - project name
736+
# - action
737+
# - hash or hash_base:filename
738+
739+
# When the script is the root DirectoryIndex for the domain,
740+
# $href here would be something like http://gitweb.example.com/
741+
# Thus, we strip any trailing / from $href, to spare us double
742+
# slashes in the final URL
743+
$href =~ s,/$,,;
744+
745+
# Then add the project name, if present
735746
$href .= "/".esc_url($params{'project'}) if defined $params{'project'};
736747
delete $params{'project'};
737748

738-
# Summary just uses the project path URL
739-
if (defined $params{'action'} && $params{'action'} eq 'summary') {
749+
# Summary just uses the project path URL, any other action is
750+
# added to the URL
751+
if (defined $params{'action'}) {
752+
$href .= "/".esc_url($params{'action'}) unless $params{'action'} eq 'summary';
740753
delete $params{'action'};
741754
}
755+
756+
# Finally, we put either hash_base:file_name or hash
757+
if (defined $params{'hash_base'}) {
758+
$href .= "/".esc_url($params{'hash_base'});
759+
if (defined $params{'file_name'}) {
760+
$href .= ":".esc_url($params{'file_name'});
761+
delete $params{'file_name'};
762+
}
763+
delete $params{'hash'};
764+
delete $params{'hash_base'};
765+
} elsif (defined $params{'hash'}) {
766+
$href .= "/".esc_url($params{'hash'});
767+
delete $params{'hash'};
768+
}
742769
}
743770

744771
# now encode the parameters explicitly

0 commit comments

Comments
 (0)