From 22f8de0f4f9b60ba3c6d3cc164cdf07ff988d2a4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 22:07:47 -1000 Subject: Show a renamed file's diff as the rename A diff limited to the new name cannot see the old one, so the diffstat's link for a renamed file, the commit page reached from that file's log, and the file's rawdiff and patch all showed every line as added. A path the old tree lacks is now diffed across the whole commit with rename detection aimed at it alone, the way git blame looks for a rename, so it is compared with the commit's deleted files and nothing else. Doing it in cgit_diff_tree keeps the log's counts for that commit in step with the page they link to. The rawdiff and patch pages leave the diff to git's own output, so for them that search finds the old name, and both names go into the limit with rename detection on. --- source/ui-patch.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/ui-patch.c') diff --git a/source/ui-patch.c b/source/ui-patch.c index 0fa9a2e..a60e7cc 100644 --- a/source/ui-patch.c +++ b/source/ui-patch.c @@ -12,6 +12,7 @@ #include "html.h" #include "ui-patch.h" #include "ui-shared.h" +#include "shared.h" // Room for two hex object ids, the two dots between them, and the null byte. #define REV_RANGE_LEN (2 * GIT_MAX_HEXSZ + 3) @@ -24,6 +25,7 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref struct strvec rev_argv = STRVEC_INIT; char rev_range[REV_RANGE_LEN]; const char *version; + char *source = NULL; if (!new_rev) new_rev = ctx.qry.head; @@ -47,9 +49,20 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref else strvec_push(&rev_argv, "--format=format:From %H Mon Sep 17 00:00:00 2001%n" "From: %an%nDate: %aD%n%w(78,0,1)Subject: %s%n%n%w(0)%b"); + // A file the change renamed is limited by its old name as well, with + // rename detection on, so that git pairs the two into the rename. That + // name comes from the tree rather than the request, so it is matched + // literally. + if (prefix) + source = cgit_rename_source(&old_oid, &new_oid, prefix); + if (source) + strvec_push(&rev_argv, "-M"); strvec_pushl(&rev_argv, rev_range, "--", NULL); if (prefix) strvec_push(&rev_argv, prefix); + if (source) + strvec_pushf(&rev_argv, ":(literal)%s", source); + free(source); // Git inlines a blob up to its own big-file threshold, far past what // any other view inflates, so max-blob-size is applied through it. -- cgit 2.12.1