# [PATCHv4 2/3] gitweb: support to globally disable a snapshot format

1 messages from 2009-08-05 to 2009-08-05. Participants: Mark A Rada.
Thread: https://gitlist.dev/t/20403

## Mark A Rada, 2009-08-05 13:19

Subject: [PATCHv4 2/3] gitweb: support to globally disable a snapshot format
Message-ID: <CDA93DD6-D1FA-4F8A-84D8-FA9A8493FBF9@uwaterloo.ca>
URL: https://gitlist.dev/e/CDA93DD6-D1FA-4F8A-84D8-FA9A8493FBF9%40uwaterloo.ca

```
Now XZ is disabled by default.


--
Mark A Rada (ferrous26)
marada@uwaterloo.ca


------->8------------
From: Mark Rada <marada@uwaterloo.ca>
Date: Sat, 1 Aug 2009 13:24:03 -0400
Subject: [PATCH 2/3] gitweb: support to globally disable a snapshot  
format

I added an optional variable, 'disabled', to to the
$known_snapshot_formats keys so that a Gitweb administrator can
globally enable or disable a specific format for snapshots.

All formats are enabled by default, except for the txz format
(explained below), because project specific overriding is disabled by
default.

The txz format is disabled as it is still new and has relatively high
resource requirements (ref. 4f1c1fb73b4cdaf4bcf817fb2af99bd71f1ca61f).

Signed-off-by: Mark Rada <marada@uwaterloo.ca>
---
  gitweb/gitweb.perl |   11 ++++++++---
  1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 3398163..5a628fa 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -160,7 +160,8 @@ our %known_snapshot_formats = (
  	# 	'suffix' => filename suffix,
  	# 	'format' => --format for git-archive,
  	# 	'compressor' => [compressor command and arguments]
-	# 	                (array reference, optional)}
+	# 	                (array reference, optional),
+	# 	'disabled' => boolean (optional)}
  	#
  	'tgz' => {
  		'display' => 'tar.gz',
@@ -181,7 +182,8 @@ our %known_snapshot_formats = (
  		'type' => 'application/x-xz',
  		'suffix' => '.tar.xz',
  		'format' => 'tar',
-		'compressor' => ['xz']},
+		'compressor' => ['xz'],
+		'disabled' => 1},

  	'zip' => {
  		'display' => 'zip',
@@ -502,7 +504,8 @@ sub filter_snapshot_fmts {
  		exists $known_snapshot_format_aliases{$_} ?
  		       $known_snapshot_format_aliases{$_} : $_} @fmts;
  	@fmts = grep {
-		exists $known_snapshot_formats{$_} } @fmts;
+		exists $known_snapshot_formats{$_} &&
+		!$known_snapshot_formats{$_}{'disabled'}} @fmts;
  }

  our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
@@ -5171,6 +5174,8 @@ sub git_snapshot {
  		die_error(400, "Unknown snapshot format");
  	} elsif (!grep($_ eq $format, @snapshot_fmts)) {
  		die_error(403, "Unsupported snapshot format");
+	} elsif ($known_snapshot_formats{$format}{'disabled'}) {
+		die_error(403, "Snapshot format not allowed");
  	}

  	if (!defined $hash) {
-- 
1.6.4

```
