summaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-08-29 19:06:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-09-03 22:10:53 (GMT)
commit1577dc0f7c1326ce59e1e97fad8a0b1e8c826203 (patch)
tree3902021af0fa77ff2a87fd1cbaa1c68a45211c82 /tree.c
parent745f6812895b31c02b29bdfe4ae8e5498f776c26 (diff)
downloadgit-1577dc0f7c1326ce59e1e97fad8a0b1e8c826203.zip
git-1577dc0f7c1326ce59e1e97fad8a0b1e8c826203.tar.gz
git-1577dc0f7c1326ce59e1e97fad8a0b1e8c826203.tar.bz2
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>
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/tree.c b/tree.c
index 4720945..1466bcc 100644
--- a/tree.c
+++ b/tree.c
@@ -244,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
struct tree *parse_tree_indirect(const struct object_id *oid)
{
- struct object *obj = parse_object(the_repository, oid);
- do {
- if (!obj)
- 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);
+ struct repository *r = the_repository;
+ struct object *obj = parse_object(r, oid);
+ return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
}