]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: check pathspec against Bloom filter first
authorToon Claes <toon@iotcl.com>
Fri, 17 Jul 2026 15:47:01 +0000 (17:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Jul 2026 20:20:57 +0000 (13:20 -0700)
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>
builtin/last-modified.c

index 5478182f2e95c235357dbed778c10d4b656a1d62..e8ee61040457740b4c7e2d5cca2aaa4a6db78380 100644 (file)
@@ -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;