tag: add repository argument to deref_tag

Add a repository argument to allow the callers of deref_tag to be more specific about which repository to act on. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jun 28, 2018 at 18:22 UTC a74093da5ed601a09fa158e5ba6f6f14c1142a3e
18 files changed +42 -26
blame.c
+3 -3
@@ -1674,7 +1674,7 @@ static struct commit *find_single_final(struct rev_info *revs,
1674 struct object *obj = revs->pending.objects[i].item;
1675 if (obj->flags & UNINTERESTING)
1676 continue;
1677 - obj = deref_tag(obj, NULL, 0);
1677 + obj = deref_tag(the_repository, obj, NULL, 0);
1678 if (obj->type != OBJ_COMMIT)
1679 die("Non commit %s?", revs->pending.objects[i].name);
1680 if (found)
@@ -1705,7 +1705,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
1705
1706 /* Is that sole rev a committish? */
1707 obj = revs->pending.objects[0].item;
1708 - obj = deref_tag(obj, NULL, 0);
1708 + obj = deref_tag(the_repository, obj, NULL, 0);
1709 if (obj->type != OBJ_COMMIT)
1710 return NULL;
1711
@@ -1741,7 +1741,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
1741 struct object *obj = revs->pending.objects[i].item;
1742 if (!(obj->flags & UNINTERESTING))
1743 continue;
1744 - obj = deref_tag(obj, NULL, 0);
1744 + obj = deref_tag(the_repository, obj, NULL, 0);
1745 if (obj->type != OBJ_COMMIT)
1746 die("Non commit %s?", revs->pending.objects[i].name);
1747 if (found)
builtin/diff.c
+1 -1
@@ -402,7 +402,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
402 int flags = (obj->flags & UNINTERESTING);
403 if (!obj->parsed)
404 obj = parse_object(the_repository, &obj->oid);
405 - obj = deref_tag(obj, NULL, 0);
405 + obj = deref_tag(the_repository, obj, NULL, 0);
406 if (!obj)
407 die(_("invalid object '%s' given."), name);
408 if (obj->type == OBJ_COMMIT)
builtin/fmt-merge-msg.c
+2 -1
@@ -344,7 +344,8 @@ static void shortlog(const char *name,
344 const struct object_id *oid = &origin_data->oid;
345 int limit = opts->shortlog_len;
346
347 - branch = deref_tag(parse_object(the_repository, oid), oid_to_hex(oid),
347 + branch = deref_tag(the_repository, parse_object(the_repository, oid),
348 + oid_to_hex(oid),
349 GIT_SHA1_HEXSZ);
350 if (!branch || branch->type != OBJ_COMMIT)
351 return;
builtin/grep.c
+2 -1
@@ -647,7 +647,8 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
647
648 for (i = 0; i < nr; i++) {
649 struct object *real_obj;
650 - real_obj = deref_tag(list->objects[i].item, NULL, 0);
650 + real_obj = deref_tag(the_repository, list->objects[i].item,
651 + NULL, 0);
652
653 /* load the gitmodules file for this rev */
654 if (recurse_submodules) {
builtin/name-rev.c
+2 -1
@@ -455,7 +455,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
455 commit = NULL;
456 object = parse_object(the_repository, &oid);
457 if (object) {
458 - struct object *peeled = deref_tag(object, *argv, 0);
458 + struct object *peeled = deref_tag(the_repository,
459 + object, *argv, 0);
460 if (peeled && peeled->type == OBJ_COMMIT)
461 commit = (struct commit *)peeled;
462 }
commit.c
+2 -1
@@ -27,7 +27,8 @@ const char *commit_type = "commit";
27 struct commit *lookup_commit_reference_gently_the_repository(
28 const struct object_id *oid, int quiet)
29 {
30 - struct object *obj = deref_tag(parse_object(the_repository, oid),
30 + struct object *obj = deref_tag(the_repository,
31 + parse_object(the_repository, oid),
32 NULL, 0);
33
34 if (!obj)
fetch-pack.c
+6 -3
@@ -126,7 +126,8 @@ static void rev_list_push(struct commit *commit, int mark)
126
127 static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
128 {
129 - struct object *o = deref_tag(parse_object(the_repository, oid),
129 + struct object *o = deref_tag(the_repository,
130 + parse_object(the_repository, oid),
131 refname, 0);
132
133 if (o && o->type == OBJ_COMMIT)
@@ -144,7 +145,8 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id *
145 static int clear_marks(const char *refname, const struct object_id *oid,
146 int flag, void *cb_data)
147 {
147 - struct object *o = deref_tag(parse_object(the_repository, oid),
148 + struct object *o = deref_tag(the_repository,
149 + parse_object(the_repository, oid),
150 refname, 0);
151
152 if (o && o->type == OBJ_COMMIT)
@@ -802,7 +804,8 @@ static int everything_local(struct fetch_pack_args *args,
804 * Don't mark them common yet; the server has to be told so first.
805 */
806 for (ref = *refs; ref; ref = ref->next) {
805 - struct object *o = deref_tag(lookup_object(the_repository,
807 + struct object *o = deref_tag(the_repository,
808 + lookup_object(the_repository,
809 ref->old_oid.hash),
810 NULL, 0);
811
http-backend.c
+1 -1
@@ -442,7 +442,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
442
443 strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons);
444 if (o->type == OBJ_TAG) {
445 - o = deref_tag(o, name, 0);
445 + o = deref_tag(the_repository, o, name, 0);
446 if (!o)
447 return 0;
448 strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
http-push.c
+1 -1
@@ -1477,7 +1477,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1477 oid_to_hex(&ref->old_oid), ls->dentry_name);
1478
1479 if (o->type == OBJ_TAG) {
1480 - o = deref_tag(o, ls->dentry_name, 0);
1480 + o = deref_tag(the_repository, o, ls->dentry_name, 0);
1481 if (o)
1482 strbuf_addf(buf, "%s\t%s^{}\n",
1483 oid_to_hex(&o->oid), ls->dentry_name);
line-log.c
+1 -1
@@ -479,7 +479,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
479 struct object *obj = revs->pending.objects[i].item;
480 if (obj->flags & UNINTERESTING)
481 continue;
482 - obj = deref_tag(obj, NULL, 0);
482 + obj = deref_tag(the_repository, obj, NULL, 0);
483 if (obj->type != OBJ_COMMIT)
484 die("Non commit %s?", revs->pending.objects[i].name);
485 if (commit)
merge-recursive.c
+2 -1
@@ -3467,7 +3467,8 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
3467 {
3468 struct object *object;
3469
3470 - object = deref_tag(parse_object(the_repository, oid), name,
3470 + object = deref_tag(the_repository, parse_object(the_repository, oid),
3471 + name,
3472 strlen(name));
3473 if (!object)
3474 return NULL;
remote.c
+4 -2
@@ -1802,12 +1802,14 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
1802 * Both new_commit and old_commit must be commit-ish and new_commit is descendant of
1803 * old_commit. Otherwise we require --force.
1804 */
1805 - o = deref_tag(parse_object(the_repository, old_oid), NULL, 0);
1805 + o = deref_tag(the_repository, parse_object(the_repository, old_oid),
1806 + NULL, 0);
1807 if (!o || o->type != OBJ_COMMIT)
1808 return 0;
1809 old_commit = (struct commit *) o;
1810
1810 - o = deref_tag(parse_object(the_repository, new_oid), NULL, 0);
1811 + o = deref_tag(the_repository, parse_object(the_repository, new_oid),
1812 + NULL, 0);
1813 if (!o || o->type != OBJ_COMMIT)
1814 return 0;
1815 new_commit = (struct commit *) o;
server-info.c
+1 -1
@@ -64,7 +64,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
64 return -1;
65
66 if (o->type == OBJ_TAG) {
67 - o = deref_tag(o, path, 0);
67 + o = deref_tag(the_repository, o, path, 0);
68 if (o)
69 if (fprintf(fp, "%s %s^{}\n",
70 oid_to_hex(&o->oid), path) < 0)
sha1-name.c
+7 -4
@@ -239,7 +239,8 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
239 return 0;
240
241 /* We need to do this the hard way... */
242 - obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
242 + obj = deref_tag(the_repository, parse_object(the_repository, oid),
243 + NULL, 0);
244 if (obj && obj->type == OBJ_COMMIT)
245 return 1;
246 return 0;
@@ -263,7 +264,8 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
264 return 0;
265
266 /* We need to do this the hard way... */
266 - obj = deref_tag(parse_object(the_repository, oid), NULL, 0);
267 + obj = deref_tag(the_repository, parse_object(the_repository, oid),
268 + NULL, 0);
269 if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
270 return 1;
271 return 0;
@@ -968,7 +970,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
970 if (!o)
971 return -1;
972 if (!expected_type) {
971 - o = deref_tag(o, name, sp - name - 2);
973 + o = deref_tag(the_repository, o, name, sp - name - 2);
974 if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
975 return -1;
976 oidcpy(oid, &o->oid);
@@ -1100,7 +1102,8 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
1102 if (!object)
1103 return 0;
1104 if (object->type == OBJ_TAG) {
1103 - object = deref_tag(object, path, strlen(path));
1105 + object = deref_tag(the_repository, object, path,
1106 + strlen(path));
1107 if (!object)
1108 return 0;
1109 }
shallow.c
+3 -1
@@ -96,7 +96,9 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
96 if (i < heads->nr) {
97 int **depth_slot;
98 commit = (struct commit *)
99 - deref_tag(heads->objects[i++].item, NULL, 0);
99 + deref_tag(the_repository,
100 + heads->objects[i++].item,
101 + NULL, 0);
102 if (!commit || commit->object.type != OBJ_COMMIT) {
103 commit = NULL;
104 continue;
tag.c
+1 -1
@@ -64,7 +64,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
64 return ret;
65 }
66
67 -struct object *deref_tag(struct object *o, const char *warn, int warnlen)
67 +struct object *deref_tag_the_repository(struct object *o, const char *warn, int warnlen)
68 {
69 while (o && o->type == OBJ_TAG)
70 if (((struct tag *)o)->tagged)
tag.h
+2 -1
@@ -17,7 +17,8 @@ extern struct tag *lookup_tag_the_repository(const struct object_id *oid);
17 extern int parse_tag_buffer_the_repository(struct tag *item, const void *data, unsigned long size);
18 extern int parse_tag(struct tag *item);
19 extern void release_tag_memory(struct tag *t);
20 -extern struct object *deref_tag(struct object *, const char *, int);
20 +#define deref_tag(r, o, w, l) deref_tag_##r(o, w, l)
21 +extern struct object *deref_tag_the_repository(struct object *, const char *, int);
22 extern struct object *deref_tag_noverify(struct object *);
23 extern int gpg_verify_tag(const struct object_id *oid,
24 const char *name_to_report, unsigned flags);
upload-pack.c
+1 -1
@@ -380,7 +380,7 @@ static int ok_to_give_up(void)
380
381 if (want->flags & COMMON_KNOWN)
382 continue;
383 - want = deref_tag(want, "a want line", 0);
383 + want = deref_tag(the_repository, want, "a want line", 0);
384 if (!want || want->type != OBJ_COMMIT) {
385 /* no way to tell if this is reachable by
386 * looking at the ancestry chain alone, so