From: Muhammed Dilshad A Date: Wed, 07 Oct 2026 16:35:14 GMT Subject: [PATCH v2 2/2] combine-diff: filter the fast scan by the relative prefix Message-ID: In-Reply-To: The pairwise scan filters paths by --relative before looking for renames. The fast scan bypasses those callbacks, so it can show changes outside the requested prefix. Filter the fast scan's paths by the same literal prefix and release the discarded records. Add tests for excluding outside paths and for keeping explicit prefixes with repeated separators literal, as ordinary diff does. Helped-by: Junio C Hamano Signed-off-by: Muhammed Dilshad A --- combine-diff.c | 18 ++++++++++++++++++ t/t4038-diff-combined.sh | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/combine-diff.c b/combine-diff.c index d615471717..e8a3bd1ee9 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1474,6 +1474,24 @@ static struct combine_diff_path *find_paths_multitree( strbuf_release(&base); free(parents_oid); + + /* Match the prefix filtering used by the pairwise scan. */ + if (opt->prefix) { + struct combine_diff_path **tail = &paths; + + while (*tail) { + struct combine_diff_path *p = *tail; + + if (starts_with(p->path, opt->prefix)) { + tail = &p->next; + continue; + } + *tail = p->next; + for (i = 0; i < nparent; i++) + free(p->parent[i].path); + free(p); + } + } return paths; } diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 21eeb4fbcb..50df3dfb46 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -652,4 +652,25 @@ test_expect_success 'combined raw relative diff follows an outside rename source test_cmp expect actual ' +test_expect_success 'fast combined relative diff excludes outside paths' ' + ours_oid=$(git -C cross-prefix rev-parse HEAD^:here/file) && + merged_oid=$(git -C cross-prefix rev-parse HEAD:here/file) && + printf "::100644 000000 100644 %s %s %s MA\tfile\tfile\tfile\n" \ + "$ours_oid" "$ZERO_OID" "$merged_oid" >expect && + git -C cross-prefix diff-tree --no-commit-id -c --raw --no-renames \ + --combined-all-paths --relative=here/ HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'combined diff keeps explicit relative prefixes literal' ' + git -C cross-prefix diff HEAD^ HEAD --relative=here// >actual && + test_must_be_empty actual && + git -C cross-prefix diff-tree --no-commit-id --cc -M \ + --combined-all-paths --relative=here// HEAD >actual && + test_must_be_empty actual && + git -C cross-prefix diff-tree --no-commit-id --cc --no-renames \ + --combined-all-paths --relative=here// HEAD >actual && + test_must_be_empty actual +' + test_done -- 2.55.0