From b9e3ea6a1b3a5fa9a2c2ec8cf9e15870261d9221 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 1 Nov 2026 15:27:07 -1000 Subject: Keep the range in a large diff's patch link The link named only id, so for a diff between two commits it led to a patch of the newer one alone, and without an id it lost the branch as well and led to the default branch's tip. --- source/ui-commit.c | 2 +- source/ui-diff.c | 2 +- source/ui-shared.c | 14 +++++++++++--- source/ui-shared.h | 2 +- tests/t0204-limits.sh | 11 +++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/source/ui-commit.c b/source/ui-commit.c index 0916c33..15259e6 100644 --- a/source/ui-commit.c +++ b/source/ui-commit.c @@ -265,7 +265,7 @@ void cgit_print_commit(char *hex, const char *prefix) commit_hex = oid_to_hex(&commit->object.oid); cgit_commit_link(commit_hex, NULL, NULL, ctx.qry.head, commit_hex, prefix); html(" ("); - cgit_patch_link("patch", NULL, NULL, NULL, commit_hex, prefix); + cgit_patch_link("patch", NULL, NULL, NULL, commit_hex, NULL, prefix); html(")\n"); // The parent rows follow the commit row so the commit hashes sit diff --git a/source/ui-diff.c b/source/ui-diff.c index 0e2e75e..1549949 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -670,7 +670,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi if (cap_diffs && ctx.cfg.max_diff_files > 0 && files > ctx.cfg.max_diff_files) { html("
"); html("This diff is too large to be rendered inline. Follow a file above, or the "); - cgit_patch_link("patch", NULL, NULL, NULL, ctx.qry.oid, NULL); + cgit_patch_link("patch", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, NULL); html(" link for the whole commit."); html("
"); if (show_ctrls) diff --git a/source/ui-shared.c b/source/ui-shared.c index 0eeda44..0865ffa 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -605,7 +605,7 @@ static void self_link(const char *name, const char *title, const char *class) else if (!strcmp(ctx.qry.page, "commit")) cgit_commit_link(name, title, class, ctx.qry.head, rev, ctx.qry.path); else if (!strcmp(ctx.qry.page, "patch")) - cgit_patch_link(name, title, class, ctx.qry.head, rev, ctx.qry.path); + cgit_patch_link(name, title, class, ctx.qry.head, rev, ctx.qry.oid2, ctx.qry.path); else if (!strcmp(ctx.qry.page, "refs")) cgit_refs_link(name, title, class, ctx.qry.head, rev, ctx.qry.path); else if (!strcmp(ctx.qry.page, "snapshot")) @@ -920,9 +920,17 @@ void cgit_diff_link(const char *name, const char *title, const char *class, } void cgit_patch_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path) + const char *head, const char *new_rev, const char *old_rev, const char *path) { - reporevlink("patch", name, title, class, head, rev, path); + const char *delim; + + delim = repolink(title, class, "patch", head, path); + delim = emit_rev_arg(delim, new_rev); + if (old_rev) + url_arg(delim, "id2", old_rev); + html("'>"); + html_txt(name); + html(""); } void cgit_stats_link(const char *name, const char *title, const char *class, diff --git a/source/ui-shared.h b/source/ui-shared.h index cd937a3..fa73c83 100644 --- a/source/ui-shared.h +++ b/source/ui-shared.h @@ -79,7 +79,7 @@ extern void cgit_log_link(const char *name, const char *title, const char *class extern void cgit_commit_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path); extern void cgit_patch_link(const char *name, const char *title, const char *class, - const char *head, const char *rev, const char *path); + const char *head, const char *new_rev, const char *old_rev, const char *path); extern void cgit_refs_link(const char *name, const char *title, const char *class, const char *head, const char *rev, const char *path); extern void cgit_diff_link(const char *name, const char *title, const char *class, diff --git a/tests/t0204-limits.sh b/tests/t0204-limits.sh index ecc33bf..9b0488c 100755 --- a/tests/t0204-limits.sh +++ b/tests/t0204-limits.sh @@ -135,6 +135,17 @@ test_expect_success 'the single-file page is not limited by max-diff-files' ' grep "class=.hunk." tmp ' +# The patch the notice links to has to hold the change the page compared, +# both ends of a range and a branch other than the default. +test_expect_success 'the stat only notice links the patch of the same change' ' + new=$(git -C repos/limits rev-parse HEAD) && + old=$(git -C repos/limits rev-parse HEAD~2) && + cgit_rc limitfilesrc "url=limits/diff/&id=$new&id2=$old" >tmp && + grep "href=./limits/patch/?id=$new&id2=$old.>patch link" tmp && + cgit_rc limitfilesrc "url=limits/diff/&h=branch-1" >tmp && + grep "href=./limits/patch/?h=branch-1.>patch link" tmp +' + # The diff views must not inflate a blob past max-blob-size merely to render # it, which is the same defence the tree and plain views make and is easy to # miss on this path. Such a file is reported as binary instead. -- cgit 2.12.1