{"thread":{"id":"16128","subject":"[PATHv3 0/3] PATH_INFO snapshot formats","startedAt":"2008-11-02T09:21:36Z","lastAt":"2008-11-03T06:17:40Z","messageCount":5,"participants":["Giuseppe Bilotta","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"94641","messageId":"1225617699-30004-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16128","inReplyTo":null,"subject":"[PATHv3 0/3] PATH_INFO snapshot formats","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-11-02T09:21:36Z","receivedAt":"2008-11-02T09:21:36Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"The following three patches allow gitweb to read (and emit) PATH_INFO\nURLs with embedded snapshot_format information. This eliminates one\nfor CGI parameter when PATH_INFO is enabled, and also offers a more\nuser-friendly URL for snapshots.\n\nThe first patch is actually rather independent from the other two: it\ncollects the definition (and calculation) of the array of allowed\nsnapshot into a global variable.\n\nGiuseppe Bilotta (3):\n  gitweb: make the supported snapshot formats array global\n  gitweb: retrieve snapshot format from PATH_INFO\n  gitweb: embed snapshot format parameter in PATH_INFO\n\n gitweb/gitweb.perl |   70 ++++++++++++++++++++++++++++++++++++++++++++++------\n 1 files changed, 62 insertions(+), 8 deletions(-)\n"},{"id":"94642","messageId":"1225617699-30004-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16128","inReplyTo":"1225617699-30004-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATHv3 1/3] gitweb: make the supported snapshot formats array global","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-11-02T09:21:37Z","receivedAt":"2008-11-02T09:21:37Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"The array of supported snapshot format is used and defined (with two\ndifferent names) in two routines, one of which (format_snapshot_links)\nis often called multiple times per page.\n\nSimplify code and speed up page generation by making the array global.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   15 +++++++--------\n 1 files changed, 7 insertions(+), 8 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 9d1af7e..8441912 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -721,6 +721,10 @@ if (defined $searchtext) {\n our $git_dir;\n $git_dir = \"$projectroot/$project\" if $project;\n \n+# list of supported snapshot formats\n+our @snapshot_fmts = gitweb_check_feature('snapshot');\n+@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);\n+\n # dispatch\n if (!defined $action) {\n \tif (defined $hash) {\n@@ -1647,8 +1651,6 @@ sub format_diff_line {\n # linked.  Pass the hash of the tree/commit to snapshot.\n sub format_snapshot_links {\n \tmy ($hash) = @_;\n-\tmy @snapshot_fmts = gitweb_check_feature('snapshot');\n-\t@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);\n \tmy $num_fmts = @snapshot_fmts;\n \tif ($num_fmts > 1) {\n \t\t# A parenthesized list of links bearing format names.\n@@ -4850,20 +4852,17 @@ sub git_tree {\n }\n \n sub git_snapshot {\n-\tmy @supported_fmts = gitweb_check_feature('snapshot');\n-\t@supported_fmts = filter_snapshot_fmts(@supported_fmts);\n-\n \tmy $format = $input_params{'snapshot_format'};\n-\tif (!@supported_fmts) {\n+\tif (!@snapshot_fmts) {\n \t\tdie_error(403, \"Snapshots not allowed\");\n \t}\n \t# default to first supported snapshot format\n-\t$format ||= $supported_fmts[0];\n+\t$format ||= $snapshot_fmts[0];\n \tif ($format !~ m/^[a-z0-9]+$/) {\n \t\tdie_error(400, \"Invalid snapshot format parameter\");\n \t} elsif (!exists($known_snapshot_formats{$format})) {\n \t\tdie_error(400, \"Unknown snapshot format\");\n-\t} elsif (!grep($_ eq $format, @supported_fmts)) {\n+\t} elsif (!grep($_ eq $format, @snapshot_fmts)) {\n \t\tdie_error(403, \"Unsupported snapshot format\");\n \t}\n \n-- \n1.5.6.5\n"},{"id":"94644","messageId":"1225617699-30004-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16128","inReplyTo":"1225617699-30004-2-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATHv3 2/3] gitweb: retrieve snapshot format from PATH_INFO","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-11-02T09:21:38Z","receivedAt":"2008-11-02T09:21:38Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"We parse requests for $project/snapshot/$head.$sfx as equivalent to\n$project/snapshot/$head?sf=$sfx, where $sfx is any of the known\n(although not necessarily supported) snapshot formats (or its default\nsuffix).\n\nThe filename for the resulting package preserves the requested\nextensions (so asking for a .tgz gives a .tgz, and asking for a .tar.gz\ngives a .tar.gz), although for obvious reasons it doesn't preserve the\nbasename (git/snapshot/next.tgz returns a file names git-next.tgz).\n\nThis introduces a potential case for ambiguity if a project has a head\nthat ends with a snapshot-like suffix (.zip, .tgz, .tar.gz, etc) and the\nsf CGI parameter is not present; however, gitweb only produces URLs with\nthe sf parameter currently, so this is only a potential issue for\nhand-coded URLs for extremely unusual project.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   38 ++++++++++++++++++++++++++++++++++++++\n 1 files changed, 38 insertions(+), 0 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 8441912..0a41be5 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -616,6 +616,44 @@ sub evaluate_path_info {\n \t\t\t$input_params{'hash_parent'} ||= $parentrefname;\n \t\t}\n \t}\n+\n+\t# for the snapshot action, we allow URLs in the form\n+\t# $project/snapshot/$hash.ext\n+\t# where .ext determines the snapshot and gets removed from the\n+\t# passed $refname to provide the $hash.\n+\t#\n+\t# To be able to tell that $refname includes the format extension, we\n+\t# require the following two conditions to be satisfied:\n+\t# - the hash input parameter MUST have been set from the $refname part\n+\t#   of the URL (i.e. they must be equal)\n+\t# - the snapshot format MUST NOT have been defined already (e.g. from\n+\t#   CGI parameter sf)\n+\t# It's also useless to try any matching unless $refname has a dot,\n+\t# so we check for that too\n+\tif ($input_params{'action'} eq 'snapshot' &&\n+\t\tdefined $refname && index($refname, '.') != -1 &&\n+\t\t$refname eq $input_params{'hash'} &&\n+\t\t!defined $input_params{'snapshot_format'}) {\n+\t\t# We loop over the known snapshot formats, checking for\n+\t\t# extensions. Allowed extensions are both the defined suffix\n+\t\t# (which includes the initial dot already) and the snapshot\n+\t\t# format key itself, with a prepended dot\n+\t\twhile (my ($fmt, %opt) = each %known_snapshot_formats) {\n+\t\t\tmy $hash = $refname;\n+\t\t\tmy $sfx;\n+\t\t\t$hash =~ s/(\\Q$opt{'suffix'}\\E|\\Q.$fmt\\E)$//;\n+\t\t\tnext unless $sfx = $1;\n+\t\t\t# a valid suffix was found, so set the snapshot format\n+\t\t\t# and reset the hash parameter\n+\t\t\t$input_params{'snapshot_format'} = $fmt;\n+\t\t\t$input_params{'hash'} = $hash;\n+\t\t\t# we also set the format suffix to the one requested\n+\t\t\t# in the URL: this way a request for e.g. .tgz returns\n+\t\t\t# a .tgz instead of a .tar.gz\n+\t\t\t$known_snapshot_formats{$fmt}{'suffix'} = $sfx;\n+\t\t\tlast;\n+\t\t}\n+\t}\n }\n evaluate_path_info();\n \n-- \n1.5.6.5\n"},{"id":"94643","messageId":"1225617699-30004-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"16128","inReplyTo":"1225617699-30004-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATHv3 3/3] gitweb: embed snapshot format parameter in PATH_INFO","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2008-11-02T09:21:39Z","receivedAt":"2008-11-02T09:21:39Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"When PATH_INFO is active, get rid of the sf CGI parameter by embedding\nthe snapshot format information in the PATH_INFO URL, in the form of an\nappropriate extension.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n gitweb/gitweb.perl |   17 +++++++++++++++++\n 1 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 0a41be5..d2484ab 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -810,6 +810,7 @@ sub href (%) {\n \t\t#   - action\n \t\t#   - hash_parent or hash_parent_base:/file_parent\n \t\t#   - hash or hash_base:/filename\n+\t\t#   - the snapshot_format as an appropriate suffix\n \n \t\t# When the script is the root DirectoryIndex for the domain,\n \t\t# $href here would be something like http://gitweb.example.com/\n@@ -821,6 +822,10 @@ sub href (%) {\n \t\t$href .= \"/\".esc_url($params{'project'}) if defined $params{'project'};\n \t\tdelete $params{'project'};\n \n+\t\t# since we destructively absorb parameters, we keep this\n+\t\t# boolean that remembers if we're handling a snapshot\n+\t\tmy $is_snapshot = $params{'action'} eq 'snapshot';\n+\n \t\t# Summary just uses the project path URL, any other action is\n \t\t# added to the URL\n \t\tif (defined $params{'action'}) {\n@@ -860,6 +865,18 @@ sub href (%) {\n \t\t\t$href .= esc_url($params{'hash'});\n \t\t\tdelete $params{'hash'};\n \t\t}\n+\n+\t\t# If the action was a snapshot, we can absorb the\n+\t\t# snapshot_format parameter too\n+\t\tif ($is_snapshot) {\n+\t\t\tmy $fmt = $params{'snapshot_format'};\n+\t\t\t# snapshot_format should always be defined when href()\n+\t\t\t# is called, but just in case some code forgets, we\n+\t\t\t# fall back to the default\n+\t\t\t$fmt ||= $snapshot_fmts[0];\n+\t\t\t$href .= $known_snapshot_formats{$fmt}{'suffix'};\n+\t\t\tdelete $params{'snapshot_format'};\n+\t\t}\n \t}\n \n \t# now encode the parameters explicitly\n-- \n1.5.6.5\n"},{"id":"94717","messageId":"7v7i7lwcxn.fsf@gitster.siamese.dyndns.org","threadId":"16128","inReplyTo":"1225617699-30004-3-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATHv3 2/3] gitweb: retrieve snapshot format from PATH_INFO","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-03T06:17:40Z","receivedAt":"2008-11-03T06:17:40Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> writes:\n\n> +\t# It's also useless to try any matching unless $refname has a dot,\n> +\t# so we check for that too\n> +\tif ($input_params{'action'} eq 'snapshot' &&\n\nThis broke t9500 because $input_params{'action'} can be undef.  What I'll\nbe pushing out on 'pu' has a fixup on it (I am rewinding and rebuilding\n'pu' right now so it will be a while).\n\nNext time, please make sure that your patches pass the tests before sending\nthem out.\n\nThanks.\n"}]}