@matheusbsbs / matheus-bagliano / commits / 8db49a7f6f
Fork 0

gitweb: generate parent..current URLs

If use_pathinfo is enabled, href now creates links that contain paths in the form $project/$action/oldhash:/oldname..newhash:/newname for actions that use hash_parent etc. If any of the filename contains two consecutive dots, it's kept as a CGI parameter since the resulting path would otherwise be ambiguous. 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 8db49a7f6f272ecb72c75a172e9753f3981488ce
1 file changed +24 -4
gitweb/gitweb.perl
+24 -4
@@ -766,6 +766,7 @@ sub href (%) {
766 # try to put as many parameters as possible in PATH_INFO:
767 # - project name
768 # - action
769 + # - hash_parent or hash_parent_base:/file_parent
770 # - hash or hash_base:/filename
771
772 # When the script is the root DirectoryIndex for the domain,
@@ -785,17 +786,36 @@ sub href (%) {
786 delete $params{'action'};
787 }
788
788 - # Finally, we put either hash_base:/file_name or hash
789 + # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
790 + # stripping nonexistent or useless pieces
791 + $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
792 + || $params{'hash_parent'} || $params{'hash'});
793 if (defined $params{'hash_base'}) {
790 - $href .= "/".esc_url($params{'hash_base'});
791 - if (defined $params{'file_name'}) {
794 + if (defined $params{'hash_parent_base'}) {
795 + $href .= esc_url($params{'hash_parent_base'});
796 + # skip the file_parent if it's the same as the file_name
797 + delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
798 + if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
799 + $href .= ":/".esc_url($params{'file_parent'});
800 + delete $params{'file_parent'};
801 + }
802 + $href .= "..";
803 + delete $params{'hash_parent'};
804 + delete $params{'hash_parent_base'};
805 + } elsif (defined $params{'hash_parent'}) {
806 + $href .= esc_url($params{'hash_parent'}). "..";
807 + delete $params{'hash_parent'};
808 + }
809 +
810 + $href .= esc_url($params{'hash_base'});
811 + if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
812 $href .= ":/".esc_url($params{'file_name'});
813 delete $params{'file_name'};
814 }
815 delete $params{'hash'};
816 delete $params{'hash_base'};
817 } elsif (defined $params{'hash'}) {
798 - $href .= "/".esc_url($params{'hash'});
818 + $href .= esc_url($params{'hash'});
819 delete $params{'hash'};
820 }
821 }