@matheusbsbs / matheus-bagliano / commits / b02bd7a632
Fork 0

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>

Giuseppe Bilotta committed Oct 21, 2008 at 21:34 UTC b02bd7a6323a85f9feedd9c8cd7d7401021dfb11
1 file changed +30 -3
gitweb/gitweb.perl
+30 -3
@@ -731,14 +731,41 @@ sub href (%) {
731
732 my ($use_pathinfo) = gitweb_check_feature('pathinfo');
733 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
746 $href .= "/".esc_url($params{'project'}) if defined $params{'project'};
747 delete $params{'project'};
748
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';
753 delete $params{'action'};
754 }
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 + }
769 }
770
771 # now encode the parameters explicitly