[PATCH 3/4] Make number of columns in stat overview configurable

Julius Plenz plenz at cis.fu-berlin.de
Tue Oct 30 14:07:17 CET 2012


I'm pretty sure this constitutes a violation of how the data structure
cgit_period's use was intended, but that's much easier than passing the
"count" parameter to all the functions that need it.

Signed-off-by: Julius Plenz <plenz at cis.fu-berlin.de>
---
 cgit.c     |  2 ++
 cgit.h     |  1 +
 ui-stats.c | 26 +++++++++++++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/cgit.c b/cgit.c
index f1105fb..04637ab 100644
--- a/cgit.c
+++ b/cgit.c
@@ -305,6 +305,8 @@ static void querystring_cb(const char *name, const char *value)
 		ctx.qry.showmsg = atoi(value);
 	} else if (!strcmp(name, "period")) {
 		ctx.qry.period = xstrdup(value);
+	} else if (!strcmp(name, "nr_periods")) {
+		ctx.qry.nr_periods = atoi(value);
 	} else if (!strcmp(name, "ss")) {
 		ctx.qry.ssdiff = atoi(value);
 		ctx.qry.has_ssdiff = 1;
diff --git a/cgit.h b/cgit.h
index 5692224..4a3f528 100644
--- a/cgit.h
+++ b/cgit.h
@@ -161,6 +161,7 @@ struct cgit_query {
 	int context;
 	int ignorews;
 	char *vpath;
+	int nr_periods;
 };
 
 struct cgit_config {
diff --git a/ui-stats.c b/ui-stats.c
index 59f4c1e..4ca8c4a 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -128,10 +128,10 @@ static char *pretty_year(struct tm *tm)
 }
 
 struct cgit_period periods[] = {
-	{'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week},
-	{'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month},
-	{'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
-	{'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year},
+	{'w', "week", 24, 4, trunc_week, dec_week, inc_week, pretty_week},
+	{'m', "month", 24, 4, trunc_month, dec_month, inc_month, pretty_month},
+	{'q', "quarter", 24, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter},
+	{'y', "year", 24, 4, trunc_year, dec_year, inc_year, pretty_year},
 };
 
 /* Given a period code or name, return a period index (1, 2, 3 or 4)
@@ -363,7 +363,7 @@ void cgit_show_stats(struct cgit_context *ctx)
 {
 	struct string_list authors;
 	struct cgit_period *period;
-	int top, i;
+	int top, cols, i;
 	const char *code = "w";
 
 	if (ctx->qry.period)
@@ -379,6 +379,13 @@ void cgit_show_stats(struct cgit_context *ctx)
 				     period->name));
 		return;
 	}
+
+	cols = ctx->qry.nr_periods;
+	if(!cols || cols > period->max_periods)
+		cols = period->count;
+	else
+		period->count = cols;
+
 	authors = collect_stats(ctx, period);
 	qsort(authors.items, authors.nr, sizeof(struct string_list_item),
 		cmp_total_commits);
@@ -408,6 +415,15 @@ void cgit_show_stats(struct cgit_context *ctx)
 	html_intoption(100, "100", top);
 	html_intoption(-1, "all", top);
 	html("</select></td></tr>");
+
+	html("<tr><td class='label'>Columns:</td>");
+	html("<td class='ctrl'><select name='nr_periods' onchange='this.form.submit();'>");
+	html_intoption(1, "1", cols);
+	html_intoption(4, "4", cols);
+	html_intoption(12, "12", cols);
+	html_intoption(24, "24", cols);
+	html("</select></td></tr>");
+
 	html("<tr><td/><td class='ctrl'>");
 	html("<noscript><input type='submit' value='Reload'/></noscript>");
 	html("</td></tr></table>");
-- 
1.7.12.3-zedat





More information about the CGit mailing list