aboutsummaryrefslogtreecommitdiff
path: root/cgit.c
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-09-13 03:54:08 +0000
committerJohn Keeping <john@keeping.me.uk>2016-10-01 10:51:07 +0000
commit1a66e7f3c15bf8d0d5d1b198c6674911a213779e (patch)
tree23f5d14af44ad63e1a9ad8c615fe622a0d4b52fe /cgit.c
parent84b158abe04ca37eb6e3038d3b63a9518714b66d (diff)
downloadcgit-1a66e7f3c15bf8d0d5d1b198c6674911a213779e.tar
cgit-1a66e7f3c15bf8d0d5d1b198c6674911a213779e.tar.gz
cgit-1a66e7f3c15bf8d0d5d1b198c6674911a213779e.zip
ui-repolist: Allow sections to be collapsiblejk/collapsible-sections
The index page can be difficult to navigate for really large git servers. This change allows a configuration like: section-collapse=people section-collapse=tests And an index page would only display the "people" and "tests" section headers entries (not their repos) with a hyperlink that can be used to drill down into each section. Additionally the boolean logic around displaying sections in ui-repolist.c was simplified to eliminate an impossible condition. Signed-off-by: Andy Doan <andy.doan@linaro.org> Reviewed-by: John Keeping <john@keeping.me.uk> Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/cgit.c b/cgit.c
index 2f29aa6..3266a98 100644
--- a/cgit.c
+++ b/cgit.c
@@ -77,7 +77,7 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
item = string_list_append(&repo->submodules, xstrdup(name + 12));
item->util = xstrdup(value);
} else if (!strcmp(name, "section"))
- repo->section = xstrdup(value);
+ repo->section = get_or_create_section(value);
else if (!strcmp(name, "readme") && value != NULL) {
if (repo->readme.items == ctx.cfg.readme.items)
memset(&repo->readme, 0, sizeof(repo->readme));
@@ -107,7 +107,7 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
static void config_cb(const char *name, const char *value)
{
if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
- ctx.cfg.section = xstrdup(value);
+ ctx.cfg.section = get_or_create_section(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
@@ -242,6 +242,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.section_from_path = atoi(value);
else if (!strcmp(name, "repository-sort"))
ctx.cfg.repository_sort = xstrdup(value);
+ else if (!strcmp(name, "section-collapse"))
+ get_or_create_section(value)->collapse = 1;
else if (!strcmp(name, "section-sort"))
ctx.cfg.section_sort = atoi(value);
else if (!strcmp(name, "source-filter"))
@@ -385,7 +387,7 @@ static void prepare_context(void)
ctx.cfg.root_desc = "a fast webinterface for the git dscm";
ctx.cfg.scan_hidden_path = 0;
ctx.cfg.script_name = CGIT_SCRIPT_NAME;
- ctx.cfg.section = "";
+ ctx.cfg.section = NULL;
ctx.cfg.repository_sort = "name";
ctx.cfg.section_sort = 1;
ctx.cfg.summary_branches = 10;
@@ -794,7 +796,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
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);
+ fprintf(f, "repo.section=%s\n", repo->section->name);
if (repo->homepage)
fprintf(f, "repo.homepage=%s\n", repo->homepage);
if (repo->clone_url)
@@ -1026,6 +1028,23 @@ static int calc_ttl(void)
return ctx.cfg.cache_repo_ttl;
}
+struct cgit_section* get_or_create_section(const char *section)
+{
+ struct cgit_section *ptr = ctx.sections;
+ while(ptr) {
+ if (!strcmp(section, ptr->name))
+ return ptr;
+ ptr = ptr->next;
+ }
+ /* Not found insert into head of list */
+ ptr = xmalloc(sizeof(*ptr));
+ ptr->name = xstrdup(section);
+ ptr->collapse = 0;
+ ptr->next = ctx.sections;
+ ctx.sections = ptr;
+ return ptr;
+}
+
int cmd_main(int argc, const char **argv)
{
const char *path;