diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Fold `enable-stats` back into `max-stats`
A `max-stats` period enables the page again, as it did before v2.2.0, so one key does both jobs.
-rw-r--r--source/cgit.c6
-rw-r--r--source/cgit.h2
-rw-r--r--source/cmd.c2
-rw-r--r--source/shared.c1
-rw-r--r--source/ui-shared.c2
-rw-r--r--source/ui-stats.c7
-rw-r--r--source/ui-tree.c2
-rwxr-xr-xtests/t0112-stats.sh13
8 files changed, 12 insertions, 23 deletions
diff --git a/source/cgit.c b/source/cgit.c
index 72e36c8..0e0ea7c 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -255,8 +255,6 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
}
if (repo->snapshot_prefix)
fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix);
- if (repo->enable_stats != ctx.cfg.enable_stats)
- fprintf(f, "repo.enable-stats=%d\n", repo->enable_stats);
if (repo->max_stats != ctx.cfg.max_stats)
fprintf(f, "repo.max-stats=%s\n",
cgit_find_stats_periodname(repo->max_stats));
@@ -549,8 +547,6 @@ static void apply_config(const char *name, const char *value)
ctx.cfg.enable_filter_overrides = atoi(value);
else if (!strcmp(name, "enable-follow-links"))
ctx.cfg.enable_follow_links = atoi(value);
- else if (!strcmp(name, "enable-stats"))
- ctx.cfg.enable_stats = atoi(value);
else if (!strcmp(name, "enable-http-clone"))
ctx.cfg.enable_http_clone = atoi(value);
else if (!strcmp(name, "enable-index-links"))
@@ -1191,8 +1187,6 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
repo->enable_subject_links = atoi(value);
else if (!strcmp(name, "enable-html-serving"))
repo->enable_html_serving = atoi(value);
- else if (!strcmp(name, "enable-stats"))
- repo->enable_stats = atoi(value);
else if (!strcmp(name, "branch-sort")) {
if (!strcmp(value, "age"))
repo->branch_sort = 1;
diff --git a/source/cgit.h b/source/cgit.h
index bab41c5..fa52010 100644
--- a/source/cgit.h
+++ b/source/cgit.h
@@ -92,7 +92,6 @@ struct cgit_repo {
int enable_remote_branches;
int enable_subject_links;
int enable_html_serving;
- int enable_stats;
int max_stats;
int branch_sort;
int commit_sort;
@@ -218,7 +217,6 @@ struct cgit_config {
int enable_filter_overrides;
int enable_follow_links;
int enable_gitmodules_links;
- int enable_stats;
int enable_http_clone;
int enable_index_links;
int enable_index_owner;
diff --git a/source/cmd.c b/source/cmd.c
index 68c395a..b6b1c67 100644
--- a/source/cmd.c
+++ b/source/cmd.c
@@ -162,7 +162,7 @@ static void snapshot_fn(void)
static void stats_fn(void)
{
- if (ctx.repo->enable_stats)
+ if (ctx.repo->max_stats)
cgit_show_stats();
else
cgit_print_error_page(404, "Not Found", "Stats are disabled");
diff --git a/source/shared.c b/source/shared.c
index 37c21ae..43b8e56 100644
--- a/source/shared.c
+++ b/source/shared.c
@@ -224,7 +224,6 @@ struct cgit_repo *cgit_add_repo(const char *url)
repo->enable_remote_branches = ctx.cfg.enable_remote_branches;
repo->enable_subject_links = ctx.cfg.enable_subject_links;
repo->enable_html_serving = ctx.cfg.enable_html_serving;
- repo->enable_stats = ctx.cfg.enable_stats;
repo->max_stats = ctx.cfg.max_stats;
repo->branch_sort = ctx.cfg.branch_sort;
repo->commit_sort = ctx.cfg.commit_sort;
diff --git a/source/ui-shared.c b/source/ui-shared.c
index 5cf9428..74b5be0 100644
--- a/source/ui-shared.c
+++ b/source/ui-shared.c
@@ -625,7 +625,7 @@ static void print_repo_tabs(void)
tab_class("diff"), ctx.qry.head,
ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath);
html("</li>\n");
- if (ctx.repo->enable_stats) {
+ if (ctx.repo->max_stats) {
html("<li>");
cgit_stats_link("stats", "Commit activity", tab_class("stats"),
ctx.qry.head, ctx.qry.vpath);
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 134e4c2..97918e0 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -382,9 +382,8 @@ static void print_options_form(const struct cgit_period *period, int top)
html("<form method='get'>");
cgit_add_hidden_formfields(1, 0, "stats");
html("<table><tr><td colspan='2'></td></tr>\n");
- if (!ctx.repo->max_stats || ctx.repo->max_stats > 1) {
- choices = ctx.repo->max_stats ?
- ctx.repo->max_stats : (int)ARRAY_SIZE(periods);
+ if (ctx.repo->max_stats > 1) {
+ choices = ctx.repo->max_stats;
html("<tr><td class='label'>Period:</td>");
html("<td class='ctrl'><select name='period' data-autosubmit='1'>");
for (i = 0; i < choices; i++)
@@ -452,7 +451,7 @@ void cgit_show_stats(void)
"Unknown statistics type: %c", code[0]);
return;
}
- if (ctx.repo->max_stats && period_index > ctx.repo->max_stats) {
+ if (period_index > ctx.repo->max_stats) {
cgit_print_error_page(400, "Bad Request",
"Statistics type disabled: %s", period->name);
return;
diff --git a/source/ui-tree.c b/source/ui-tree.c
index b742b64..cbf783f 100644
--- a/source/ui-tree.c
+++ b/source/ui-tree.c
@@ -342,7 +342,7 @@ static void print_ls_row(const struct object_id *oid, const char *pathname,
cgit_log_link("log", NULL, "button", ctx.qry.head,
walk->rev, fullpath.buf, 0, NULL, NULL,
ctx.qry.showmsg, 0);
- if (ctx.repo->enable_stats)
+ if (ctx.repo->max_stats)
cgit_stats_link("stats", NULL, "button", ctx.qry.head,
fullpath.buf);
if (!S_ISGITLINK(mode))
diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh
index 262932c..4d61e6c 100755
--- a/tests/t0112-stats.sh
+++ b/tests/t0112-stats.sh
@@ -1,14 +1,14 @@
#!/bin/sh
-# Checks the per repository statistics page, which stays off until a config
-# turns it on and then reports commits per author. A second config caps the
-# period so that what max-stats takes out of the period selector is covered
+# Checks the per repository statistics page, which stays off until max-stats
+# turns it on and then reports commits per author. A second config sets a
+# finer max-stats so that what it takes out of the period selector is covered
# as well.
test_description='Check the statistics page'
. ./setup.sh
-# The shared test config sets no enable-stats, so this is what an untouched
+# The shared test config sets no max-stats, so this is what an untouched
# install does.
test_expect_success 'stats are off by default' '
cgit_url "foo/stats" >tmp &&
@@ -31,14 +31,13 @@ test_expect_success 'set up a stats config' '
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
- echo "enable-stats=1" &&
+ echo "max-stats=year" &&
echo "repo.url=stat" &&
echo "repo.path=$PWD/repos/pulse/.git"
} >statsrc &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
- echo "enable-stats=1" &&
echo "max-stats=month" &&
echo "repo.url=stat" &&
echo "repo.path=$PWD/repos/pulse/.git"
@@ -71,7 +70,7 @@ test_expect_success 'stats below a path stay a normal page' '
grep "<h2>Commits per author" tmp
'
-test_expect_success 'all four periods offered when max-stats is unset' '
+test_expect_success 'max-stats=year offers all four periods' '
statq "url=stat/stats/" >tmp &&
grep "<option value=.w." tmp &&
grep "<option value=.m." tmp &&