Skip to content

Commit 1577dc0

Browse files
rscharfegitster
authored andcommitted
tree: simplify parse_tree_indirect()
Reduce code duplication by turning parse_tree_indirect() into a wrapper of repo_peel_to_type(). This avoids a segfault when handling a broken tag where ->tagged is NULL. The new version also checks the return value of parse_object() that was ignored by the old one. Initial-patch-by: Stefan Sperling <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 745f681 commit 1577dc0

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

tree.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
244244

245245
struct tree *parse_tree_indirect(const struct object_id *oid)
246246
{
247-
struct object *obj = parse_object(the_repository, oid);
248-
do {
249-
if (!obj)
250-
return NULL;
251-
if (obj->type == OBJ_TREE)
252-
return (struct tree *) obj;
253-
else if (obj->type == OBJ_COMMIT)
254-
obj = &(get_commit_tree(((struct commit *)obj))->object);
255-
else if (obj->type == OBJ_TAG)
256-
obj = ((struct tag *) obj)->tagged;
257-
else
258-
return NULL;
259-
if (!obj->parsed)
260-
parse_object(the_repository, &obj->oid);
261-
} while (1);
247+
struct repository *r = the_repository;
248+
struct object *obj = parse_object(r, oid);
249+
return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
262250
}

0 commit comments

Comments
 (0)