tag: support arbitrary repositories in parse_tag()

Allow callers of parse_tag() pass in the repository to use. Let most of them pass in the_repository to get the same result as before. One of them has stopped using the_repository in ef9b0370da (sha1-name.c: store and use repo in struct disambiguate_state, 2019-04-16); let it pass in its stored repository. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 28, 2025 at 19:10 UTC b6e4cc8c32850315323961659e553d1d14591f7f
8 files changed +13 -13
builtin/describe.c
+3 -3
@@ -112,13 +112,13 @@ static int replace_name(struct commit_name *e,
112
113 if (!e->tag) {
114 t = lookup_tag(the_repository, &e->oid);
115 - if (!t || parse_tag(t))
115 + if (!t || parse_tag(the_repository, t))
116 return 1;
117 e->tag = t;
118 }
119
120 t = lookup_tag(the_repository, oid);
121 - if (!t || parse_tag(t))
121 + if (!t || parse_tag(the_repository, t))
122 return 0;
123 *tag = t;
124
@@ -335,7 +335,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst)
335 {
336 if (n->prio == 2 && !n->tag) {
337 n->tag = lookup_tag(the_repository, &n->oid);
338 - if (!n->tag || parse_tag(n->tag))
338 + if (!n->tag || parse_tag(the_repository, n->tag))
339 die(_("annotated tag %s not available"), n->path);
340 }
341 if (n->tag && !n->name_checked) {
builtin/pack-objects.c
+1 -1
@@ -3293,7 +3293,7 @@ static void add_tag_chain(const struct object_id *oid)
3293
3294 tag = lookup_tag(the_repository, oid);
3295 while (1) {
3296 - if (!tag || parse_tag(tag) || !tag->tagged)
3296 + if (!tag || parse_tag(the_repository, tag) || !tag->tagged)
3297 die(_("unable to pack objects reachable from tag %s"),
3298 oid_to_hex(oid));
3299
fsck.c
+1 -1
@@ -474,7 +474,7 @@ static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *optio
474 {
475 const char *name = fsck_get_object_name(options, &tag->object.oid);
476
477 - if (parse_tag(tag))
477 + if (parse_tag(the_repository, tag))
478 return -1;
479 if (name)
480 fsck_put_object_name(options, &tag->tagged->oid, "%s", name);
object-name.c
+1 -1
@@ -449,7 +449,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
449 } else if (type == OBJ_TAG) {
450 struct tag *tag = lookup_tag(ds->repo, oid);
451
452 - if (!parse_tag(tag) && tag->tag) {
452 + if (!parse_tag(ds->repo, tag) && tag->tag) {
453 /*
454 * TRANSLATORS: This is a line of ambiguous
455 * tag object output. E.g.:
ref-filter.c
+1 -1
@@ -2866,7 +2866,7 @@ static int match_points_at(struct oid_array *points_at,
2866 while (obj && obj->type == OBJ_TAG) {
2867 struct tag *tag = (struct tag *)obj;
2868
2869 - if (parse_tag(tag) < 0) {
2869 + if (parse_tag(the_repository, tag) < 0) {
2870 obj = NULL;
2871 break;
2872 }
tag.c
+4 -4
@@ -13,6 +13,7 @@
13 #include "gpg-interface.h"
14 #include "hex.h"
15 #include "packfile.h"
16 +#include "repository.h"
17
18 const char *tag_type = "tag";
19
@@ -203,7 +204,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
204 return 0;
205 }
206
206 -int parse_tag(struct tag *item)
207 +int parse_tag(struct repository *r, struct tag *item)
208 {
209 enum object_type type;
210 void *data;
@@ -212,8 +213,7 @@ int parse_tag(struct tag *item)
213
214 if (item->object.parsed)
215 return 0;
215 - data = odb_read_object(the_repository->objects, &item->object.oid,
216 - &type, &size);
216 + data = odb_read_object(r->objects, &item->object.oid, &type, &size);
217 if (!data)
218 return error("Could not read %s",
219 oid_to_hex(&item->object.oid));
@@ -222,7 +222,7 @@ int parse_tag(struct tag *item)
222 return error("Object %s not a tag",
223 oid_to_hex(&item->object.oid));
224 }
225 - ret = parse_tag_buffer(the_repository, item, data, size);
225 + ret = parse_tag_buffer(r, item, data, size);
226 free(data);
227 return ret;
228 }
tag.h
+1 -1
@@ -13,7 +13,7 @@ struct tag {
13 };
14 struct tag *lookup_tag(struct repository *r, const struct object_id *oid);
15 int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size);
16 -int parse_tag(struct tag *item);
16 +int parse_tag(struct repository *r, struct tag *item);
17 void release_tag_memory(struct tag *t);
18 struct object *deref_tag(struct repository *r, struct object *, const char *, int);
19 int gpg_verify_tag(struct repository *r, const struct object_id *oid,
walker.c
+1 -1
@@ -115,7 +115,7 @@ static int process_commit(struct walker *walker, struct commit *commit)
115
116 static int process_tag(struct walker *walker, struct tag *tag)
117 {
118 - if (parse_tag(tag))
118 + if (parse_tag(the_repository, tag))
119 return -1;
120 return process(walker, tag->tagged);
121 }