From 640177a987270564a8ef90cdc359677209fbe0fe Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Jul 2026 04:46:22 -0400 Subject: [PATCH 1/2] diff-lib: drop stale comment about advancing o->pos The comment above oneway_diff() claims that the callback must advance o->pos to skip index entries it has already processed. That stopped being true in da165f470e (unpack-trees.c: prepare for looking ahead in the index, 2010-01-07), which moved that bookkeeping into unpack_trees(). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff-lib.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 0e868b28b6..bcab7c8500 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -508,11 +508,9 @@ static void do_oneway_diff(struct unpack_trees_options *o, * For diffing, the index is more important, and we only have a * single tree. * - * We're supposed to advance o->pos to skip what we have already processed. - * * This wrapper makes it all more readable, and takes care of all * the fairly complex unpack_trees() semantic requirements, including - * the skipping, the path matching, the type conflict cases etc. + * the path matching, the type conflict cases etc. */ static int oneway_diff(const struct cache_entry * const *src, struct unpack_trees_options *o) From 151726d3ca54cbd279d527dc048133ead5c8b582 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 26 Jul 2026 04:47:05 -0400 Subject: [PATCH 2/2] diff-lib: skip paths outside prefix in oneway_diff() Commit 8174627b3d (diff-lib: ignore paths that are outside $cwd if --relative asked, 2021-08-22) taught run_diff_files() to skip entries outside the requested prefix before processing them. Do the same in oneway_diff(), which handles the diff-index code path. The lower-level diff queue functions already reject such paths, but checking here avoids unnecessary work and keeps them out of every do_oneway_diff() code path. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff-lib.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index bcab7c8500..d07e5d8d5b 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -538,6 +538,11 @@ static int oneway_diff(const struct cache_entry * const *src, if (!idx && !tree) BUG("oneway_diff with neither idx nor tree"); + if (revs->diffopt.prefix && + strncmp((idx ? idx : tree)->name, revs->diffopt.prefix, + revs->diffopt.prefix_length)) + return 0; + if (ce_path_match(revs->diffopt.repo->index, idx ? idx : tree, &revs->prune_data, NULL)) {