Merge branch 'rs/get-tagged-oid'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:29 +0000 (13:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2019 04:19:29 +0000 (13:19 +0900)
Code cleanup.

* rs/get-tagged-oid:
use get_tagged_oid()
tag: factor out get_tagged_oid()

builtin/describe.c
builtin/log.c
builtin/replace.c
pack-bitmap.c
packfile.c
ref-filter.c
revision.c
tag.c
tag.h
index 200154297d5ea8baddda52e39cd4de302595bfcc..e048f85484c5ea2bd1d6b684aa10b407b2699c45 100644 (file)
@@ -313,7 +313,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
                 */
                append_name(n, dst);
                if (longformat)
-                       append_suffix(0, n->tag ? &n->tag->tagged->oid : oid, dst);
+                       append_suffix(0, n->tag ? get_tagged_oid(n->tag) : oid, dst);
                if (suffix)
                        strbuf_addstr(dst, suffix);
                return;
index 44b10b3415414c0723ace29d9defb62c1354e9d6..c4b35fdaf9b77c05da927fb3a2800a7fd8da9f91 100644 (file)
@@ -627,6 +627,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                        break;
                case OBJ_TAG: {
                        struct tag *t = (struct tag *)o;
+                       struct object_id *oid = get_tagged_oid(t);
 
                        if (rev.shown_one)
                                putchar('\n');
@@ -638,10 +639,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                        rev.shown_one = 1;
                        if (ret)
                                break;
-                       o = parse_object(the_repository, &t->tagged->oid);
+                       o = parse_object(the_repository, oid);
                        if (!o)
                                ret = error(_("could not read object %s"),
-                                           oid_to_hex(&t->tagged->oid));
+                                           oid_to_hex(oid));
                        objects[i].item = o;
                        i--;
                        break;
index 644b21ca8d57a75fa83ecbf0e58dd07a685cd9e4..2a4afb3b932c79a1ed04bdd283d810813d5c4a66 100644 (file)
@@ -421,7 +421,7 @@ static int check_one_mergetag(struct commit *commit,
                if (get_oid(mergetag_data->argv[i], &oid) < 0)
                        return error(_("not a valid object name: '%s'"),
                                     mergetag_data->argv[i]);
-               if (oideq(&tag->tagged->oid, &oid))
+               if (oideq(get_tagged_oid(tag), &oid))
                        return 0; /* found */
        }
 
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 1a7d69fe32a8808dd34063c48daf61e32886b47a..f3f962af4c6ccce48a5a0175ae95de9a171288c0 100644 (file)
@@ -2122,7 +2122,7 @@ static int add_promisor_object(const struct object_id *oid,
                        oidset_insert(set, &parents->item->object.oid);
        } else if (obj->type == OBJ_TAG) {
                struct tag *tag = (struct tag *) obj;
-               oidset_insert(set, &tag->tagged->oid);
+               oidset_insert(set, get_tagged_oid(tag));
        }
        return 0;
 }
index 7338cfc67158ede687ba2c410ca6de29e414f5c4..220e9bd74a507cb5e73fcdd64e88ab3ff384baff 100644 (file)
@@ -1766,7 +1766,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
         * If it is a tag object, see if we use a value that derefs
         * the object, and if we do grab the object it refers to.
         */
-       oi_deref.oid = ((struct tag *)obj)->tagged->oid;
+       oi_deref.oid = *get_tagged_oid((struct tag *)obj);
 
        /*
         * NEEDSWORK: This derefs tag only once, which
@@ -1997,7 +1997,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
        if (!obj)
                die(_("malformed object at '%s'"), refname);
        if (obj->type == OBJ_TAG)
-               tagged_oid = &((struct tag *)obj)->tagged->oid;
+               tagged_oid = get_tagged_oid((struct tag *)obj);
        if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
                return tagged_oid;
        return NULL;
index 51690e480d5b626224e919f04dbfb8d1c3426f3e..a2406c451925f42dad2f7b5851c7ce7c48b64eff 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 */