Diff options
| -rw-r--r-- | MANUAL.txt | 5 | |
| -rw-r--r-- | source/ui-snapshot.c | 13 | |
| -rw-r--r-- | source/ui-snapshot.h | 3 | |
| -rwxr-xr-x | tests/t0205-config.sh | 19 |
4 files changed, 38 insertions, 2 deletions
@@ -551,7 +551,10 @@ snapshots:: Text which specifies the default set of snapshot formats that cgit generates links for. The value is a space-separated list of zero or more of the values "tar", "tar.gz", "tar.bz2", "tar.lz", "tar.xz", "tar.zst" - and "zip". The special value "all" enables all snapshot formats. All + and "zip", and any other name in it is ignored with a warning. The + special value "all" enables all snapshot formats. A value that starts + with a number other than "0" is the legacy form and enables "tar" alone + whatever follows the number, while "0" enables none. All compressors use default settings. Some settings can be influenced with environment variables, for example set ZSTD_CLEVEL=10 in the web server environment for higher (but slower) zstd compression. A ref with a slash diff --git a/source/ui-snapshot.c b/source/ui-snapshot.c index 333bce6..910bee6 100644 --- a/source/ui-snapshot.c +++ b/source/ui-snapshot.c @@ -13,6 +13,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "cgit.h" +#include "config.h" #include "filter.h" #include "html.h" #include "shared.h" @@ -321,6 +322,7 @@ int cgit_parse_snapshots_mask(const char *str) struct string_list_item *item; const struct cgit_snapshot_format *f; int mask = 0; + int len; // A number is the legacy form of this setting and is still taken // ahead of the named forms below. @@ -340,6 +342,17 @@ int cgit_parse_snapshots_mask(const char *str) break; } } + // A 0 is the legacy form offering none, and stays quiet. + if (f->suffix || !strcmp(item->string, "0")) + continue; + // The first line alone, since a git config value can hold a + // newline that would forge a log line of its own. + len = (int)strcspn(item->string, "\n"); + if (config_origin.file) + fprintf(stderr, "[cgit] Ignoring unknown snapshot format %.*s in %s line %d\n", + len, item->string, config_origin.file, config_origin.line); + else + fprintf(stderr, "[cgit] Ignoring unknown snapshot format %.*s\n", len, item->string); } string_list_clear(&tokens, 0); diff --git a/source/ui-snapshot.h b/source/ui-snapshot.h index 12241a9..3edc9a9 100644 --- a/source/ui-snapshot.h +++ b/source/ui-snapshot.h @@ -29,7 +29,8 @@ extern unsigned cgit_snapshot_format_bit(const struct cgit_snapshot_format *f); * Turn a cgitrc snapshots value into a mask over cgit_snapshot_formats. A * plain non-zero number is the legacy boolean form and enables plain tar * alone, the word all enables every format, and otherwise the value is a - * space separated list of suffixes. + * space separated list of suffixes, where a name matching no format is + * logged with the file and line it came from. */ extern int cgit_parse_snapshots_mask(const char *str); diff --git a/tests/t0205-config.sh b/tests/t0205-config.sh index 5044148..129b8de 100755 --- a/tests/t0205-config.sh +++ b/tests/t0205-config.sh @@ -179,6 +179,25 @@ test_expect_success 'a word in a scanned git config is reported' ' grep "Reading hide=true in $PWD/wordscan/foo.git/config line $line as 0, since it is not a whole number" err ' +# A snapshot format name that matches nothing used to drop out without a +# word, so a typo read like a format left off on purpose. The legacy 0 for +# none stays quiet, and a leading number other than 0 still means tar alone. +test_expect_success 'an unknown snapshot format is reported' ' + cgitrc_repo snaprc snap "snapshots=tar zap tar.gz" \ + "repo.path=$PWD/repos/foo/.git" "repo.snapshots=tar 0 tar.gzz" && + cgit_rc snaprc "url=snap/commit/" >tmp 2>err && + grep "href=./snap/snapshot/snap-master.tar.>" tmp && + ! grep "snap-master.tar.gz" tmp && + grep "Ignoring unknown snapshot format zap in $PWD/snaprc line 3" err && + grep "Ignoring unknown snapshot format tar.gzz in $PWD/snaprc line 6" err && + test_line_count = 2 err && + cgitrc_repo legacyrc snap "snapshots=2 zip" "repo.path=$PWD/repos/foo/.git" && + cgit_rc legacyrc "url=snap/commit/" >tmp 2>err && + grep "href=./snap/snapshot/snap-master.tar.>" tmp && + ! grep "snap-master.zip" tmp && + test_must_be_empty err +' + # The error page names the repository alone, so the log gets the path that # would not open, once for the request. test_expect_success 'a repository that will not open is logged with its path' ' |
