summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-09-13 20:02:07 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-09-13 20:02:07 (UTC)
commit92f6940975f6771f3a08d497c02575ee5bdc79da (patch) (side-by-side diff)
treec1c538b24e50be3bf63356acf246cda76b91c519
parent5f12e45fe3338095916a444ff106dd9fc9991d84 (diff)
parentee554849ac7209fa8f7486327ec9f3b370e4c876 (diff)
downloadcgit-92f6940975f6771f3a08d497c02575ee5bdc79da.zip
cgit-92f6940975f6771f3a08d497c02575ee5bdc79da.tar.gz
cgit-92f6940975f6771f3a08d497c02575ee5bdc79da.tar.bz2
Merge branch 'lh/repo-scan'
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cache.h2
-rw-r--r--cgit.c265
-rw-r--r--cgit.css2
-rw-r--r--cgit.h9
-rw-r--r--cgitrc.5.txt48
-rw-r--r--scan-tree.c32
-rw-r--r--scan-tree.h2
-rw-r--r--shared.c3
-rw-r--r--ui-repolist.c37
-rw-r--r--ui-stats.c8
-rw-r--r--ui-stats.h1
11 files changed, 329 insertions, 80 deletions
diff --git a/cache.h b/cache.h
index 66cc41f..ac9276b 100644
--- a/cache.h
+++ b/cache.h
@@ -34,2 +34,4 @@ extern void cache_log(const char *format, ...);
+extern unsigned long hash_str(const char *str);
+
#endif /* CGIT_CACHE_H */
diff --git a/cgit.c b/cgit.c
index ec40e1f..bd37788 100644
--- a/cgit.c
+++ b/cgit.c
@@ -42,5 +42,54 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args)
+static void process_cached_repolist(const char *path);
+
+void repo_config(struct cgit_repo *repo, const char *name, const char *value)
+{
+ if (!strcmp(name, "name"))
+ repo->name = xstrdup(value);
+ else if (!strcmp(name, "clone-url"))
+ repo->clone_url = xstrdup(value);
+ else if (!strcmp(name, "desc"))
+ repo->desc = xstrdup(value);
+ else if (!strcmp(name, "owner"))
+ repo->owner = xstrdup(value);
+ else if (!strcmp(name, "defbranch"))
+ repo->defbranch = xstrdup(value);
+ else if (!strcmp(name, "snapshots"))
+ repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
+ else if (!strcmp(name, "enable-log-filecount"))
+ repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
+ else if (!strcmp(name, "enable-log-linecount"))
+ repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
+ else if (!strcmp(name, "max-stats"))
+ repo->max_stats = cgit_find_stats_period(value, NULL);
+ else if (!strcmp(name, "module-link"))
+ repo->module_link= xstrdup(value);
+ else if (!strcmp(name, "section"))
+ repo->section = xstrdup(value);
+ else if (!strcmp(name, "readme") && value != NULL) {
+ if (*value == '/')
+ ctx.repo->readme = xstrdup(value);
+ else
+ ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
+ } else if (ctx.cfg.enable_filter_overrides) {
+ if (!strcmp(name, "about-filter"))
+ repo->about_filter = new_filter(value, 0);
+ else if (!strcmp(name, "commit-filter"))
+ repo->commit_filter = new_filter(value, 0);
+ else if (!strcmp(name, "source-filter"))
+ repo->source_filter = new_filter(value, 1);
+ }
+}
+
void config_cb(const char *name, const char *value)
{
- if (!strcmp(name, "root-title"))
+ if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
+ ctx.cfg.section = xstrdup(value);
+ else if (!strcmp(name, "repo.url"))
+ ctx.repo = cgit_add_repo(value);
+ else if (ctx.repo && !strcmp(name, "repo.path"))
+ ctx.repo->path = trim_end(value, '/');
+ else if (ctx.repo && !prefixcmp(name, "repo."))
+ repo_config(ctx.repo, name + 5, value);
+ else if (!strcmp(name, "root-title"))
ctx.cfg.root_title = xstrdup(value);
@@ -82,2 +131,4 @@ void config_cb(const char *name, const char *value)
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
+ else if (!strcmp(name, "enable-filter-overrides"))
+ ctx.cfg.enable_filter_overrides = atoi(value);
else if (!strcmp(name, "enable-index-links"))
@@ -100,2 +151,4 @@ void config_cb(const char *name, const char *value)
ctx.cfg.cache_repo_ttl = atoi(value);
+ else if (!strcmp(name, "cache-scanrc-ttl"))
+ ctx.cfg.cache_scanrc_ttl = atoi(value);
else if (!strcmp(name, "cache-static-ttl"))
@@ -118,2 +171,7 @@ void config_cb(const char *name, const char *value)
ctx.cfg.max_commit_count = atoi(value);
+ else if (!strcmp(name, "scan-path"))
+ if (!ctx.cfg.nocache && ctx.cfg.cache_size)
+ process_cached_repolist(value);
+ else
+ scan_tree(value, repo_config);
else if (!strcmp(name, "source-filter"))
@@ -138,40 +196,3 @@ void config_cb(const char *name, const char *value)
add_mimetype(name + 9, value);
- else if (!strcmp(name, "repo.group"))
- ctx.cfg.repo_group = xstrdup(value);
- else if (!strcmp(name, "repo.url"))
- ctx.repo = cgit_add_repo(value);
- else if (!strcmp(name, "repo.name"))
- ctx.repo->name = xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.path"))
- ctx.repo->path = trim_end(value, '/');
- else if (ctx.repo && !strcmp(name, "repo.clone-url"))
- ctx.repo->clone_url = xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.desc"))
- ctx.repo->desc = xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.owner"))
- ctx.repo->owner = xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.defbranch"))
- ctx.repo->defbranch = xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.snapshots"))
- ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
- else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount"))
- ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
- else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount"))
- ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
- else if (ctx.repo && !strcmp(name, "repo.max-stats"))
- ctx.repo->max_stats = cgit_find_stats_period(value, NULL);
- else if (ctx.repo && !strcmp(name, "repo.module-link"))
- ctx.repo->module_link= xstrdup(value);
- else if (ctx.repo && !strcmp(name, "repo.about-filter"))
- ctx.repo->about_filter = new_filter(value, 0);
- else if (ctx.repo && !strcmp(name, "repo.commit-filter"))
- ctx.repo->commit_filter = new_filter(value, 0);
- else if (ctx.repo && !strcmp(name, "repo.source-filter"))
- ctx.repo->source_filter = new_filter(value, 1);
- else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) {
- if (*value == '/')
- ctx.repo->readme = xstrdup(value);
- else
- ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value));
- } else if (!strcmp(name, "include"))
+ else if (!strcmp(name, "include"))
parse_configfile(value, config_cb);
@@ -238,2 +259,3 @@ static void prepare_context(struct cgit_context *ctx)
ctx->cfg.cache_root_ttl = 5;
+ ctx->cfg.cache_scanrc_ttl = 15;
ctx->cfg.cache_static_ttl = -1;
@@ -255,2 +277,3 @@ static void prepare_context(struct cgit_context *ctx)
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
+ ctx->cfg.section = "";
ctx->cfg.summary_branches = 10;
@@ -419,17 +442,75 @@ int cmp_repos(const void *a, const void *b)
-void print_repo(struct cgit_repo *repo)
+char *build_snapshot_setting(int bitmap)
+{
+ const struct cgit_snapshot_format *f;
+ char *result = xstrdup("");
+ char *tmp;
+ int len;
+
+ for (f = cgit_snapshot_formats; f->suffix; f++) {
+ if (f->bit & bitmap) {
+ tmp = result;
+ result = xstrdup(fmt("%s%s ", tmp, f->suffix));
+ free(tmp);
+ }
+ }
+ len = strlen(result);
+ if (len)
+ result[len - 1] = '\0';
+ return result;
+}
+
+char *get_first_line(char *txt)
+{
+ char *t = xstrdup(txt);
+ char *p = strchr(t, '\n');
+ if (p)
+ *p = '\0';
+ return t;
+}
+
+void print_repo(FILE *f, struct cgit_repo *repo)
{
- printf("repo.url=%s\n", repo->url);
- printf("repo.name=%s\n", repo->name);
- printf("repo.path=%s\n", repo->path);
+ fprintf(f, "repo.url=%s\n", repo->url);
+ fprintf(f, "repo.name=%s\n", repo->name);
+ fprintf(f, "repo.path=%s\n", repo->path);
if (repo->owner)
- printf("repo.owner=%s\n", repo->owner);
- if (repo->desc)
- printf("repo.desc=%s\n", repo->desc);
+ fprintf(f, "repo.owner=%s\n", repo->owner);
+ if (repo->desc) {
+ char *tmp = get_first_line(repo->desc);
+ fprintf(f, "repo.desc=%s\n", tmp);
+ free(tmp);
+ }
if (repo->readme)
- printf("repo.readme=%s\n", repo->readme);
- printf("\n");
+ fprintf(f, "repo.readme=%s\n", repo->readme);
+ if (repo->defbranch)
+ fprintf(f, "repo.defbranch=%s\n", repo->defbranch);
+ if (repo->module_link)
+ fprintf(f, "repo.module-link=%s\n", repo->module_link);
+ if (repo->section)
+ fprintf(f, "repo.section=%s\n", repo->section);
+ if (repo->clone_url)
+ fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
+ fprintf(f, "repo.enable-log-filecount=%d\n",
+ repo->enable_log_filecount);
+ fprintf(f, "repo.enable-log-linecount=%d\n",
+ repo->enable_log_linecount);
+ if (repo->about_filter && repo->about_filter != ctx.cfg.about_filter)
+ fprintf(f, "repo.about-filter=%s\n", repo->about_filter->cmd);
+ if (repo->commit_filter && repo->commit_filter != ctx.cfg.commit_filter)
+ fprintf(f, "repo.commit-filter=%s\n", repo->commit_filter->cmd);
+ if (repo->source_filter && repo->source_filter != ctx.cfg.source_filter)
+ fprintf(f, "repo.source-filter=%s\n", repo->source_filter->cmd);
+ if (repo->snapshots != ctx.cfg.snapshots) {
+ char *tmp = build_snapshot_setting(repo->snapshots);
+ fprintf(f, "repo.snapshots=%s\n", tmp);
+ free(tmp);
+ }
+ if (repo->max_stats != ctx.cfg.max_stats)
+ fprintf(f, "repo.max-stats=%s\n",
+ cgit_find_stats_periodname(repo->max_stats));
+ fprintf(f, "\n");
}
-void print_repolist(struct cgit_repolist *list)
+void print_repolist(FILE *f, struct cgit_repolist *list, int start)
{
@@ -437,6 +518,71 @@ void print_repolist(struct cgit_repolist *list)
- for(i = 0; i < list->count; i++)
- print_repo(&list->repos[i]);
+ for(i = start; i < list->count; i++)
+ print_repo(f, &list->repos[i]);
+}
+
+/* Scan 'path' for git repositories, save the resulting repolist in 'cached_rc'
+ * and return 0 on success.
+ */
+static int generate_cached_repolist(const char *path, const char *cached_rc)
+{
+ char *locked_rc;
+ int idx;
+ FILE *f;
+
+ locked_rc = xstrdup(fmt("%s.lock", cached_rc));
+ f = fopen(locked_rc, "wx");
+ if (!f) {
+ /* Inform about the error unless the lockfile already existed,
+ * since that only means we've got concurrent requests.
+ */
+ if (errno != EEXIST)
+ fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
+ locked_rc, strerror(errno), errno);
+ return errno;
+ }
+ idx = cgit_repolist.count;
+ scan_tree(path, repo_config);
+ print_repolist(f, &cgit_repolist, idx);
+ if (rename(locked_rc, cached_rc))
+ fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
+ locked_rc, cached_rc, strerror(errno), errno);
+ fclose(f);
+ return 0;
}
+static void process_cached_repolist(const char *path)
+{
+ struct stat st;
+ char *cached_rc;
+ time_t age;
+
+ cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root,
+ hash_str(path)));
+
+ if (stat(cached_rc, &st)) {
+ /* Nothing is cached, we need to scan without forking. And
+ * if we fail to generate a cached repolist, we need to
+ * invoke scan_tree manually.
+ */
+ if (generate_cached_repolist(path, cached_rc))
+ scan_tree(path, repo_config);
+ return;
+ }
+
+ parse_configfile(cached_rc, config_cb);
+
+ /* If the cached configfile hasn't expired, lets exit now */
+ age = time(NULL) - st.st_mtime;
+ if (age <= (ctx.cfg.cache_scanrc_ttl * 60))
+ return;
+
+ /* The cached repolist has been parsed, but it was old. So lets
+ * rescan the specified path and generate a new cached repolist
+ * in a child-process to avoid latency for the current request.
+ */
+ if (fork())
+ return;
+
+ exit(generate_cached_repolist(path, cached_rc));
+}
@@ -477,5 +623,16 @@ static void cgit_parse_args(int argc, const char **argv)
}
- if (!strncmp(argv[i], "--scan-tree=", 12)) {
+ if (!strncmp(argv[i], "--scan-tree=", 12) ||
+ !strncmp(argv[i], "--scan-path=", 12)) {
+ /* HACK: the global snapshot bitmask defines the
+ * set of allowed snapshot formats, but the config
+ * file hasn't been parsed yet so the mask is
+ * currently 0. By setting all bits high before
+ * scanning we make sure that any in-repo cgitrc
+ * snapshot setting is respected by scan_tree().
+ * BTW: we assume that there'll never be more than
+ * 255 different snapshot formats supported by cgit...
+ */
+ ctx.cfg.snapshots = 0xFF;
scan++;
- scan_tree(argv[i] + 12);
+ scan_tree(argv[i] + 12, repo_config);
}
@@ -485,3 +642,3 @@ static void cgit_parse_args(int argc, const char **argv)
sizeof(struct cgit_repo), cmp_repos);
- print_repolist(&cgit_repolist);
+ print_repolist(stdout, &cgit_repolist, 0);
exit(0);
diff --git a/cgit.css b/cgit.css
index ebf3322..c47ebc9 100644
--- a/cgit.css
+++ b/cgit.css
@@ -431,3 +431,3 @@ table.diff td div.del {
-table.list td.repogroup {
+table.list td.reposection {
font-style: italic;
diff --git a/cgit.h b/cgit.h
index a20679a..6c6c460 100644
--- a/cgit.h
+++ b/cgit.h
@@ -67,5 +67,5 @@ struct cgit_repo {
char *defbranch;
- char *group;
char *module_link;
char *readme;
+ char *section;
char *clone_url;
@@ -81,2 +81,5 @@ struct cgit_repo {
+typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
+ const char *value);
+
struct cgit_repolist {
@@ -158,3 +161,2 @@ struct cgit_config {
char *module_link;
- char *repo_group;
char *robots;
@@ -164,2 +166,3 @@ struct cgit_config {
char *script_name;
+ char *section;
char *virtual_root;
@@ -170,4 +173,6 @@ struct cgit_config {
int cache_root_ttl;
+ int cache_scanrc_ttl;
int cache_static_ttl;
int embedded;
+ int enable_filter_overrides;
int enable_index_links;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 3b16db9..4dc383d 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -56,2 +56,6 @@ cache-root-ttl::
+cache-scanrc-ttl::
+ Number which specifies the time-to-live, in minutes, for the result
+ of scanning a path for git repositories. Default value: "15".
+
cache-size::
@@ -86,2 +90,6 @@ embedded::
+enable-filter-overrides::
+ Flag which, when set to "1", allows all filter settings to be
+ overridden in repository-specific cgitrc files. Default value: none.
+
enable-index-links::
@@ -202,4 +210,4 @@ renamelimit::
repo.group::
- A value for the current repository group, which all repositories
- specified after this setting will inherit. Default value: none.
+ Legacy alias for "section". This option is deprecated and will not be
+ supported in cgit-1.0.
@@ -222,2 +230,12 @@ root-title::
+scan-path::
+ A path which will be scanned for repositories. If caching is enabled,
+ the result will be cached as a cgitrc include-file in the cache
+ directory. Default value: none. See also: cache-scanrc-ttl.
+
+section::
+ The name of the current repository section - all repositories defined
+ after this option will inherit the current section name. Default value:
+ none.
+
snapshots::
@@ -258,3 +276,4 @@ REPOSITORY SETTINGS
repo.about-filter::
- Override the default about-filter. Default value: <about-filter>.
+ Override the default about-filter. Default value: none. See also:
+ "enable-filter-overrides".
@@ -265,3 +284,4 @@ repo.clone-url::
repo.commit-filter::
- Override the default commit-filter. Default value: <commit-filter>.
+ Override the default commit-filter. Default value: none. See also:
+ "enable-filter-overrides".
@@ -307,4 +327,9 @@ repo.snapshots::
+repo.section::
+ Override the current section name for this repository. Default value:
+ none.
+
repo.source-filter::
- Override the default source-filter. Default value: <source-filter>.
+ Override the default source-filter. Default value: none. See also:
+ "enable-filter-overrides".
@@ -315,2 +340,15 @@ repo.url::
+REPOSITORY-SPECIFIC CGITRC FILE
+-------------------------------
+When the option "scan-path" is used to auto-discover git repositories, cgit
+will try to parse the file "cgitrc" within any found repository. Such a
+repo-specific config file may contain any of the repo-specific options
+described above, except "repo.url" and "repo.path". Additionally, the "filter"
+options are only acknowledged in repo-specific config files when
+"enable-filter-overrides" is set to "1".
+
+Note: the "repo." prefix is dropped from the option names in repo-specific
+config files, e.g. "repo.desc" becomes "desc".
+
+
EXAMPLE CGITRC FILE
diff --git a/scan-tree.c b/scan-tree.c
index 4da21a4..dbca797 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -1,2 +1,3 @@
#include "cgit.h"
+#include "configfile.h"
#include "html.h"
@@ -37,5 +38,12 @@ static int is_git_dir(const char *path)
-static void add_repo(const char *base, const char *path)
+struct cgit_repo *repo;
+repo_config_fn config_fn;
+
+static void repo_config(const char *name, const char *value)
+{
+ config_fn(repo, name, value);
+}
+
+static void add_repo(const char *base, const char *path, repo_config_fn fn)
{
- struct cgit_repo *repo;
struct stat st;
@@ -78,5 +86,11 @@ static void add_repo(const char *base, const char *path)
repo->readme = "README.html";
+
+ p = fmt("%s/cgitrc", path);
+ if (!stat(p, &st)) {
+ config_fn = fn;
+ parse_configfile(xstrdup(p), &repo_config);
+ }
}
-static void scan_path(const char *base, const char *path)
+static void scan_path(const char *base, const char *path, repo_config_fn fn)
{
@@ -88,3 +102,7 @@ static void scan_path(const char *base, const char *path)
if (is_git_dir(path)) {
- add_repo(base, path);
+ add_repo(base, path, fn);
+ return;
+ }
+ if (is_git_dir(fmt("%s/.git", path))) {
+ add_repo(base, fmt("%s/.git", path), fn);
return;
@@ -118,3 +136,3 @@ static void scan_path(const char *base, const char *path)
if (S_ISDIR(st.st_mode))
- scan_path(base, buf);
+ scan_path(base, buf, fn);
free(buf);
@@ -124,5 +142,5 @@ static void scan_path(const char *base, const char *path)
-void scan_tree(const char *path)
+void scan_tree(const char *path, repo_config_fn fn)
{
- scan_path(path, path);
+ scan_path(path, path, fn);
}
diff --git a/scan-tree.h b/scan-tree.h
index b103b16..11539f4 100644
--- a/scan-tree.h
+++ b/scan-tree.h
@@ -2,2 +2,2 @@
-extern void scan_tree(const char *path);
+extern void scan_tree(const char *path, repo_config_fn fn);
diff --git a/shared.c b/shared.c
index 4cb9573..d7b2d5a 100644
--- a/shared.c
+++ b/shared.c
@@ -50,2 +50,3 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret = &cgit_repolist.repos[cgit_repolist.count-1];
+ memset(ret, 0, sizeof(struct cgit_repo));
ret->url = trim_end(url, '/');
@@ -55,3 +56,3 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->owner = NULL;
- ret->group = ctx.cfg.repo_group;
+ ret->section = ctx.cfg.section;
ret->defbranch = "master";
diff --git a/ui-repolist.c b/ui-repolist.c
index 7c7aa9b..3ef2e99 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -138,2 +138,14 @@ static int cmp(const char *s1, const char *s2)
+static int sort_section(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+ int result;
+
+ result = cmp(r1->section, r2->section);
+ if (!result)
+ result = cmp(r1->name, r2->name);
+ return result;
+}
+
static int sort_name(const void *a, const void *b)
@@ -180,2 +192,3 @@ struct sortcolumn {
struct sortcolumn sortcolumn[] = {
+ {"section", sort_section},
{"name", sort_name},
@@ -205,3 +218,4 @@ void cgit_print_repolist()
int i, columns = 4, hits = 0, header = 0;
- char *last_group = NULL;
+ char *last_section = NULL;
+ char *section;
int sorted = 0;
@@ -221,2 +235,4 @@ void cgit_print_repolist()
sorted = sort_repolist(ctx.qry.sort);
+ else
+ sort_repolist("section");
@@ -234,15 +250,18 @@ void cgit_print_repolist()
print_header(columns);
+ section = ctx.repo->section;
+ if (section && !strcmp(section, ""))
+ section = NULL;
if (!sorted &&
- ((last_group == NULL && ctx.repo->group != NULL) ||
- (last_group != NULL && ctx.repo->group == NULL) ||
- (last_group != NULL && ctx.repo->group != NULL &&
- strcmp(ctx.repo->group, last_group)))) {
- htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
+ ((last_section == NULL && section != NULL) ||
+ (last_section != NULL && section == NULL) ||
+ (last_section != NULL && section != NULL &&
+ strcmp(section, last_section)))) {
+ htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
columns);
- html_txt(ctx.repo->group);
+ html_txt(section);
html("</td></tr>");
- last_group = ctx.repo->group;
+ last_section = section;
}
htmlf("<tr><td class='%s'>",
- !sorted && ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
+ !sorted && section ? "sublevel-repo" : "toplevel-repo");
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
diff --git a/ui-stats.c b/ui-stats.c
index 9fc06d3..bdaf9cc 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -156,2 +156,10 @@ int cgit_find_stats_period(const char *expr, struct cgit_period **period)
+const char *cgit_find_stats_periodname(int idx)
+{
+ if (idx > 0 && idx < 4)
+ return periods[idx - 1].name;
+ else
+ return "";
+}
+
static void add_commit(struct string_list *authors, struct commit *commit,
diff --git a/ui-stats.h b/ui-stats.h
index 4f13dba..f0761ba 100644
--- a/ui-stats.h
+++ b/ui-stats.h
@@ -23,2 +23,3 @@ struct cgit_period {
extern int cgit_find_stats_period(const char *expr, struct cgit_period **period);
+extern const char *cgit_find_stats_periodname(int idx);