diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 5478182f2e..5678731a04 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -272,6 +272,18 @@ static bool maybe_changed_path(struct last_modified *lm, if (!filter) return true; + /* + * With --show-trees we also track the tree entries containing the + * paths, so a change to any of those parent directories matters too. + */ + if (lm->show_trees) { + if (!revs_maybe_changed_in_bloom_with_parents(&lm->rev, filter)) + return false; + } else { + if (!revs_maybe_changed_in_bloom(&lm->rev, filter)) + return false; + } + hashmap_for_each_entry(&lm->paths, &iter, ent, hashent) { if (active && !bitmap_get(active, ent->diff_idx)) continue; diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh index 9dba4b9d90..df73c7d0d0 100755 --- a/t/t8020-last-modified.sh +++ b/t/t8020-last-modified.sh @@ -269,6 +269,27 @@ test_expect_success 'last-modified merge undoes changes' ' EOF ' +test_expect_success 'last-modified with Bloom filters and --show-trees' ' + test_when_finished rm -rf bloom && + git init bloom && + ( + cd bloom && + mkdir d && + test_commit base-a d/a && + test_commit base-b d/b && + test_commit touch-a d/a && + test_commit touch-b d/b && + + git commit-graph write --reachable --changed-paths && + git -c core.commitGraph=false last-modified -t HEAD -- d/a \ + >expect && + git -c core.commitGraph=true last-modified -t HEAD -- d/a \ + >actual && + + test_cmp expect actual + ) +' + test_expect_success 'cannot run last-modified on two commits' ' test_must_fail git last-modified HEAD HEAD~1 2>err && test_grep "last-modified can only operate on one commit at a time" err