From: Jeff King Date: Sun, 26 Jul 2026 08:47:05 +0000 (-0400) Subject: diff-lib: skip paths outside prefix in oneway_diff() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=151726d3ca54cbd279d527dc048133ead5c8b582;p=thirdparty%2Fgit.git 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 --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)) {