tag: factor out get_tagged_oid()

Add a function for accessing the ID of the object referenced by a tag
safely, i.e. without causing a segfault when encountering a broken tag
where ->tagged is NULL.

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-09-05 21:55:55 +02:00
committed by Junio C Hamano
parent 745f681289
commit dad3f0607b
4 changed files with 10 additions and 6 deletions

7
tag.c
View File

@ -212,3 +212,10 @@ int parse_tag(struct tag *item)
free(data);
return ret;
}
struct object_id *get_tagged_oid(struct tag *tag)
{
if (!tag->tagged)
die("bad tag");
return &tag->tagged->oid;
}