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 <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Toon Claes committed Jul 17, 2026 at 17:47 UTC 31f4a59adba09f327e965694cae9c71e876266eb
1 file changed +3
builtin/last-modified.c
+3
@@ -272,6 +272,9 @@ static bool maybe_changed_path(struct last_modified *lm,
272 if (!filter)
273 return true;
274
275 + if (revs_maybe_changed_in_bloom(&lm->rev, filter) == 0)
276 + return false;
277 +
278 hashmap_for_each_entry(&lm->paths, &iter, ent, hashent) {
279 if (active && !bitmap_get(active, ent->diff_idx))
280 continue;