Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Report a max-stats value that names no period
A value cgit does not know as a period turns the statistics page off,
so a typo such as "decade" read the same as leaving stats off on
purpose. The empty value stays quiet because a cached repolist writes
it for a repository that turned stats off.
Diffstat (limited to 'source')
| -rw-r--r-- | source/cgit.c | 29 |
1 file changed, 27 insertions, 2 deletions
diff --git a/source/cgit.c b/source/cgit.c index 12ed19e..5a0f2e3 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -575,6 +575,31 @@ static void parse_date_setting(const char *format, struct date_mode *mode) } } +/* + * A max-stats value that names no period turns the statistics page off, the + * same as leaving it unset, so a typo is logged with where it was written. + * An empty value and "0" turn the page off on purpose, and a cached repolist + * writes the empty one, so those stay quiet. + */ +static int config_stats_period(const char *value) +{ + int period = cgit_find_stats_period(value, NULL); + int len; + + if (period || !*value || !strcmp(value, "0")) + return period; + // 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(value, "\n"); + if (config_origin.file) + fprintf(stderr, "[cgit] Turning statistics off for max-stats=%.*s in %s line %d, since it names no period\n", + len, value, config_origin.file, config_origin.line); + else + fprintf(stderr, "[cgit] Turning statistics off for max-stats=%.*s, since it names no period\n", + len, value); + return period; +} + static void apply_config(const char *name, const char *value) { const char *arg; @@ -666,7 +691,7 @@ static void apply_config(const char *name, const char *value) else if (!strcmp(name, "enable-cache-list")) ctx.cfg.enable_cache_list = config_int(name, value); else if (!strcmp(name, "max-stats")) - ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); + ctx.cfg.max_stats = config_stats_period(value); else if (!strcmp(name, "cache-size")) ctx.cfg.cache_size = config_int(name, value); else if (!strcmp(name, "cache-root")) @@ -1367,7 +1392,7 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu if (!strcmp(value, "topo")) repo->commit_sort = 2; } else if (!strcmp(name, "max-stats")) - repo->max_stats = cgit_find_stats_period(value, NULL); + repo->max_stats = config_stats_period(value); else if (!strcmp(name, "module-link")) repo->module_link = cgit_strdup_first_line(value); else if (skip_prefix(name, "module-link.", &path)) { |
