summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-09-05 19:55:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-09-05 21:10:18 (GMT)
commitdad3f0607bf1c864f80723ab20b39527260f2c4f (patch)
tree6244ac7c9264fa111df3523c8c384bb395abd98c
parent745f6812895b31c02b29bdfe4ae8e5498f776c26 (diff)
downloadgit-dad3f0607bf1c864f80723ab20b39527260f2c4f.zip
git-dad3f0607bf1c864f80723ab20b39527260f2c4f.tar.gz
git-dad3f0607bf1c864f80723ab20b39527260f2c4f.tar.bz2
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>
-rw-r--r--pack-bitmap.c4
-rw-r--r--revision.c4
-rw-r--r--tag.c7
-rw-r--r--tag.h1
4 files changed, 10 insertions, 6 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c
index ed2befa..30842e1 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -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)
diff --git a/revision.c b/revision.c
index 0741229..ee1b155 100644
--- a/revision.c
+++ b/revision.c
@@ -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 5db870e..bfa0e31 100644
--- 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 03265fb..3ce8e72 100644
--- 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 */