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>
René Scharfe committed
Sep 5, 2019 at 21:55 UTC
dad3f0607bf1c864f80723ab20b39527260f2c4f
4 files changed
+10
-6
pack-bitmap.c
+1
-3
@@ -709,9 +709,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
709
else
710
object_list_insert(object, &wants);
711
712
- if (!tag->tagged)
713
- die("bad tag");
714
- object = parse_object_or_die(&tag->tagged->oid, NULL);
712
+ object = parse_object_or_die(get_tagged_oid(tag), NULL);
713
}
714
715
if (object->flags & UNINTERESTING)
revision.c
+1
-3
@@ -404,9 +404,7 @@ static struct commit *handle_commit(struct rev_info *revs,
404
struct tag *tag = (struct tag *) object;
405
if (revs->tag_objects && !(flags & UNINTERESTING))
406
add_pending_object(revs, object, tag->tag);
407
- if (!tag->tagged)
408
- die("bad tag");
409
- object = parse_object(revs->repo, &tag->tagged->oid);
407
+ object = parse_object(revs->repo, get_tagged_oid(tag));
408
if (!object) {
409
if (revs->ignore_missing_links || (flags & UNINTERESTING))
410
return NULL;
tag.c
+7
@@ -212,3 +212,10 @@ int parse_tag(struct tag *item)
212
free(data);
213
return ret;
214
}
215
+
216
+struct object_id *get_tagged_oid(struct tag *tag)
217
+{
218
+ if (!tag->tagged)
219
+ die("bad tag");
220
+ return &tag->tagged->oid;
221
+}
tag.h
+1
@@ -19,5 +19,6 @@ struct object *deref_tag(struct repository *r, struct object *, const char *, in
19
struct object *deref_tag_noverify(struct object *);
20
int gpg_verify_tag(const struct object_id *oid,
21
const char *name_to_report, unsigned flags);
22
+struct object_id *get_tagged_oid(struct tag *tag);
23
24
#endif /* TAG_H */