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-diff.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source/ui-diff.c') diff --git a/source/ui-diff.c b/source/ui-diff.c index 315a8f0..0e2e75e 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -510,8 +510,15 @@ static void print_raw_patch(const struct object_id *old_tree_oid, const struct o repo_diff_setup(the_repository, &diffopt); diffopt.output_format = DIFF_FORMAT_PATCH; diffopt.flags.recursive = 1; - if (prefix) - cgit_diff_limit_path(&diffopt, prefix); + if (prefix) { + char *source = cgit_rename_source(old_tree_oid, new_tree_oid, prefix); + + if (source) + cgit_diff_limit_rename(&diffopt, prefix, source); + else + cgit_diff_limit_path(&diffopt, prefix); + free(source); + } diff_setup_done(&diffopt); ctx.page.mimetype = "text/plain"; -- cgit 2.12.1