Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Name the followed path in the diffstat header
With follow set the diff runs over the whole commit and show_filepair
applies the path, so the header read (limited to '') whether or not a
path was given.
| -rw-r--r-- | source/ui-diff.c | 12 | |
| -rwxr-xr-x | tests/t0107-diff.sh | 22 |
2 files changed, 30 insertions, 4 deletions
diff --git a/source/ui-diff.c b/source/ui-diff.c index 958d6e7..c696ab1 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -431,16 +431,20 @@ static void inspect_filepair(struct diff_filepair *pair) total_rems += lines_removed; } +/* + * The header names the path the request gave, which under follow is applied + * by show_filepair while the walk itself runs over the whole commit. + */ static void print_diffstat(const struct object_id *old_oid, const struct object_id *new_oid, - const char *prefix) + const char *prefix, const char *path) { int i; html("<div class='diffstat-header'>"); cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, NULL); - if (prefix) { + if (path) { html(" (limited to '"); - html_txt(prefix); + html_txt(path); html("')"); } html("</div>\n"); @@ -659,7 +663,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi if (difftype == DIFF_STATONLY) ctx.qry.difftype = ctx.cfg.difftype; - print_diffstat(old_rev_oid, new_rev_oid, prefix); + print_diffstat(old_rev_oid, new_rev_oid, prefix, path); if (difftype == DIFF_STATONLY) { if (show_ctrls) diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index 1f12220..861ca44 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -170,6 +170,28 @@ test_expect_success 'so does the commit page limited to the new name' ' ! grep "a/file-1 b/file-1" tmp ' +# Following a file diffs the whole commit and keeps the pairs on that path, +# and the header still names the path rather than the empty limit the walk +# runs under. +test_expect_success 'a followed file is diffed as the rename alone' ' + cgitrc_repo followrc moved enable-follow-links=1 && + cgit_ok followrc "url=moved/diff/new.txt&follow=1" >tmp && + grep "diff --git a/old.txt b/new.txt" tmp && + grep "Diffstat</a> (limited to .new.txt.)</div>" tmp && + grep "<div class=.diffstat-summary.>1 file changed, 0 insertions, 0 deletions</div>" tmp && + ! grep "a/file-1 b/file-1" tmp && + cgit_ok followrc "url=moved/commit/new.txt&follow=1" >tmp && + grep "diff --git a/old.txt b/new.txt" tmp && + grep "Diffstat</a> (limited to .new.txt.)</div>" tmp && + ! grep "a/file-1 b/file-1" tmp +' + +test_expect_success 'following with no path limits nothing' ' + cgit_ok followrc "url=moved/commit/&follow=1" >tmp && + grep "diff --git a/file-1 b/file-1" tmp && + grep "<div class=.diffstat-header.><a href=[^>]*>Diffstat</a></div>" tmp +' + test_expect_success 'a file added outright still shows as new' ' added=$(git -C repos/moved rev-parse HEAD~1) && cgit_ok movedrc "url=moved/diff/old.txt&id=$added" >tmp && |
