cgit

commit 2f8648ff7f5c7119ab035c134504f04eefe068fb

Author: Christian Hesse <mail@eworm.de>

snapshot: strip bit from struct cgit_snapshot_format

We had a static bit value in struct cgit_snapshot_format. We do not rely
on it and things can be calculated on the fly. So strip it.

Signed-off-by: Christian Hesse <mail@eworm.de>

 cgit.c | 2 +-
 cgit.h | 4 +++-
 shared.c | 2 +-
 ui-shared.c | 2 +-
 ui-snapshot.c | 17 +++++++++++------


diff --git a/cgit.c b/cgit.c
index d2f7b9c7bbb4f30e0c2ee813c79b50466e1a5d3e..ca0a89c0a17d7b23bfb7facb2299ca537242ad9d 100644
--- a/cgit.c
+++ b/cgit.c
@@ -765,7 +765,7 @@ 	const struct cgit_snapshot_format *f;
 	struct strbuf result = STRBUF_INIT;
 
 	for (f = cgit_snapshot_formats; f->suffix; f++) {
-		if (f->bit & bitmap) {
+		if (cgit_snapshot_format_bit(f) & bitmap) {
 			if (result.len)
 				strbuf_addch(&result, ' ');
 			strbuf_addstr(&result, f->suffix);




diff --git a/cgit.h b/cgit.h
index a686390499b218d027cfbfdeb69397d1aa672ba3..0798dc5ce2e688775bd671cc610a0bf8f7941720 100644
--- a/cgit.h
+++ b/cgit.h
@@ -46,6 +46,8 @@  * Default encoding
  */
 #define PAGE_ENCODING "UTF-8"
 
+#define BIT(x)	(1U << (x))
+
 typedef void (*configfn)(const char *name, const char *value);
 typedef void (*filepair_fn)(struct diff_filepair *pair);
 typedef void (*linediff_fn)(char *line, int len);
@@ -314,7 +316,6 @@ struct cgit_snapshot_format {
 	const char *suffix;
 	const char *mimetype;
 	write_archive_fn_t write_func;
-	int bit;
 };
 
 extern const char *cgit_version;
@@ -376,6 +377,7 @@
 extern int cgit_parse_snapshots_mask(const char *str);
 extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
 						     const struct cgit_snapshot_format *f);
+extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
 
 extern int cgit_open_filter(struct cgit_filter *filter, ...);
 extern int cgit_close_filter(struct cgit_filter *filter);




diff --git a/shared.c b/shared.c
index 0a11e68aae4981cf9f972a0913ac2522014fe41a..d59ae7ef9cf5f68046322178c8766eebb5f193e3 100644
--- a/shared.c
+++ b/shared.c
@@ -400,7 +400,7 @@ 	for_each_string_list_item(item, &tokens) {
 		for (f = cgit_snapshot_formats; f->suffix; f++) {
 			if (!strcmp(item->string, f->suffix) ||
 			    !strcmp(item->string, f->suffix + 1)) {
-				rv |= f->bit;
+				rv |= cgit_snapshot_format_bit(f);
 				break;
 			}
 		}




diff --git a/ui-shared.c b/ui-shared.c
index 8a786e0a3e27e63d1e6f19c28b85e0fc1c326673..e8c0723c75fc84958c230b1eee3824382ca69f66 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1127,7 +1127,7 @@ 		cgit_compose_snapshot_prefix(&filename, basename, ref);
 
 	prefixlen = filename.len;
 	for (f = cgit_snapshot_formats; f->suffix; f++) {
-		if (!(repo->snapshots & f->bit))
+		if (!(repo->snapshots & cgit_snapshot_format_bit(f)))
 			continue;
 		strbuf_setlen(&filename, prefixlen);
 		strbuf_addstr(&filename, f->suffix);




diff --git a/ui-snapshot.c b/ui-snapshot.c
index c7611e88947edfed93b497bd654703e3c8987efe..83ce6e86243fd3105f24bef20a71924a0e8173e0 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -86,11 +86,11 @@ 	return write_compressed_tar_archive(hex, prefix, argv);
 }
 
 const struct cgit_snapshot_format cgit_snapshot_formats[] = {
-	{ ".zip", "application/x-zip", write_zip_archive, 0x01 },
-	{ ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 },
-	{ ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 },
-	{ ".tar", "application/x-tar", write_tar_archive, 0x08 },
-	{ ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 },
+	{ ".tar",	"application/x-tar",	write_tar_archive	},
+	{ ".tar.gz",	"application/x-gzip",	write_tar_gzip_archive	},
+	{ ".tar.bz2",	"application/x-bzip2",	write_tar_bzip2_archive	},
+	{ ".tar.xz",	"application/x-xz",	write_tar_xz_archive	},
+	{ ".zip",	"application/x-zip",	write_zip_archive	},
 	{ NULL }
 };
 
@@ -128,6 +128,11 @@ 		if (ends_with(filename, fmt->suffix))
 			return fmt;
 	}
 	return NULL;
+}
+
+const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
+{
+	return BIT(f - &cgit_snapshot_formats[0]);
 }
 
 static int make_snapshot(const struct cgit_snapshot_format *format,
@@ -263,7 +268,7 @@ 		filename = adj_filename;
 	}
 
 	f = get_format(filename);
-	if (!f || !(ctx.repo->snapshots & f->bit)) {
+	if (!f || !(ctx.repo->snapshots & cgit_snapshot_format_bit(f))) {
 		cgit_print_error_page(400, "Bad request",
 				"Unsupported snapshot format: %s", filename);
 		return;