commit: add repository argument to lookup_commit

Add a repository argument to allow callers of lookup_commit to be more specific about which repository to handle. 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: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jun 28, 2018 at 18:21 UTC c1f5eb49620d4f287af28509621a364e3888cfe7
19 files changed +46 -33
builtin/am.c
+2 -1
@@ -1633,7 +1633,8 @@ static void do_commit(const struct am_state *state)
1633
1634 if (!get_oid_commit("HEAD", &parent)) {
1635 old_oid = &parent;
1636 - commit_list_insert(lookup_commit(&parent), &parents);
1636 + commit_list_insert(lookup_commit(the_repository, &parent),
1637 + &parents);
1638 } else {
1639 old_oid = NULL;
1640 say(state, stderr, _("applying to an empty history"));
builtin/commit-tree.c
+3 -1
@@ -6,6 +6,7 @@
6 #include "cache.h"
7 #include "config.h"
8 #include "object-store.h"
9 +#include "repository.h"
10 #include "commit.h"
11 #include "tree.h"
12 #include "builtin.h"
@@ -60,7 +61,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
61 if (get_oid_commit(argv[i], &oid))
62 die("Not a valid object name %s", argv[i]);
63 assert_oid_type(&oid, OBJ_COMMIT);
63 - new_parent(lookup_commit(&oid), &parents);
64 + new_parent(lookup_commit(the_repository, &oid),
65 + &parents);
66 continue;
67 }
68
builtin/diff-tree.c
+1 -1
@@ -25,7 +25,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p)
25
26 /* Graft the fake parents locally to the commit */
27 while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) {
28 - struct commit *parent = lookup_commit(&oid);
28 + struct commit *parent = lookup_commit(the_repository, &oid);
29 if (!pptr) {
30 /* Free the real parent list */
31 free_commit_list(commit->parents);
builtin/fast-export.c
+1 -1
@@ -963,7 +963,7 @@ static void import_marks(char *input_file)
963 /* only commits */
964 continue;
965
966 - commit = lookup_commit(&oid);
966 + commit = lookup_commit(the_repository, &oid);
967 if (!commit)
968 die("not a commit? can't happen: %s", oid_to_hex(&oid));
969
builtin/fmt-merge-msg.c
+1 -1
@@ -572,7 +572,7 @@ static void find_merge_parents(struct merge_parents *result,
572 commit_list_insert(parent, &parents);
573 add_merge_parent(result, &obj->oid, &parent->object.oid);
574 }
575 - head_commit = lookup_commit(head);
575 + head_commit = lookup_commit(the_repository, head);
576 if (head_commit)
577 commit_list_insert(head_commit, &parents);
578 reduce_heads_replace(&parents);
builtin/merge-base.c
+1 -1
@@ -124,7 +124,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs)
124 if (is_null_oid(oid))
125 return;
126
127 - commit = lookup_commit(oid);
127 + commit = lookup_commit(the_repository, oid);
128 if (!commit ||
129 (commit->object.flags & TMP_MARK) ||
130 parse_commit(commit))
builtin/verify-commit.c
+3 -1
@@ -9,6 +9,7 @@
9 #include "config.h"
10 #include "builtin.h"
11 #include "object-store.h"
12 +#include "repository.h"
13 #include "commit.h"
14 #include "run-command.h"
15 #include <signal.h>
@@ -27,7 +28,8 @@ static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned
28
29 memset(&signature_check, 0, sizeof(signature_check));
30
30 - ret = check_commit_signature(lookup_commit(oid), &signature_check);
31 + ret = check_commit_signature(lookup_commit(the_repository, oid),
32 + &signature_check);
33 print_signature_buffer(&signature_check, flags);
34
35 signature_check_clear(&signature_check);
commit-graph.c
+5 -5
@@ -242,7 +242,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
242 struct commit *c;
243 struct object_id oid;
244 hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
245 - c = lookup_commit(&oid);
245 + c = lookup_commit(the_repository, &oid);
246 if (!c)
247 die("could not find commit %s", oid_to_hex(&oid));
248 c->graph_pos = pos;
@@ -568,7 +568,7 @@ static void close_reachable(struct packed_oid_list *oids)
568 struct commit *commit;
569
570 for (i = 0; i < oids->nr; i++) {
571 - commit = lookup_commit(&oids->list[i]);
571 + commit = lookup_commit(the_repository, &oids->list[i]);
572 if (commit)
573 commit->object.flags |= UNINTERESTING;
574 }
@@ -579,14 +579,14 @@ static void close_reachable(struct packed_oid_list *oids)
579 * closure.
580 */
581 for (i = 0; i < oids->nr; i++) {
582 - commit = lookup_commit(&oids->list[i]);
582 + commit = lookup_commit(the_repository, &oids->list[i]);
583
584 if (commit && !parse_commit(commit))
585 add_missing_parents(oids, commit);
586 }
587
588 for (i = 0; i < oids->nr; i++) {
589 - commit = lookup_commit(&oids->list[i]);
589 + commit = lookup_commit(the_repository, &oids->list[i]);
590
591 if (commit)
592 commit->object.flags &= ~UNINTERESTING;
@@ -737,7 +737,7 @@ void write_commit_graph(const char *obj_dir,
737 if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))
738 continue;
739
740 - commits.list[commits.nr] = lookup_commit(&oids.list[i]);
740 + commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]);
741 parse_commit(commits.list[commits.nr]);
742
743 for (parent = commits.list[commits.nr]->parents;
commit.c
+4 -3
@@ -52,7 +52,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
52 return c;
53 }
54
55 -struct commit *lookup_commit(const struct object_id *oid)
55 +struct commit *lookup_commit_the_repository(const struct object_id *oid)
56 {
57 struct object *obj = lookup_object(the_repository, oid->hash);
58 if (!obj)
@@ -402,7 +402,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
402 */
403 if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
404 continue;
405 - new_parent = lookup_commit(&parent);
405 + new_parent = lookup_commit(the_repository, &parent);
406 if (new_parent)
407 pptr = &commit_list_insert(new_parent, pptr)->next;
408 }
@@ -410,7 +410,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
410 int i;
411 struct commit *new_parent;
412 for (i = 0; i < graft->nr_parent; i++) {
413 - new_parent = lookup_commit(&graft->parent[i]);
413 + new_parent = lookup_commit(the_repository,
414 + &graft->parent[i]);
415 if (!new_parent)
416 continue;
417 pptr = &commit_list_insert(new_parent, pptr)->next;
commit.h
+2 -1
@@ -63,7 +63,8 @@ enum decoration_type {
63 void add_name_decoration(enum decoration_type type, const char *name, struct object *obj);
64 const struct name_decoration *get_name_decoration(const struct object *obj);
65
66 -struct commit *lookup_commit(const struct object_id *oid);
66 +#define lookup_commit(r, o) lookup_commit_##r(o)
67 +struct commit *lookup_commit_the_repository(const struct object_id *oid);
68 #define lookup_commit_reference(r, o) \
69 lookup_commit_reference_##r(o)
70 struct commit *lookup_commit_reference_the_repository(const struct object_id *oid);
fetch-pack.c
+3 -2
@@ -498,7 +498,8 @@ static int find_common(struct fetch_pack_args *args,
498 case ACK_ready:
499 case ACK_continue: {
500 struct commit *commit =
501 - lookup_commit(result_oid);
501 + lookup_commit(the_repository,
502 + result_oid);
503 if (!commit)
504 die(_("invalid commit %s"), oid_to_hex(result_oid));
505 if (args->stateless_rpc
@@ -1278,7 +1279,7 @@ static int process_acks(struct packet_reader *reader, struct oidset *common)
1279 if (!get_oid_hex(arg, &oid)) {
1280 struct commit *commit;
1281 oidset_insert(common, &oid);
1281 - commit = lookup_commit(&oid);
1282 + commit = lookup_commit(the_repository, &oid);
1283 mark_common(commit, 0, 1);
1284 }
1285 continue;
log-tree.c
+1 -1
@@ -134,7 +134,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
134
135 static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
136 {
137 - struct commit *commit = lookup_commit(&graft->oid);
137 + struct commit *commit = lookup_commit(the_repository, &graft->oid);
138 if (!commit)
139 return 0;
140 add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
notes-utils.c
+3 -1
@@ -3,6 +3,7 @@
3 #include "commit.h"
4 #include "refs.h"
5 #include "notes-utils.h"
6 +#include "repository.h"
7
8 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
9 const char *msg, size_t msg_len,
@@ -19,7 +20,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
20 /* Deduce parent commit from t->ref */
21 struct object_id parent_oid;
22 if (!read_ref(t->ref, &parent_oid)) {
22 - struct commit *parent = lookup_commit(&parent_oid);
23 + struct commit *parent = lookup_commit(the_repository,
24 + &parent_oid);
25 if (parse_commit(parent))
26 die("Failed to find/parse commit %s", t->ref);
27 commit_list_insert(parent, &parents);
object.c
+1 -1
@@ -212,7 +212,7 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
212 }
213 }
214 } else if (type == OBJ_COMMIT) {
215 - struct commit *commit = lookup_commit(oid);
215 + struct commit *commit = lookup_commit(the_repository, oid);
216 if (commit) {
217 if (parse_commit_buffer(commit, buffer, size, 1))
218 return NULL;
sequencer.c
+2 -2
@@ -594,7 +594,7 @@ static int is_index_unchanged(void)
594 if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
595 return error(_("could not resolve HEAD commit"));
596
597 - head_commit = lookup_commit(&head_oid);
597 + head_commit = lookup_commit(the_repository, &head_oid);
598
599 /*
600 * If head_commit is NULL, check_commit, called from
@@ -1101,7 +1101,7 @@ void print_commit_summary(const char *prefix, const struct object_id *oid,
1101 struct strbuf author_ident = STRBUF_INIT;
1102 struct strbuf committer_ident = STRBUF_INIT;
1103
1104 - commit = lookup_commit(oid);
1104 + commit = lookup_commit(the_repository, oid);
1105 if (!commit)
1106 die(_("couldn't look up newly created commit"));
1107 if (parse_commit(commit))
sha1-name.c
+1 -1
@@ -351,7 +351,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
351
352 type = oid_object_info(the_repository, oid, NULL);
353 if (type == OBJ_COMMIT) {
354 - struct commit *commit = lookup_commit(oid);
354 + struct commit *commit = lookup_commit(the_repository, oid);
355 if (commit) {
356 struct pretty_print_context pp = {0};
357 pp.date_mode.type = DATE_SHORT;
shallow.c
+10 -7
@@ -31,7 +31,7 @@ int register_shallow(struct repository *r, const struct object_id *oid)
31 {
32 struct commit_graft *graft =
33 xmalloc(sizeof(struct commit_graft));
34 - struct commit *commit = lookup_commit(oid);
34 + struct commit *commit = lookup_commit(the_repository, oid);
35
36 oidcpy(&graft->oid, oid);
37 graft->nr_parent = -1;
@@ -259,7 +259,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
259 if (graft->nr_parent != -1)
260 return 0;
261 if (data->flags & SEEN_ONLY) {
262 - struct commit *c = lookup_commit(&graft->oid);
262 + struct commit *c = lookup_commit(the_repository, &graft->oid);
263 if (!c || !(c->object.flags & SEEN)) {
264 if (data->flags & VERBOSE)
265 printf("Removing %s from .git/shallow\n",
@@ -624,7 +624,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
624
625 /* Mark potential bottoms so we won't go out of bound */
626 for (i = 0; i < nr_shallow; i++) {
627 - struct commit *c = lookup_commit(&oid[shallow[i]]);
627 + struct commit *c = lookup_commit(the_repository,
628 + &oid[shallow[i]]);
629 c->object.flags |= BOTTOM;
630 }
631
@@ -635,7 +636,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
636 int bitmap_size = DIV_ROUND_UP(pi.nr_bits, 32) * sizeof(uint32_t);
637 memset(used, 0, sizeof(*used) * info->shallow->nr);
638 for (i = 0; i < nr_shallow; i++) {
638 - const struct commit *c = lookup_commit(&oid[shallow[i]]);
639 + const struct commit *c = lookup_commit(the_repository,
640 + &oid[shallow[i]]);
641 uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
642 if (*map)
643 used[shallow[i]] = xmemdupz(*map, bitmap_size);
@@ -705,7 +707,7 @@ static void post_assign_shallow(struct shallow_info *info,
707 for (i = dst = 0; i < info->nr_theirs; i++) {
708 if (i != dst)
709 info->theirs[dst] = info->theirs[i];
708 - c = lookup_commit(&oid[info->theirs[i]]);
710 + c = lookup_commit(the_repository, &oid[info->theirs[i]]);
711 bitmap = ref_bitmap_at(ref_bitmap, c);
712 if (!*bitmap)
713 continue;
@@ -726,7 +728,7 @@ static void post_assign_shallow(struct shallow_info *info,
728 for (i = dst = 0; i < info->nr_ours; i++) {
729 if (i != dst)
730 info->ours[dst] = info->ours[i];
729 - c = lookup_commit(&oid[info->ours[i]]);
731 + c = lookup_commit(the_repository, &oid[info->ours[i]]);
732 bitmap = ref_bitmap_at(ref_bitmap, c);
733 if (!*bitmap)
734 continue;
@@ -748,7 +750,8 @@ static void post_assign_shallow(struct shallow_info *info,
750 int delayed_reachability_test(struct shallow_info *si, int c)
751 {
752 if (si->need_reachability_test[c]) {
751 - struct commit *commit = lookup_commit(&si->shallow->oid[c]);
753 + struct commit *commit = lookup_commit(the_repository,
754 + &si->shallow->oid[c]);
755
756 if (!si->commits) {
757 struct commit_array ca;
tag.c
+1 -1
@@ -158,7 +158,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
158 } else if (!strcmp(type, tree_type)) {
159 item->tagged = (struct object *)lookup_tree(the_repository, &oid);
160 } else if (!strcmp(type, commit_type)) {
161 - item->tagged = (struct object *)lookup_commit(&oid);
161 + item->tagged = (struct object *)lookup_commit(the_repository, &oid);
162 } else if (!strcmp(type, tag_type)) {
163 item->tagged = (struct object *)lookup_tag(&oid);
164 } else {
tree.c
+1 -1
@@ -101,7 +101,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
101 else if (S_ISGITLINK(entry.mode)) {
102 struct commit *commit;
103
104 - commit = lookup_commit(entry.oid);
104 + commit = lookup_commit(the_repository, entry.oid);
105 if (!commit)
106 die("Commit %s in submodule path %s%s not found",
107 oid_to_hex(entry.oid),