about summary refs log tree commit diff stats
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
parentsnapshot: support special value 'all' to enable all formats (diff)
downloadcgit-2f8648ff7f5c7119ab035c134504f04eefe068fb.tar.gz
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>
-rw-r--r--cgit.c2
-rw-r--r--cgit.h4
-rw-r--r--shared.c2
-rw-r--r--ui-shared.c2
-rw-r--r--ui-snapshot.c17
5 files changed, 17 insertions, 10 deletions
diff --git a/cgit.c b/cgit.c index d2f7b9c..ca0a89c 100644 --- a/cgit.c +++ b/cgit.c
@@ -765,7 +765,7 @@ static char *build_snapshot_setting(int bitmap)
765 struct strbuf result = STRBUF_INIT; 765 struct strbuf result = STRBUF_INIT;
766 766
767 for (f = cgit_snapshot_formats; f->suffix; f++) { 767 for (f = cgit_snapshot_formats; f->suffix; f++) {
768 if (f->bit & bitmap) { 768 if (cgit_snapshot_format_bit(f) & bitmap) {
769 if (result.len) 769 if (result.len)
770 strbuf_addch(&result, ' '); 770 strbuf_addch(&result, ' ');
771 strbuf_addstr(&result, f->suffix); 771 strbuf_addstr(&result, f->suffix);
diff --git a/cgit.h b/cgit.h index a686390..0798dc5 100644 --- a/cgit.h +++ b/cgit.h
@@ -46,6 +46,8 @@
46 */ 46 */
47#define PAGE_ENCODING "UTF-8" 47#define PAGE_ENCODING "UTF-8"
48 48
49#define BIT(x) (1U << (x))
50
49typedef void (*configfn)(const char *name, const char *value); 51typedef void (*configfn)(const char *name, const char *value);
50typedef void (*filepair_fn)(struct diff_filepair *pair); 52typedef void (*filepair_fn)(struct diff_filepair *pair);
51typedef void (*linediff_fn)(char *line, int len); 53typedef void (*linediff_fn)(char *line, int len);
@@ -314,7 +316,6 @@ struct cgit_snapshot_format {
314 const char *suffix; 316 const char *suffix;
315 const char *mimetype; 317 const char *mimetype;
316 write_archive_fn_t write_func; 318 write_archive_fn_t write_func;
317 int bit;
318}; 319};
319 320
320extern const char *cgit_version; 321extern const char *cgit_version;
@@ -376,6 +377,7 @@ extern const char *cgit_repobasename(const char *reponame);
376extern int cgit_parse_snapshots_mask(const char *str); 377extern int cgit_parse_snapshots_mask(const char *str);
377extern const struct object_id *cgit_snapshot_get_sig(const char *ref, 378extern const struct object_id *cgit_snapshot_get_sig(const char *ref,
378 const struct cgit_snapshot_format *f); 379 const struct cgit_snapshot_format *f);
380extern const unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f);
379 381
380extern int cgit_open_filter(struct cgit_filter *filter, ...); 382extern int cgit_open_filter(struct cgit_filter *filter, ...);
381extern int cgit_close_filter(struct cgit_filter *filter); 383extern int cgit_close_filter(struct cgit_filter *filter);
diff --git a/shared.c b/shared.c index 0a11e68..d59ae7e 100644 --- a/shared.c +++ b/shared.c
@@ -400,7 +400,7 @@ int cgit_parse_snapshots_mask(const char *str)
400 for (f = cgit_snapshot_formats; f->suffix; f++) { 400 for (f = cgit_snapshot_formats; f->suffix; f++) {
401 if (!strcmp(item->string, f->suffix) || 401 if (!strcmp(item->string, f->suffix) ||
402 !strcmp(item->string, f->suffix + 1)) { 402 !strcmp(item->string, f->suffix + 1)) {
403 rv |= f->bit; 403 rv |= cgit_snapshot_format_bit(f);
404 break; 404 break;
405 } 405 }
406 } 406 }
diff --git a/ui-shared.c b/ui-shared.c index 8a786e0..e8c0723 100644 --- a/ui-shared.c +++ b/ui-shared.c
@@ -1127,7 +1127,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
1127 1127
1128 prefixlen = filename.len; 1128 prefixlen = filename.len;
1129 for (f = cgit_snapshot_formats; f->suffix; f++) { 1129 for (f = cgit_snapshot_formats; f->suffix; f++) {
1130 if (!(repo->snapshots & f->bit)) 1130 if (!(repo->snapshots & cgit_snapshot_format_bit(f)))
1131 continue; 1131 continue;
1132 strbuf_setlen(&filename, prefixlen); 1132 strbuf_setlen(&filename, prefixlen);
1133 strbuf_addstr(&filename, f->suffix); 1133 strbuf_addstr(&filename, f->suffix);
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;