Merge branch 'rs/get-tagged-oid'

Code cleanup.

* rs/get-tagged-oid:
  use get_tagged_oid()
  tag: factor out get_tagged_oid()
maint
Junio C Hamano 2019-09-30 13:19:29 +09:00
commit cf861cd7a0
9 changed files with 18 additions and 13 deletions

View File

@ -313,7 +313,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
*/ */
append_name(n, dst); append_name(n, dst);
if (longformat) 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) if (suffix)
strbuf_addstr(dst, suffix); strbuf_addstr(dst, suffix);
return; return;

View File

@ -627,6 +627,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
break; break;
case OBJ_TAG: { case OBJ_TAG: {
struct tag *t = (struct tag *)o; struct tag *t = (struct tag *)o;
struct object_id *oid = get_tagged_oid(t);


if (rev.shown_one) if (rev.shown_one)
putchar('\n'); putchar('\n');
@ -638,10 +639,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
rev.shown_one = 1; rev.shown_one = 1;
if (ret) if (ret)
break; break;
o = parse_object(the_repository, &t->tagged->oid); o = parse_object(the_repository, oid);
if (!o) if (!o)
ret = error(_("could not read object %s"), ret = error(_("could not read object %s"),
oid_to_hex(&t->tagged->oid)); oid_to_hex(oid));
objects[i].item = o; objects[i].item = o;
i--; i--;
break; break;

View File

@ -421,7 +421,7 @@ static int check_one_mergetag(struct commit *commit,
if (get_oid(mergetag_data->argv[i], &oid) < 0) if (get_oid(mergetag_data->argv[i], &oid) < 0)
return error(_("not a valid object name: '%s'"), return error(_("not a valid object name: '%s'"),
mergetag_data->argv[i]); mergetag_data->argv[i]);
if (oideq(&tag->tagged->oid, &oid)) if (oideq(get_tagged_oid(tag), &oid))
return 0; /* found */ return 0; /* found */
} }



View File

@ -709,9 +709,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
else else
object_list_insert(object, &wants); object_list_insert(object, &wants);


if (!tag->tagged) object = parse_object_or_die(get_tagged_oid(tag), NULL);
die("bad tag");
object = parse_object_or_die(&tag->tagged->oid, NULL);
} }


if (object->flags & UNINTERESTING) if (object->flags & UNINTERESTING)

View File

@ -2122,7 +2122,7 @@ static int add_promisor_object(const struct object_id *oid,
oidset_insert(set, &parents->item->object.oid); oidset_insert(set, &parents->item->object.oid);
} else if (obj->type == OBJ_TAG) { } else if (obj->type == OBJ_TAG) {
struct tag *tag = (struct tag *) obj; struct tag *tag = (struct tag *) obj;
oidset_insert(set, &tag->tagged->oid); oidset_insert(set, get_tagged_oid(tag));
} }
return 0; return 0;
} }

View 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 * 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. * 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 * 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) if (!obj)
die(_("malformed object at '%s'"), refname); die(_("malformed object at '%s'"), refname);
if (obj->type == OBJ_TAG) 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) if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
return tagged_oid; return tagged_oid;
return NULL; return NULL;

View File

@ -404,9 +404,7 @@ static struct commit *handle_commit(struct rev_info *revs,
struct tag *tag = (struct tag *) object; struct tag *tag = (struct tag *) object;
if (revs->tag_objects && !(flags & UNINTERESTING)) if (revs->tag_objects && !(flags & UNINTERESTING))
add_pending_object(revs, object, tag->tag); add_pending_object(revs, object, tag->tag);
if (!tag->tagged) object = parse_object(revs->repo, get_tagged_oid(tag));
die("bad tag");
object = parse_object(revs->repo, &tag->tagged->oid);
if (!object) { if (!object) {
if (revs->ignore_missing_links || (flags & UNINTERESTING)) if (revs->ignore_missing_links || (flags & UNINTERESTING))
return NULL; return NULL;

7
tag.c
View File

@ -212,3 +212,10 @@ int parse_tag(struct tag *item)
free(data); free(data);
return ret; return ret;
} }

struct object_id *get_tagged_oid(struct tag *tag)
{
if (!tag->tagged)
die("bad tag");
return &tag->tagged->oid;
}

1
tag.h
View File

@ -19,5 +19,6 @@ struct object *deref_tag(struct repository *r, struct object *, const char *, in
struct object *deref_tag_noverify(struct object *); struct object *deref_tag_noverify(struct object *);
int gpg_verify_tag(const struct object_id *oid, int gpg_verify_tag(const struct object_id *oid,
const char *name_to_report, unsigned flags); const char *name_to_report, unsigned flags);
struct object_id *get_tagged_oid(struct tag *tag);


#endif /* TAG_H */ #endif /* TAG_H */