From 1f783c957e24323a97f34258040fac6f65b95657 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 5 Nov 2026 20:56:15 -1000 Subject: Name a pinned commit with the page in the title --- source/ui-shared.c | 31 ++++++++++++++++++++++++++++--- tests/t0005-markup.sh | 13 +++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/source/ui-shared.c b/source/ui-shared.c index cb5e050..788551d 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1442,10 +1442,31 @@ void cgit_redirect(const char *url, const char *query, bool permanent) html("\n\n"); } +/* + * A repository page's title runs page - repository - site, apart from the + * summary's, which has no page name and opens with the repository. Answer the + * length of the name the title opens with. + */ +static size_t title_name_len(const char *title) +{ + struct strbuf tail = STRBUF_INIT; + size_t len = strlen(title); + + strbuf_addf(&tail, " - %s", ctx.cfg.root_title); + if (strip_suffix_mem(title, &len, tail.buf)) { + strbuf_reset(&tail); + strbuf_addf(&tail, " - %s", ctx.repo->name); + strip_suffix_mem(title, &len, tail.buf); + } + strbuf_release(&tail); + return len; +} + static void print_docstart(void) { const struct object_id *pinned; struct string_list_item *item; + struct strbuf title = STRBUF_INIT; const char *desc, *robots; char *host; @@ -1466,11 +1487,15 @@ static void print_docstart(void) html(""); // A page that chose no title still has to name itself, since an empty // title element is not valid. - html_txt(ctx.page.title ? ctx.page.title : ctx.cfg.root_title); + strbuf_addstr(&title, ctx.page.title ? ctx.page.title : ctx.cfg.root_title); // The auth page goes out before the repository is opened, when - // pinned_oid cannot resolve anything yet. + // pinned_oid cannot resolve anything yet. The commit is the page's, so + // it is named with the page, ahead of the repository and the site. if (ctx.env.authenticated && (pinned = pinned_oid())) - html_txtf(" @ %.*s", SHORT_HASH_LEN, oid_to_hex(pinned)); + strbuf_insertf(&title, title_name_len(title.buf), " @ %.*s", + SHORT_HASH_LEN, oid_to_hex(pinned)); + html_txt(title.buf); + strbuf_release(&title); html("\n"); // The placeholder a scanned repository carries instead of a description // is left out, since it describes nothing. Until the auth filter lets diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index cf9143b..064e74d 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -118,6 +118,19 @@ test_expect_success 'each page names itself, then the repository and the site' ' grep "blame - hello.c < dir - hooks - $site" tmp ' +# A commit the page is pinned to belongs with the page's own name, or with the +# repository's on the summary, which has no name of its own. +test_expect_success 'a pinned page names its commit before the repository' ' + site="Git repository browser" && + old=$(git -C repos/hooks rev-parse HEAD~1 | cut -c1-10) && + cgit_rc hooksrc "url=hooks/tree/&id=$old" >tmp && + grep "tree @ $old - hooks - $site" tmp && + cgit_rc hooksrc "url=hooks/commit/&id=$old" >tmp && + grep "commit 2 @ $old - hooks - $site" tmp && + cgit_rc hooksrc "url=hooks/&id=$old" >tmp && + grep "hooks @ $old - $site" tmp +' + # The logo is all its link holds, so it is named for where the link leads, # which by default is the site's index. test_expect_success 'the logo is named after the site' ' -- cgit 2.12.1