Skip to content

Commit 0abc7d3

Browse files
committed
path-walk API: avoid adding a root tree more than once (#5195)
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.
2 parents 47153c7 + 75b2232 commit 0abc7d3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

path-walk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,11 @@ static int setup_pending_objects(struct path_walk_info *info,
326326
struct object *obj = pending->item;
327327

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

332+
obj->flags |= SEEN;
333+
332334
/* Navigate annotated tag object chains. */
333335
while (obj->type == OBJ_TAG) {
334336
struct tag *tag = lookup_tag(info->revs->repo, &obj->oid);

t/t6601-path-walk.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,26 @@ test_expect_success 'trees are reported exactly once' '
365365
test_line_count = 1 out-filtered
366366
'
367367

368+
test_expect_success 'trees are reported exactly once' '
369+
test_when_finished "rm -rf unique-trees" &&
370+
test_create_repo unique-trees &&
371+
(
372+
cd unique-trees &&
373+
mkdir initial &&
374+
test_commit initial/file &&
375+
376+
git switch -c move-to-top &&
377+
git mv initial/file.t ./ &&
378+
test_tick &&
379+
git commit -m moved &&
380+
381+
git update-ref refs/heads/other HEAD
382+
) &&
383+
384+
test-tool -C unique-trees path-walk -- --all >out &&
385+
tree=$(git -C unique-trees rev-parse HEAD:) &&
386+
grep "$tree" out >out-filtered &&
387+
test_line_count = 1 out-filtered
388+
'
389+
368390
test_done

0 commit comments

Comments
 (0)