Skip to content

Commit

Permalink
path-walk API: avoid adding a root tree more than once
Browse files Browse the repository at this point in the history
When adding tree objects, we are very careful to avoid adding the same
tree object more than once. There was one small gap in that logic,
though: when adding a root tree object. Two refs can easily share the
same root tree object, and we should still not add it more than once.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho authored and Git for Windows Build Agent committed Feb 13, 2025
1 parent 54082ae commit 4cd0f5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion path-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,11 @@ static int setup_pending_objects(struct path_walk_info *info,
struct object *obj = pending->item;

/* Commits will be picked up by revision walk. */
if (obj->type == OBJ_COMMIT)
if (obj->type == OBJ_COMMIT || obj->flags & SEEN)
continue;

obj->flags |= SEEN;

/* Navigate annotated tag object chains. */
while (obj->type == OBJ_TAG) {
struct tag *tag = lookup_tag(info->revs->repo, &obj->oid);
Expand Down
22 changes: 22 additions & 0 deletions t/t6601-path-walk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,26 @@ test_expect_success 'trees are reported exactly once' '
test_line_count = 1 out-filtered
'

test_expect_success 'trees are reported exactly once' '
test_when_finished "rm -rf unique-trees" &&
test_create_repo unique-trees &&
(
cd unique-trees &&
mkdir initial &&
test_commit initial/file &&
git switch -c move-to-top &&
git mv initial/file.t ./ &&
test_tick &&
git commit -m moved &&
git update-ref refs/heads/other HEAD
) &&
test-tool -C unique-trees path-walk -- --all >out &&
tree=$(git -C unique-trees rev-parse HEAD:) &&
grep "$tree" out >out-filtered &&
test_line_count = 1 out-filtered
'

test_done

0 comments on commit 4cd0f5d

Please sign in to comment.