From ba066ae56395d481d669d69c4ad14d9a268c0762 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 1 Nov 2026 10:18:08 -1000 Subject: Lead a blame page's folder crumbs to the tree --- source/ui-shared.c | 19 +++++++++++++++++-- tests/t0104-tree.sh | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/source/ui-shared.c b/source/ui-shared.c index 23daa2b..0eeda44 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -618,6 +618,21 @@ static void self_link(const char *name, const char *title, const char *class) reporevlink(ctx.qry.page, name, title, class, ctx.qry.head, NULL, ctx.qry.path); } +/* + * A crumb leads to the same page for the prefix it stands for, except that + * blame takes a file alone, so on that page a folder's crumb leads to the + * tree. + */ +static void crumb_link(const char *name, int folder) +{ + const char *rev = ctx.qry.has_oid ? ctx.qry.oid : NULL; + + if (folder && !strcmp(ctx.qry.page, "blame")) + cgit_tree_link(name, NULL, NULL, ctx.qry.head, rev, ctx.qry.path); + else + self_link(name, NULL, NULL); +} + static void print_path_crumbs(char *path) { char *old_path = ctx.qry.path; @@ -625,7 +640,7 @@ static void print_path_crumbs(char *path) int levels = 0; ctx.qry.path = NULL; - self_link("root", NULL, NULL); + crumb_link("root", 1); // self_link reads the path out of ctx.qry, so terminating the buffer at // each slash is what makes a crumb link to the prefix it stands for. ctx.qry.path = start = path; @@ -634,7 +649,7 @@ static void print_path_crumbs(char *path) slash = end; *slash = '\0'; html_txt("/"); - self_link(start, NULL, NULL); + crumb_link(start, slash < end); if (slash < end) *slash = '/'; start = slash + 1; diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 26a0cb4..754b3e1 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -79,6 +79,22 @@ test_expect_success 'the blame stripes are as wide as the escaped line' ' grep "^ \\{31\\}" tmp ' +# Blame takes a file alone, so on its page the crumbs for the folders above +# the file lead to the tree. +test_expect_success 'the folder crumbs of a blame page lead to the tree' ' + mkrepo repos/nested 1 && + ( + cd repos/nested && + mkdir -p a/b && + echo x >a/b/file.txt && + git add a && + git commit -m nested + ) && + cgitrc_repo nestedrc nested enable-blame=1 && + cgit_rc nestedrc "url=nested/blame/a/b/file.txt" >tmp && + grep "path: root/a/b/file.txt" tmp +' + test_expect_success 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >tmp' test_expect_success 'verify a+b link' ' -- cgit 2.12.1