From: Toon Claes Date: Fri, 17 Jul 2026 15:47:01 +0000 (+0200) Subject: last-modified: check pathspec against Bloom filter first X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=31f4a59adba09f327e965694cae9c71e876266eb;p=thirdparty%2Fgit.git last-modified: check pathspec against Bloom filter first When git-last-modified(1) starts, it builds a list of all the paths matching the pathspec it needs to find the last modifying commit for. For example, every file and subdirectory listed by: $ git last-modified -t --max-depth=0 -- src/ As it resolves a commit for each path during the revision walk, it drops that path from the list. To avoid diffing trees for every commit, Bloom filters are used when available. For each remaining path, the commit's Bloom filter is checked to see whether the commit changed that path. The Bloom filter says either "no" or "maybe", and only in the latter case is the diff calculated. git-log(1) does this differently. It does not expand the pathspec but checks the Bloom filter against the pathspec itself. This way, commits not touching any path matching the pathspec can be discarded as a whole. Apply this same check to git-last-modified(1). In a previous commit the function revs_maybe_changed_in_bloom(), used by git-log(1), was made public. Use this as a pre-filter in git-last-modified(1). After this pre-filter, paths are still checked one-by-one to only find those which don't have a "last commit" yet. Signed-off-by: Toon Claes Signed-off-by: Junio C Hamano --- diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 5478182f2e..e8ee610404 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -272,6 +272,9 @@ static bool maybe_changed_path(struct last_modified *lm, if (!filter) return true; + if (revs_maybe_changed_in_bloom(&lm->rev, filter) == 0) + return false; + hashmap_for_each_entry(&lm->paths, &iter, ent, hashent) { if (active && !bitmap_get(active, ent->diff_idx)) continue;