Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path-walk API: avoid adding a root tree more than once #5195

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions path-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ int walk_objects_by_path(struct path_walk_info *info)
struct object_array_entry *pending = info->revs->pending.objects + i;
struct object *obj = pending->item;

if (obj->type == OBJ_COMMIT)
if (obj->type == OBJ_COMMIT || obj->flags & SEEN)
continue;

obj->flags |= SEEN;

while (obj->type == OBJ_TAG) {
struct tag *tag = lookup_tag(info->revs->repo,
&obj->oid);
Expand Down Expand Up @@ -358,9 +360,13 @@ int walk_objects_by_path(struct path_walk_info *info)
oid = get_commit_tree_oid(c);
t = lookup_tree(info->revs->repo, oid);

if (t->object.flags & SEEN)
continue;
t->object.flags |= SEEN;

if (t) {
oidset_insert(&root_tree_set, oid);
oid_array_append(&root_tree_list->oids, oid);
if (!oidset_insert(&root_tree_set, oid))
oid_array_append(&root_tree_list->oids, oid);
} else {
warning("could not find tree %s", oid_to_hex(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 @@ -311,4 +311,26 @@ test_expect_success 'topic, not base, boundary with pruning' '
test_cmp expect.sorted out.sorted
'

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
Loading