aboutsummaryrefslogtreecommitdiffstats
path: root/ui-snapshot.c
diff options
context:
space:
mode:
authorChristian Hesse2018-06-11 08:26:59 +0200
committerJason A. Donenfeld2018-06-27 18:13:00 +0200
commit2f8648ff7f5c7119ab035c134504f04eefe068fb (patch)
tree8fc7db6324b6483939cdfcf201793866877a5d92 /ui-snapshot.c
parent30a378b571c9f826d37c913b32b363f54a8997f4 (diff)
downloadcgit-2f8648ff7f5c7119ab035c134504f04eefe068fb.tar.gz
cgit-2f8648ff7f5c7119ab035c134504f04eefe068fb.tar.bz2
cgit-2f8648ff7f5c7119ab035c134504f04eefe068fb.zip
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>
Diffstat (limited to 'ui-snapshot.c')
-rw-r--r--ui-snapshot.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ui-snapshot.c b/ui-snapshot.c
index c7611e8..83ce6e8 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -86,11 +86,11 @@ static int write_tar_xz_archive(const char *hex, const char *prefix)
86} 86}
87 87
88const struct cgit_snapshot_format cgit_snapshot_formats[] = { 88const struct cgit_snapshot_format cgit_snapshot_formats[] = {
89 { ".zip", "application/x-zip", write_zip_archive, 0x01 }, 89 { ".tar", "application/x-tar", write_tar_archive },
90 { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 }, 90 { ".tar.gz", "application/x-gzip", write_tar_gzip_archive },
91 { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 }, 91 { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive },
92 { ".tar", "application/x-tar", write_tar_archive, 0x08 }, 92 { ".tar.xz", "application/x-xz", write_tar_xz_archive },
93 { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 }, 93 { ".zip", "application/x-zip", write_zip_archive },
94 { NULL } 94 { NULL }
95}; 95};
96 96
@@ -130,6 +130,11 @@ static const struct cgit_snapshot_format *get_format(const char *filename)
130 return NULL; 130 return NULL;
131} 131}
132 132
133const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f)
134{
135 return BIT(f - &cgit_snapshot_formats[0]);
136}
137
133static int make_snapshot(const struct cgit_snapshot_format *format, 138static int make_snapshot(const struct cgit_snapshot_format *format,
134 const char *hex, const char *prefix, 139 const char *hex, const char *prefix,
135 const char *filename) 140 const char *filename)
@@ -263,7 +268,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
263 } 268 }
264 269
265 f = get_format(filename); 270 f = get_format(filename);
266 if (!f || !(ctx.repo->snapshots & f->bit)) { 271 if (!f || !(ctx.repo->snapshots & cgit_snapshot_format_bit(f))) {
267 cgit_print_error_page(400, "Bad request", 272 cgit_print_error_page(400, "Bad request",
268 "Unsupported snapshot format: %s", filename); 273 "Unsupported snapshot format: %s", filename);
269 return; 274 return;