gitweb: embed snapshot format parameter in PATH_INFO
When PATH_INFO is active, get rid of the sf CGI parameter by embedding the snapshot format information in the PATH_INFO URL, in the form of an appropriate extension. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Nov 2, 2008 at 10:21 UTC
c752a0e00c7f122dbca72552b1bf193e5850a1b1
1 file changed
+17
gitweb/gitweb.perl
+17
@@ -811,6 +811,7 @@ sub href (%) {
811
# - action
812
# - hash_parent or hash_parent_base:/file_parent
813
# - hash or hash_base:/filename
814
+ # - the snapshot_format as an appropriate suffix
815
816
# When the script is the root DirectoryIndex for the domain,
817
# $href here would be something like http://gitweb.example.com/
@@ -822,6 +823,10 @@ sub href (%) {
823
$href .= "/".esc_url($params{'project'}) if defined $params{'project'};
824
delete $params{'project'};
825
826
+ # since we destructively absorb parameters, we keep this
827
+ # boolean that remembers if we're handling a snapshot
828
+ my $is_snapshot = $params{'action'} eq 'snapshot';
829
+
830
# Summary just uses the project path URL, any other action is
831
# added to the URL
832
if (defined $params{'action'}) {
@@ -861,6 +866,18 @@ sub href (%) {
866
$href .= esc_url($params{'hash'});
867
delete $params{'hash'};
868
}
869
+
870
+ # If the action was a snapshot, we can absorb the
871
+ # snapshot_format parameter too
872
+ if ($is_snapshot) {
873
+ my $fmt = $params{'snapshot_format'};
874
+ # snapshot_format should always be defined when href()
875
+ # is called, but just in case some code forgets, we
876
+ # fall back to the default
877
+ $fmt ||= $snapshot_fmts[0];
878
+ $href .= $known_snapshot_formats{$fmt}{'suffix'};
879
+ delete $params{'snapshot_format'};
880
+ }
881
}
882
883
# now encode the parameters explicitly