Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
| -rw-r--r-- | source/ui-commit.c | 2 | |
| -rw-r--r-- | source/ui-diff.c | 2 | |
| -rw-r--r-- | source/ui-shared.c | 14 | |
| -rw-r--r-- | source/ui-shared.h | 2 | |
| -rwxr-xr-x | 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(")</div></td></tr>\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("<div class='truncated'>"); 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("</div>"); 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("</a>"); } 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</a> link" tmp && + cgit_rc limitfilesrc "url=limits/diff/&h=branch-1" >tmp && + grep "href=./limits/patch/?h=branch-1.>patch</a> 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. |
