git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] last-modified: check pathspec against Bloom filter first

From
Jeff King <peff@peff.net>
Date
Jul 18, 2026, 08:37 UTC
Message-ID
<20260718083757.GD22588@coredump.intra.peff.net>
In-Reply-To
<alq1Q55ezuN9ZI9j@com-79390>
On Fri, Jul 17, 2026 at 06:05:39PM -0500, Taylor Blau wrote:
Show 11 quoted lines
> > 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)
> 
> Nit: please prefer 'if (!foo())' over 'if (foo() == 0)'.

Yeah, though there is some subtlety here because of the tristate return I described elsewhere in the thread. I think if we switch to a boolean return then a straight "!" becomes even more desirable.

> I don't think this is safe with '--show-trees'. The original pathspec
> does not cover every entry in 'lm->paths', since the function
> 'populate_paths_from_revs()' also adds ancestor tree entries.

Hmm, interesting. I am surprised to learn that "-t" includes "d" when the pathspec asked for "d/a". I thought it was mostly about showing "d/a" when we recurse to find "d/a/b". But I guess it does not make a distinction between the two (probably because it is just telling the diff code to show trees, and it does not further apply the pathspec to the output).

Does this mean there is also a bug in "git log"? I guess not, because it is purely pruning based on the pathspec, and only shows "d/" for those commits.

>         git -c core.commitGraph=false last-modified -t HEAD -- d/a \
>             >expect &&
>         git -c core.commitGraph=true last-modified -t HEAD -- d/a \
>             >actual &&

A minor side note: the documentation claims "-t" has no effect without "-r", but it clearly is not true (it tells us to show "d", even when we are not recursing).

Show 6 quoted lines
> I think that the conditional is otherwise correct, if guarded when we
> know that 'lm->show_trees' is false, like so:
> 
>     if (!lm->show_trees &&
>         !revs_maybe_changed_in_bloom(&lm->rev, filter))
>             return false;

Hmph. That makes this optimization all but useless, because the intended use case of last-modified is almost always going to use "-t" to be able to mark the interior trees. And most callers are not going to care about seeing "d" here; their purpose was to find out about the things _inside_ "d".

Would we consider removing "d" from the output for this case? Presumably by double-checking the pathspecs again in add_path_from_diff(). That gives less surprising output (to me, anyway) and would enable this optimization. And the command is still marked as experimental, and I think this is exactly the kind of corner case that is meant to cover.

-Peff
Previous: Taylor BlauNext: Taylor Blau
Message 11 of 30 in “last-modified: use the pathspec's Bloom key to pre-filter commits”
  1. 0/4 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Jul 17, 2026
  2. 1/4 revision: move bloom keyvec precondition into functionToon Claes, Jul 17, 2026
  3. Jeff KingJul 18, 2026
  4. Toon ClaesAug 5, 2026
  5. Jeff KingAug 5, 2026
  6. 2/4 revision: expose check for paths maybe changed in Bloom filterToon Claes, Jul 17, 2026
  7. Junio C HamanoJul 17, 2026
  8. Taylor BlauJul 17, 2026
  9. 3/4 last-modified: check pathspec against Bloom filter firstToon Claes, Jul 17, 2026
  10. Taylor BlauJul 17, 2026
  11. Jeff KingJul 18, 2026
  12. Taylor BlauJul 18, 2026
  13. Jeff KingJul 20, 2026
  14. 4/4 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Jul 17, 2026
  15. Toon ClaesJul 17, 2026
  16. Jeff KingJul 18, 2026
  17. Junio C HamanoAug 4, 2026
  18. Taylor BlauAug 5, 2026
  19. Junio C HamanoAug 5, 2026
  20. Jeff KingAug 5, 2026
  21. Taylor BlauJul 17, 2026
  22. Toon ClaesJul 17, 2026
  23. 0/6 last-modified: use the pathspec's Bloom key to pre-filter commitsToon Claes, Aug 7, 2026
  24. 1/6 revision: move bloom keyvec precondition into functionToon Claes, Aug 7, 2026
  25. 2/6 revision: expose check for paths maybe changed in Bloom filterToon Claes, Aug 7, 2026
  26. 3/6 bloom: add helper to check if any key in a vector is presentToon Claes, Aug 7, 2026
  27. 4/6 revision: add Bloom check that includes parent directoriesToon Claes, Aug 7, 2026
  28. 5/6 last-modified: check pathspec against Bloom filter firstToon Claes, Aug 7, 2026
  29. 6/6 last-modified: keep per-path Bloom filters for wildcard pathspecsToon Claes, Aug 7, 2026
  30. Junio C HamanoAug 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.