Skip to content

Commit cf861cd

Browse files
committed
Merge branch 'rs/get-tagged-oid'
Code cleanup. * rs/get-tagged-oid: use get_tagged_oid() tag: factor out get_tagged_oid()
2 parents 91243b0 + c77722b commit cf861cd

File tree

9 files changed

+18
-13
lines changed

9 files changed

+18
-13
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
313313
*/
314314
append_name(n, dst);
315315
if (longformat)
316-
append_suffix(0, n->tag ? &n->tag->tagged->oid : oid, dst);
316+
append_suffix(0, n->tag ? get_tagged_oid(n->tag) : oid, dst);
317317
if (suffix)
318318
strbuf_addstr(dst, suffix);
319319
return;

builtin/log.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
627627
break;
628628
case OBJ_TAG: {
629629
struct tag *t = (struct tag *)o;
630+
struct object_id *oid = get_tagged_oid(t);
630631

631632
if (rev.shown_one)
632633
putchar('\n');
@@ -638,10 +639,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
638639
rev.shown_one = 1;
639640
if (ret)
640641
break;
641-
o = parse_object(the_repository, &t->tagged->oid);
642+
o = parse_object(the_repository, oid);
642643
if (!o)
643644
ret = error(_("could not read object %s"),
644-
oid_to_hex(&t->tagged->oid));
645+
oid_to_hex(oid));
645646
objects[i].item = o;
646647
i--;
647648
break;

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static int check_one_mergetag(struct commit *commit,
421421
if (get_oid(mergetag_data->argv[i], &oid) < 0)
422422
return error(_("not a valid object name: '%s'"),
423423
mergetag_data->argv[i]);
424-
if (oideq(&tag->tagged->oid, &oid))
424+
if (oideq(get_tagged_oid(tag), &oid))
425425
return 0; /* found */
426426
}
427427

pack-bitmap.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs)
709709
else
710710
object_list_insert(object, &wants);
711711

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);
715713
}
716714

717715
if (object->flags & UNINTERESTING)

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ static int add_promisor_object(const struct object_id *oid,
21222122
oidset_insert(set, &parents->item->object.oid);
21232123
} else if (obj->type == OBJ_TAG) {
21242124
struct tag *tag = (struct tag *) obj;
2125-
oidset_insert(set, &tag->tagged->oid);
2125+
oidset_insert(set, get_tagged_oid(tag));
21262126
}
21272127
return 0;
21282128
}

ref-filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
17661766
* If it is a tag object, see if we use a value that derefs
17671767
* the object, and if we do grab the object it refers to.
17681768
*/
1769-
oi_deref.oid = ((struct tag *)obj)->tagged->oid;
1769+
oi_deref.oid = *get_tagged_oid((struct tag *)obj);
17701770

17711771
/*
17721772
* NEEDSWORK: This derefs tag only once, which
@@ -1997,7 +1997,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
19971997
if (!obj)
19981998
die(_("malformed object at '%s'"), refname);
19991999
if (obj->type == OBJ_TAG)
2000-
tagged_oid = &((struct tag *)obj)->tagged->oid;
2000+
tagged_oid = get_tagged_oid((struct tag *)obj);
20012001
if (tagged_oid && oid_array_lookup(points_at, tagged_oid) >= 0)
20022002
return tagged_oid;
20032003
return NULL;

revision.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ static struct commit *handle_commit(struct rev_info *revs,
404404
struct tag *tag = (struct tag *) object;
405405
if (revs->tag_objects && !(flags & UNINTERESTING))
406406
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));
410408
if (!object) {
411409
if (revs->ignore_missing_links || (flags & UNINTERESTING))
412410
return NULL;

tag.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,10 @@ int parse_tag(struct tag *item)
212212
free(data);
213213
return ret;
214214
}
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ struct object *deref_tag(struct repository *r, struct object *, const char *, in
1919
struct object *deref_tag_noverify(struct object *);
2020
int gpg_verify_tag(const struct object_id *oid,
2121
const char *name_to_report, unsigned flags);
22+
struct object_id *get_tagged_oid(struct tag *tag);
2223

2324
#endif /* TAG_H */

0 commit comments

Comments
 (0)