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 <stsp@stsp.name>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2019-08-29 21:06:22 +02:00 коммит произвёл Junio C Hamano
Родитель 745f681289
Коммит 1577dc0f7c
1 изменённых файлов: 3 добавлений и 15 удалений

18
tree.c
Просмотреть файл

@ -244,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
struct tree *parse_tree_indirect(const struct object_id *oid) struct tree *parse_tree_indirect(const struct object_id *oid)
{ {
struct object *obj = parse_object(the_repository, oid); struct repository *r = the_repository;
do { struct object *obj = parse_object(r, oid);
if (!obj) return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
return NULL;
if (obj->type == OBJ_TREE)
return (struct tree *) obj;
else if (obj->type == OBJ_COMMIT)
obj = &(get_commit_tree(((struct commit *)obj))->object);
else if (obj->type == OBJ_TAG)
obj = ((struct tag *) obj)->tagged;
else
return NULL;
if (!obj->parsed)
parse_object(the_repository, &obj->oid);
} while (1);
} }