From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21400 invoked from network); 30 Jan 2022 18:04:32 -0000 Received: from lists.zx2c4.com (165.227.139.114) by inbox.vuxu.org with ESMTPUTF8; 30 Jan 2022 18:04:32 -0000 Received: by lists.zx2c4.com (OpenSMTPD) with ESMTP id 89e0cd2f; Sun, 30 Jan 2022 18:04:15 +0000 (UTC) Return-Path: Received: from mail-40138.protonmail.ch (mail-40138.protonmail.ch [185.70.40.138]) by lists.zx2c4.com (OpenSMTPD) with ESMTPS id 2e44badb (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Sun, 30 Jan 2022 18:04:13 +0000 (UTC) Date: Sun, 30 Jan 2022 18:04:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail2; t=1643565852; bh=Bhqa+bWEw8xfqGwO+z6nErnFCdIH5KR22w8kPcCHXCw=; h=Date:To:From:Reply-To:Subject:Message-ID:From:To:Cc; b=M6WmeZGFESx2QuWotOg744S/LV8txP8B9RDinXDMNY4X3tNpoq4eKLv28QQ16T+Ho 6k0vPQgXorVpq23vAW+DNbIMhZKkLnWkhi9/xuMkS4nj6vTYGMd2NuVqL98rUqhLMJ JXw5tkCJQy0r+tDaYVG0ZxYckgPFcXT6FuBpoyjxl6riBtD/Is1upMXkqovWV510JE rt7hoXVfoqicsEmRZUV6J0D1XTjIk6PTQvFhc98y1dM6PB0TTcAF6H3OSAWUlCA5Gm lwXD4UiL5p66TY/ITeVqw9umXiitHGLepETqIwE1mpvWAICJR0AYWpqZ/xc0YQkQoL zc3cRqNz+6yjw== To: "cgit@lists.zx2c4.com" From: equa Subject: [PATCH] Add "default-tab" and "root-default-tab" configuration options Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: cgit@lists.zx2c4.com X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: List for cgit developers and users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: equa Errors-To: cgit-bounces@lists.zx2c4.com Sender: "CGit" These options allow the user to specify a page to display at the root repository/index location instead of the default summary or repository list= . Signed-off-by: equa --- cgit.c | 10 ++++++++++ cgit.h | 3 +++ cgitrc.5.txt | 11 +++++++++++ cmd.c | 6 +++--- shared.c | 1 + ui-repolist.c | 2 +- ui-shared.c | 24 ++++++++++++++++++++---- ui-shared.h | 2 ++ 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/cgit.c b/cgit.c index 08d81a1..f1c2224 100644 --- a/cgit.c +++ b/cgit.c @@ -56,6 +56,8 @@ static void repo_config(struct cgit_repo *repo, const cha= r *name, const char *va =09=09repo->homepage =3D xstrdup(value); =09else if (!strcmp(name, "defbranch")) =09=09repo->defbranch =3D xstrdup(value); +=09else if (!strcmp(name, "default-tab")) +=09=09repo->default_tab =3D xstrdup(value); =09else if (!strcmp(name, "extra-head-content")) =09=09repo->extra_head_content =3D xstrdup(value); =09else if (!strcmp(name, "snapshots")) @@ -285,6 +287,10 @@ static void config_cb(const char *name, const char *va= lue) =09=09ctx.cfg.clone_url =3D xstrdup(value); =09else if (!strcmp(name, "local-time")) =09=09ctx.cfg.local_time =3D atoi(value); +=09else if (!strcmp(name, "default-tab")) +=09=09ctx.cfg.default_tab =3D xstrdup(value); +=09else if (!strcmp(name, "root-default-tab")) +=09=09ctx.cfg.root_default_tab =3D xstrdup(value); =09else if (!strcmp(name, "commit-sort")) { =09=09if (!strcmp(value, "date")) =09=09=09ctx.cfg.commit_sort =3D 1; @@ -373,6 +379,8 @@ static void prepare_context(void) =09ctx.cfg.cache_scanrc_ttl =3D 15; =09ctx.cfg.cache_dynamic_ttl =3D 5; =09ctx.cfg.cache_static_ttl =3D -1; +=09ctx.cfg.default_tab =3D "summary"; +=09ctx.cfg.root_default_tab =3D "repolist"; =09ctx.cfg.case_sensitive_sort =3D 1; =09ctx.cfg.branch_sort =3D 0; =09ctx.cfg.commit_sort =3D 0; @@ -816,6 +824,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) =09=09fprintf(f, "repo.homepage=3D%s\n", repo->homepage); =09if (repo->clone_url) =09=09fprintf(f, "repo.clone-url=3D%s\n", repo->clone_url); +=09if (repo->default_tab) +=09=09fprintf(f, "repo.default-tab=3D%s\n", repo->default_tab); =09fprintf(f, "repo.enable-blame=3D%d\n", =09 repo->enable_blame); =09fprintf(f, "repo.enable-commit-graph=3D%d\n", diff --git a/cgit.h b/cgit.h index 69b5c13..bb555cf 100644 --- a/cgit.h +++ b/cgit.h @@ -86,6 +86,7 @@ struct cgit_repo { =09char *owner; =09char *homepage; =09char *defbranch; +=09char *default_tab; =09char *module_link; =09struct string_list readme; =09char *section; @@ -215,6 +216,8 @@ struct cgit_config { =09char *repository_sort; =09char *virtual_root;=09/* Always ends with '/'. */ =09char *strict_export; +=09char *default_tab; +=09char *root_default_tab; =09int cache_size; =09int cache_dynamic_ttl; =09int cache_max_create_time; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 33a6a8c..f32fb33 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -128,6 +128,10 @@ css:: =09Url which specifies the css document to include in all cgit pages. =09Default value: "/cgit.css". +default-tab:: +=09Specifies the tab to automatically load in the root page of a repositor= y. +=09Default value: "summary". See also: root-default-tab, repo.default-tab. + email-filter:: =09Specifies a command which will be invoked to format names and email =09address of committers, authors, and taggers, as represented in various @@ -352,6 +356,10 @@ robots:: =09Text used as content for the "robots" meta-tag. Default value: =09"index, nofollow". +root-default-tab:: +=09Specifies the tab to automatically load as the root index page. +=09Default value: "repolist". See also: default-tab, repo.default-tab. + root-desc:: =09Text printed below the heading on the repository index page. Default =09value: "a fast webinterface for the git dscm". @@ -481,6 +489,9 @@ repo.defbranch:: =09as default instead. Default value: branch pointed to by HEAD, or =09"master" if there is no suitable HEAD. +repo.default-tab:: +=09Override the global default-tab. Default value: none. + repo.desc:: =09The 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) =09=09=09cgit_redirect(ctx.repo->homepage, false); =09=09else { =09=09=09char *currenturl =3D cgit_currenturl(); -=09=09=09char *redirect =3D fmtalloc("%s../", currenturl); +=09=09=09char *redirect =3D cgit_pageurl(ctx.repo->url, "summary", NULL); =09=09=09cgit_redirect(redirect, false); =09=09=09free(currenturl); =09=09=09free(redirect); @@ -196,9 +196,9 @@ struct cgit_cmd *cgit_get_cmd(void) =09if (ctx.qry.page =3D=3D NULL) { =09=09if (ctx.repo) -=09=09=09ctx.qry.page =3D "summary"; +=09=09=09ctx.qry.page =3D ctx.repo->default_tab; =09=09else -=09=09=09ctx.qry.page =3D "repolist"; +=09=09=09ctx.qry.page =3D ctx.cfg.root_default_tab; =09} =09for (i =3D 0; i < sizeof(cmds)/sizeof(*cmds); i++) diff --git a/shared.c b/shared.c index 8115469..b1090a6 100644 --- a/shared.c +++ b/shared.c @@ -79,6 +79,7 @@ struct cgit_repo *cgit_add_repo(const char *url) =09ret->clone_url =3D ctx.cfg.clone_url; =09ret->submodules.strdup_strings =3D 1; =09ret->hide =3D ret->ignore =3D 0; +=09ret->default_tab =3D ctx.cfg.default_tab; =09return ret; } diff --git a/ui-repolist.c b/ui-repolist.c index 529a203..75db72a 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -321,7 +321,7 @@ void cgit_print_repolist(void) =09=09} =09=09htmlf("", =09=09 !sorted && section ? "sublevel-repo" : "toplevel-repo"); -=09=09cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); +=09=09cgit_repo_link(ctx.repo->name, ctx.repo->name, NULL, NULL); =09=09html(""); =09=09repourl =3D cgit_repourl(ctx.repo->url); =09=09html_link_open(repourl, NULL, NULL); diff --git a/ui-shared.c b/ui-shared.c index acd8ab5..17b1e49 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -203,6 +203,9 @@ static void site_url(const char *page, const char *sear= ch, const char *sort, int { =09char *delim =3D "?"; +=09if (!strcmp(page ? page : "", ctx.cfg.root_default_tab)) +=09=09page =3D NULL; + =09if (always_root || page) =09=09html_attr(cgit_rooturl()); =09else { @@ -257,7 +260,7 @@ static void site_link(const char *page, const char *nam= e, const char *title, void cgit_index_link(const char *name, const char *title, const char *clas= s, =09=09 const char *pattern, const char *sort, int ofs, int always_root= ) { -=09site_link(NULL, name, title, class, pattern, sort, ofs, always_root); +=09site_link("repolist", name, title, class, pattern, sort, ofs, always_ro= ot); } static char *repolink(const char *title, const char *class, const char *pa= ge, @@ -317,6 +320,12 @@ static void reporevlink(const char *page, const char *= name, const char *title, { =09char *delim; +=09if (page +=09 && !rev +=09 && !path +=09 && !strcmp(page, ctx.repo->default_tab)) +=09=09page =3D NULL; + =09delim =3D repolink(title, class, page, head, path); =09if (rev && ctx.qry.head !=3D NULL && strcmp(rev, ctx.qry.head)) { =09=09html(delim); @@ -328,10 +337,17 @@ static void reporevlink(const char *page, const char = *name, const char *title, =09html(""); } +void cgit_repo_link(const char *name, const char *title, const char *class= , +=09=09 const char *head) +{ +=09reporevlink(NULL, name, title, class, head, NULL, NULL); +} + + void cgit_summary_link(const char *name, const char *title, const char *cl= ass, =09=09 const char *head) { -=09reporevlink(NULL, name, title, class, head, NULL, NULL); +=09reporevlink("summary", name, title, class, head, NULL, NULL); } void cgit_tag_link(const char *name, const char *title, const char *class, @@ -995,7 +1011,7 @@ static void print_header(void) =09if (ctx.repo) { =09=09cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1); =09=09html(" : "); -=09=09cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); +=09=09cgit_repo_link(ctx.repo->name, ctx.repo->name, NULL, NULL); =09=09if (ctx.env.authenticated) { =09=09=09html(""); =09=09=09html("
\n"); @@ -1084,7 +1100,7 @@ void cgit_print_pageheader(void) =09=09html("
\n"); =09} else if (ctx.env.authenticated) { =09=09char *currenturl =3D cgit_currenturl(); -=09=09site_link(NULL, "index", NULL, hc("repolist"), NULL, NULL, 0, 1); +=09=09site_link("repolist", "index", NULL, hc("repolist"), NULL, NULL, 0, = 1); =09=09if (ctx.cfg.root_readme) =09=09=09site_link("about", "about", NULL, hc("about"), =09=09=09=09 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, =09=09=09 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, +=09=09=09 const char *class, const char *head); extern void cgit_summary_link(const char *name, const char *title, =09=09=09 const char *class, const char *head); extern void cgit_tag_link(const char *name, const char *title, -- 2.30.2