tag: factor out get_tagged_oid()
authorRené Scharfe <l.s.r@web.de>
Thu, 5 Sep 2019 19:55:55 +0000 (21:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2019 21:10:18 +0000 (14:10 -0700)
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>
pack-bitmap.c
revision.c
tag.c
tag.h
index ed2befaac6535f25602fca57374d27d058277426..30842e1e742e112ed920ebf8a51f54e9c139c13c 100644 (file)
@@ -709,9 +709,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
                        else
                                object_list_insert(object, &wants);
 
-                       if (!tag->tagged)
-                               die("bad tag");
-                       object = parse_object_or_die(&tag->tagged->oid, NULL);
+                       object = parse_object_or_die(get_tagged_oid(tag), NULL);
                }
 
                if (object->flags & UNINTERESTING)
index 07412297f0248aae886eeb77c3a1cab13c93039c..ee1b1552b9df8d9374689c95b4ab70630280f573 100644 (file)
@@ -404,9 +404,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                struct tag *tag = (struct tag *) object;
                if (revs->tag_objects && !(flags & UNINTERESTING))
                        add_pending_object(revs, object, tag->tag);
-               if (!tag->tagged)
-                       die("bad tag");
-               object = parse_object(revs->repo, &tag->tagged->oid);
+               object = parse_object(revs->repo, get_tagged_oid(tag));
                if (!object) {
                        if (revs->ignore_missing_links || (flags & UNINTERESTING))
                                return NULL;
diff --git a/tag.c b/tag.c
index 5db870edb9e62e84f2117c2d25f2c3c4e0c616ec..bfa0e3143580f4f817fa0722a77224e81c58b615 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -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;
+}
diff --git a/tag.h b/tag.h
index 03265fbfe2942f9ca7409cb2b771b14edd9fb998..3ce8e7219244e1c2ca1c6bd31496e86a1dc25339 100644 (file)
--- a/tag.h
+++ b/tag.h
@@ -19,5 +19,6 @@ struct object *deref_tag(struct repository *r, struct object *, const char *, in
 struct object *deref_tag_noverify(struct object *);
 int gpg_verify_tag(const struct object_id *oid,
                   const char *name_to_report, unsigned flags);
+struct object_id *get_tagged_oid(struct tag *tag);
 
 #endif /* TAG_H */