{"thread":{"id":"20338","subject":"[PATCH 2/2] gitweb: support to globally enable/disable a snapshot format","startedAt":"2009-08-01T17:46:41Z","lastAt":"2011-07-06T13:59:51Z","messageCount":3,"participants":["Mark A Rada","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"119350","messageId":"8E0889CB-8A0A-45A5-AF34-9643D4EEFCEF@uwaterloo.ca","threadId":"20338","inReplyTo":null,"subject":"[PATCH 2/2] gitweb: support to globally enable/disable a snapshot format","fromName":"Mark A Rada","fromEmail":"marada@uwaterloo.ca","sentAt":"2009-08-01T17:46:41Z","receivedAt":"2009-08-01T17:46:41Z","isPatch":true,"sender":{"key":"marada@uwaterloo.ca","avatar":"https://avatars.githubusercontent.com/u/38430?v=4"},"body":"On 1-Aug-09, at 4:14 AM, Jakub Narebski wrote:\n\n> \"J.H.\" <warthog19@eaglescrag.net> writes:\n>\n>> Well you can always call xz with -[1-9] to change the compression\n>> level (same as gzip and bzip2) though I think a full disabling would\n>> be 'more' preferable, though I'm not sure I like Jakub's suggestion  \n>> of\n>> just deleting it after the fact, it would work.\n> [...]\n>\n> The problem is that 'keys %known_snapshot_formats' serves also as list\n> of allowed snapshot formats, if project specific override is enabled.\n> We can add another optional flag ('disabled' => 1) if you don't want\n> to delete from %known_snapshot_formats in $GITWEB_CONFIG, though I\n> don't know if it is worth it.  Anyway such mechanism can be added, and\n> IMHO should be added, in a separate commit.\n\n\nIs this correct?\n\n\n--\nMark A Rada (ferrous26)\nmarada@uwaterloo.ca\n\n\n----------->8--------------\nFrom: Mark Rada <marada@uwaterloo.ca>\nDate: Sat, 1 Aug 2009 13:24:03 -0400\nSubject: [PATCH 2/2] gitweb: support to globally enable/disable a  \nsnapshot format\n\nI added an 'enabled' variable to to the $known_snapshot_format keys so\nthat a Gitweb administrator can globally enable or disable a specific\nformat for snapshots.\n\nAll formats are enabled by default because project specific overriding\nis disabled by default.\n\nSigned-off-by: Mark Rada <marada@uwaterloo.ca>\n---\n  gitweb/gitweb.perl |   14 ++++++++++----\n  1 files changed, 10 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 3398163..0a9cec6 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -167,27 +167,31 @@ our %known_snapshot_formats = (\n  \t\t'type' => 'application/x-gzip',\n  \t\t'suffix' => '.tar.gz',\n  \t\t'format' => 'tar',\n-\t\t'compressor' => ['gzip']},\n+\t\t'compressor' => ['gzip'],\n+\t\t'enabled' => 1},\n\n  \t'tbz2' => {\n  \t\t'display' => 'tar.bz2',\n  \t\t'type' => 'application/x-bzip2',\n  \t\t'suffix' => '.tar.bz2',\n  \t\t'format' => 'tar',\n-\t\t'compressor' => ['bzip2']},\n+\t\t'compressor' => ['bzip2'],\n+\t\t'enabled' => 1},\n\n  \t'txz' => {\n  \t\t'display' => 'tar.xz',\n  \t\t'type' => 'application/x-xz',\n  \t\t'suffix' => '.tar.xz',\n  \t\t'format' => 'tar',\n-\t\t'compressor' => ['xz']},\n+\t\t'compressor' => ['xz'],\n+\t\t'enabled' => 1},\n\n  \t'zip' => {\n  \t\t'display' => 'zip',\n  \t\t'type' => 'application/x-zip',\n  \t\t'suffix' => '.zip',\n-\t\t'format' => 'zip'},\n+\t\t'format' => 'zip',\n+\t\t'enabled' => 1},\n  );\n\n  # Aliases so we understand old gitweb.snapshot values in repository\n@@ -5171,6 +5175,8 @@ sub git_snapshot {\n  \t\tdie_error(400, \"Unknown snapshot format\");\n  \t} elsif (!grep($_ eq $format, @snapshot_fmts)) {\n  \t\tdie_error(403, \"Unsupported snapshot format\");\n+\t} elsif (!$known_snapshot_formats{$format}{'enabled'}) {\n+\t\tdie_error(403, \"Snapshot format not allowed\");\n  \t}\n\n  \tif (!defined $hash) {\n-- \n1.6.4\n"},{"id":"119351","messageId":"m3ljm3qud7.fsf@localhost.localdomain","threadId":"20338","inReplyTo":"8E0889CB-8A0A-45A5-AF34-9643D4EEFCEF@uwaterloo.ca","subject":"Re: [PATCH 2/2] gitweb: support to globally enable/disable a snapshot format","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-08-01T18:09:57Z","receivedAt":"2009-08-01T18:09:57Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"By the way, somehow [PATCH 2/2] doesn't look for me as if it was reply\nto [PATCH 1/2] email...\n\nMark A Rada <marada@uwaterloo.ca> writes:\n> On 1-Aug-09, at 4:14 AM, Jakub Narebski wrote:\n>> \"J.H.\" <warthog19@eaglescrag.net> writes:\n>>\n>>> Well you can always call xz with -[1-9] to change the compression\n>>> level (same as gzip and bzip2) though I think a full disabling would\n>>> be 'more' preferable, though I'm not sure I like Jakub's suggestion\n>>> of just deleting it after the fact, it would work.\n>> [...]\n>>\n>> The problem is that 'keys %known_snapshot_formats' serves also as list\n>> of allowed snapshot formats, if project specific override is enabled.\n>> We can add another optional flag ('disabled' => 1) if you don't want\n>> to delete from %known_snapshot_formats in $GITWEB_CONFIG, though I\n>> don't know if it is worth it.  Anyway such mechanism can be added, and\n>> IMHO should be added, in a separate commit.\n> \n> Is this correct?\n\nThanks for doing it.\n\nIt is correct, although I had in mind slightly different solution\n\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 3398163..0a9cec6 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -167,27 +167,31 @@ our %known_snapshot_formats = (\n>   \t'txz' => {\n>   \t\t'display' => 'tar.xz',\n>   \t\t'type' => 'application/x-xz',\n>   \t\t'suffix' => '.tar.xz',\n>   \t\t'format' => 'tar',\n> -\t\t'compressor' => ['xz']},\n> +\t\t'compressor' => ['xz'],\n> +\t\t'enabled' => 1},\n\nI'd rather use here, taking for example 'txz' as \"known but disabled\"\n\n  +\t\t'compressor' => ['xz'],\n  +\t\t'disabled' => 1},\n\n\n>   \t'zip' => {\n>   \t\t'display' => 'zip',\n>   \t\t'type' => 'application/x-zip',\n>   \t\t'suffix' => '.zip',\n> \t\t'format' => 'zip'},\n>   );\n\nAnd then you would not need to modify the rest of snapshot formats,\nmaking use of the fact that $hash{'key'} is false-ish, if 'key' does\nnot exist in hash.\n\nAlso, this should be documented at least in comments.\n \n>   # Aliases so we understand old gitweb.snapshot values in repository\n> @@ -5171,6 +5175,8 @@ sub git_snapshot {\n>   \t\tdie_error(400, \"Unknown snapshot format\");\n>   \t} elsif (!grep($_ eq $format, @snapshot_fmts)) {\n>   \t\tdie_error(403, \"Unsupported snapshot format\");\n> +\t} elsif (!$known_snapshot_formats{$format}{'enabled'}) {\n> +\t\tdie_error(403, \"Snapshot format not allowed\");\n\nThis would be modified then to read:\n\n  +\t} elsif ($known_snapshot_formats{$format}{'disabled'}) {\n  +\t\tdie_error(403, \"Snapshot format not allowed\");\n\nAlso, we want not only protect againts *using* known but disabled\nformat, but also do not display it as one of formats available, even\nif project specific override is supprted for snapshot, and projects\nlist it in gitweb.snapshot:\n\n@@ -509,7 +509,8 @@ sub filter_snapshot_fmts {\n \t\texists $known_snapshot_format_aliases{$_} ?\n \t\t       $known_snapshot_format_aliases{$_} : $_} @fmts;\n \t@fmts = grep {\n-\t\texists $known_snapshot_formats{$_} } @fmts;\n+\t\texists $known_snapshot_formats{$_} &&\n+\t\t!$known_snapshot_formats{$_}{'disabled'} } @fmts;\n }\n \n our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"++GITWEB_CONFIG++\";\n\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"170920","messageId":"m339ij5x3s.fsf@localhost.localdomain","threadId":"20338","inReplyTo":"8E0889CB-8A0A-45A5-AF34-9643D4EEFCEF@uwaterloo.ca","subject":"Re: [PATCH 2/2] gitweb: support to globally enable/disable a snapshot format","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2011-07-06T13:59:51Z","receivedAt":"2011-07-06T13:59:51Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Mark A Rada <marada@uwaterloo.ca> writes:\n> On 1-Aug-09, at 4:14 AM, Jakub Narebski wrote:\n>> \"J.H.\" <warthog19@eaglescrag.net> writes:\n>>\n>>> Well you can always call xz with -[1-9] to change the compression\n>>> level (same as gzip and bzip2) though I think a full disabling would\n>>> be 'more' preferable, though I'm not sure I like Jakub's suggestion\n>>> of just deleting it after the fact, it would work.\n>> [...]\n>>\n>> The problem is that 'keys %known_snapshot_formats' serves also as list\n>> of allowed snapshot formats, if project specific override is enabled.\n>> We can add another optional flag ('disabled' => 1) if you don't want\n>> to delete from %known_snapshot_formats in $GITWEB_CONFIG, though I\n>> don't know if it is worth it.  Anyway such mechanism can be added, and\n>> IMHO should be added, in a separate commit.\n> \n> Is this correct?\n\nThanks for doing it.\n\nIt is correct, although I had in mind slightly different solution\n\n> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n> index 3398163..0a9cec6 100755\n> --- a/gitweb/gitweb.perl\n> +++ b/gitweb/gitweb.perl\n> @@ -167,27 +167,31 @@ our %known_snapshot_formats = (\n>   \t'txz' => {\n>   \t\t'display' => 'tar.xz',\n>   \t\t'type' => 'application/x-xz',\n>   \t\t'suffix' => '.tar.xz',\n>   \t\t'format' => 'tar',\n> -\t\t'compressor' => ['xz']},\n> +\t\t'compressor' => ['xz'],\n> +\t\t'enabled' => 1},\n\nI'd rather use here, taking for example 'txz' as \"known but disabled\"\n\n  +\t\t'compressor' => ['xz'],\n  +\t\t'disabled' => 1},\n\n\n>   \t'zip' => {\n>   \t\t'display' => 'zip',\n>   \t\t'type' => 'application/x-zip',\n>   \t\t'suffix' => '.zip',\n> \t\t'format' => 'zip'},\n>   );\n\nAnd then you would not need to modify the rest of snapshot formats,\nmaking use of the fact that $hash{'key'} is false-ish, if 'key' does\nnot exist in hash.\n\nAlso, this should be documented at least in comments.\n \n>   # Aliases so we understand old gitweb.snapshot values in repository\n> @@ -5171,6 +5175,8 @@ sub git_snapshot {\n>   \t\tdie_error(400, \"Unknown snapshot format\");\n>   \t} elsif (!grep($_ eq $format, @snapshot_fmts)) {\n>   \t\tdie_error(403, \"Unsupported snapshot format\");\n> +\t} elsif (!$known_snapshot_formats{$format}{'enabled'}) {\n> +\t\tdie_error(403, \"Snapshot format not allowed\");\n\nThis would be modified then to read:\n\n  +\t} elsif ($known_snapshot_formats{$format}{'disabled'}) {\n  +\t\tdie_error(403, \"Snapshot format not allowed\");\n\nAlso, we want not only protect againts *using* known but disabled\nformat, but also do not display it as one of formats available, even\nif project specific override is supprted for snapshot, and projects\nlist it in gitweb.snapshot:\n\n@@ -509,7 +509,8 @@ sub filter_snapshot_fmts {\n \t\texists $known_snapshot_format_aliases{$_} ?\n \t\t       $known_snapshot_format_aliases{$_} : $_} @fmts;\n \t@fmts = grep {\n-\t\texists $known_snapshot_formats{$_} } @fmts;\n+\t\texists $known_snapshot_formats{$_} &&\n+\t\t!$known_snapshot_formats{$_}{'disabled'} } @fmts;\n }\n \n our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || \"++GITWEB_CONFIG++\";\n\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}