From 5784efc9de06731cda916dd4575b43b93871dda3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 9 Jun 2022 17:40:38 -0500 Subject: Apply default-tab patch --- cgit.c | 10 ++++++++++ cgit.h | 3 +++ cgitrc.5.txt | 11 +++++++++++ cmd.c | 6 +++--- shared.c | 1 + ui-shared.c | 24 +++++++++++++++++++++--- ui-shared.h | 2 ++ 7 files changed, 51 insertions(+), 6 deletions(-) diff --git a/cgit.c b/cgit.c index dd28a79..0c5ccab 100644 --- a/cgit.c +++ b/cgit.c @@ -56,6 +56,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->homepage = xstrdup(value); else if (!strcmp(name, "defbranch")) repo->defbranch = xstrdup(value); + else if (!strcmp(name, "default-tab")) + repo->default_tab = xstrdup(value); else if (!strcmp(name, "extra-head-content")) repo->extra_head_content = xstrdup(value); else if (!strcmp(name, "snapshots")) @@ -285,6 +287,10 @@ static void config_cb(const char *name, const char *value) ctx.cfg.clone_url = xstrdup(value); else if (!strcmp(name, "local-time")) ctx.cfg.local_time = atoi(value); + else if (!strcmp(name, "default-tab")) + ctx.cfg.default_tab = xstrdup(value); + else if (!strcmp(name, "root-default-tab")) + ctx.cfg.root_default_tab = xstrdup(value); else if (!strcmp(name, "commit-sort")) { if (!strcmp(value, "date")) ctx.cfg.commit_sort = 1; @@ -373,6 +379,8 @@ static void prepare_context(void) ctx.cfg.cache_scanrc_ttl = 15; ctx.cfg.cache_dynamic_ttl = 5; ctx.cfg.cache_static_ttl = -1; + ctx.cfg.default_tab = "summary"; + ctx.cfg.root_default_tab = "repolist"; ctx.cfg.case_sensitive_sort = 1; ctx.cfg.branch_sort = 0; ctx.cfg.commit_sort = 0; @@ -818,6 +826,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.homepage=%s\n", repo->homepage); if (repo->clone_url) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); + if (repo->default_tab) + fprintf(f, "repo.default-tab=%s\n", repo->default_tab); fprintf(f, "repo.enable-blame=%d\n", repo->enable_blame); fprintf(f, "repo.enable-commit-graph=%d\n", diff --git a/cgit.h b/cgit.h index 72fcd84..4cd5fc3 100644 --- a/cgit.h +++ b/cgit.h @@ -86,6 +86,7 @@ struct cgit_repo { char *owner; char *homepage; char *defbranch; + char *default_tab; char *module_link; struct string_list readme; char *section; @@ -215,6 +216,8 @@ struct cgit_config { char *repository_sort; char *virtual_root; /* Always ends with '/'. */ char *strict_export; + char *default_tab; + char *root_default_tab; int cache_size; int cache_dynamic_ttl; int cache_max_create_time; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index cafb535..e9ebae5 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -128,6 +128,10 @@ css:: Url which specifies the css document to include in all cgit pages. Default value: "/cgit.css". +default-tab:: + Specifies the tab to automatically load in the root page of a repository. + Default value: "summary". See also: root-default-tab, repo.default-tab. + email-filter:: Specifies a command which will be invoked to format names and email address of committers, authors, and taggers, as represented in various @@ -352,6 +356,10 @@ robots:: Text used as content for the "robots" meta-tag. Default value: "index, nofollow". +root-default-tab:: + Specifies the tab to automatically load as the root index page. + Default value: "repolist". See also: default-tab, repo.default-tab. + root-desc:: Text printed below the heading on the repository index page. Default value: "a fast webinterface for the git dscm". @@ -481,6 +489,9 @@ repo.defbranch:: as default instead. Default value: branch pointed to by HEAD, or "master" if there is no suitable HEAD. +repo.default-tab:: + Override the global default-tab. Default value: none. + repo.desc:: The value to show as repository description. Default value: none. diff --git a/cmd.c b/cmd.c index 0eb75b1..64f6639 100644 --- a/cmd.c +++ b/cmd.c @@ -55,7 +55,7 @@ static void about_fn(void) cgit_redirect(ctx.repo->homepage, false); else { char *currenturl = cgit_currenturl(); - char *redirect = fmtalloc("%s../", currenturl); + char *redirect = cgit_pageurl(ctx.repo->url, "summary", NULL); cgit_redirect(redirect, false); free(currenturl); free(redirect); @@ -196,9 +196,9 @@ struct cgit_cmd *cgit_get_cmd(void) if (ctx.qry.page == NULL) { if (ctx.repo) - ctx.qry.page = "summary"; + ctx.qry.page = ctx.repo->default_tab; else - ctx.qry.page = "repolist"; + ctx.qry.page = ctx.cfg.root_default_tab; } for (i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) diff --git a/shared.c b/shared.c index 0bceb98..f60b8d4 100644 --- a/shared.c +++ b/shared.c @@ -79,6 +79,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->clone_url = ctx.cfg.clone_url; ret->submodules.strdup_strings = 1; ret->hide = ret->ignore = 0; + ret->default_tab = ctx.cfg.default_tab; return ret; } diff --git a/ui-shared.c b/ui-shared.c index 72a1505..0b7937c 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -203,6 +203,9 @@ static void site_url(const char *page, const char *search, const char *sort, int { char *delim = "?"; + if (!strcmp(page ? page : "", ctx.cfg.root_default_tab)) + page = NULL; + if (always_root || page) html_attr(cgit_rooturl()); else { @@ -257,7 +260,7 @@ static void site_link(const char *page, const char *name, const char *title, void cgit_index_link(const char *name, const char *title, const char *class, const char *pattern, const char *sort, int ofs, int always_root) { - site_link(NULL, name, title, class, pattern, sort, ofs, always_root); + site_link("repolist", name, title, class, pattern, sort, ofs, always_root); } static char *repolink(const char *title, const char *class, const char *page, @@ -317,6 +320,14 @@ static void reporevlink(const char *page, const char *name, const char *title, { char *delim; + if (!strcmp(page + ? page + : "", + ctx.repo + ? ctx.repo->default_tab + : ctx.cfg.root_default_tab)) + page = NULL; + delim = repolink(title, class, page, head, path); if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { html(delim); @@ -328,10 +339,17 @@ static void reporevlink(const char *page, const char *name, const char *title, html(""); } +void cgit_repo_link(const char *name, const char *title, const char *class, + const char *head) +{ + reporevlink(NULL, name, title, class, head, NULL, NULL); +} + + void cgit_summary_link(const char *name, const char *title, const char *class, const char *head) { - reporevlink(NULL, name, title, class, head, NULL, NULL); + reporevlink("summary", name, title, class, head, NULL, NULL); } void cgit_tag_link(const char *name, const char *title, const char *class, @@ -1111,7 +1129,7 @@ void cgit_print_pageheader(void) html("\n"); } else if (ctx.env.authenticated) { char *currenturl = cgit_currenturl(); - site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); + site_link("repolist", "index", NULL, hc("repolist"), NULL, NULL, 0, 1); if (ctx.cfg.root_readme) site_link("about", "about", NULL, hc("about"), NULL, NULL, 0, 1); diff --git a/ui-shared.h b/ui-shared.h index 6964873..9faf2ba 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -17,6 +17,8 @@ extern void cgit_add_clone_urls(void (*fn)(const char *)); extern void cgit_index_link(const char *name, const char *title, const char *class, const char *pattern, const char *sort, int ofs, int always_root); +extern void cgit_repo_link(const char *name, const char *title, + const char *class, const char *head); extern void cgit_summary_link(const char *name, const char *title, const char *class, const char *head); extern void cgit_tag_link(const char *name, const char *title, -- cgit 1.4.1-21-gabe81