Skip to content

Commit 31224ce

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
path-walk API: avoid adding a root tree more than once
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]>
1 parent 0a26f35 commit 31224ce

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

path-walk.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,11 @@ static int setup_pending_objects(struct path_walk_info *info,
344344
struct object *obj = pending->item;
345345

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

350+
obj->flags |= SEEN;
351+
350352
/* Navigate annotated tag object chains. */
351353
while (obj->type == OBJ_TAG) {
352354
struct tag *tag = lookup_tag(info->revs->repo, &obj->oid);

t/t6601-path-walk.sh

+22
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,26 @@ test_expect_success 'trees are reported exactly once' '
397397
test_line_count = 1 out-filtered
398398
'
399399

400+
test_expect_success 'trees are reported exactly once' '
401+
test_when_finished "rm -rf unique-trees" &&
402+
test_create_repo unique-trees &&
403+
(
404+
cd unique-trees &&
405+
mkdir initial &&
406+
test_commit initial/file &&
407+
408+
git switch -c move-to-top &&
409+
git mv initial/file.t ./ &&
410+
test_tick &&
411+
git commit -m moved &&
412+
413+
git update-ref refs/heads/other HEAD
414+
) &&
415+
416+
test-tool -C unique-trees path-walk -- --all >out &&
417+
tree=$(git -C unique-trees rev-parse HEAD:) &&
418+
grep "$tree" out >out-filtered &&
419+
test_line_count = 1 out-filtered
420+
'
421+
400422
test_done

0 commit comments

Comments
 (0)