object: add repository argument to lookup_object

Add a repository argument to allow callers of lookup_object 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 5abddd1eb72ca47cc84a9fc888c30ebaadde2eec
15 files changed +31 -26
blob.c
+1 -1
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
7
8 struct blob *lookup_blob(const struct object_id *oid)
9 {
10 - struct object *obj = lookup_object(oid->hash);
10 + struct object *obj = lookup_object(the_repository, oid->hash);
11 if (!obj)
12 return create_object(the_repository, oid->hash,
13 alloc_blob_node(the_repository));
builtin/fast-export.c
+3 -2
@@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid)
230 if (is_null_oid(oid))
231 return;
232
233 - object = lookup_object(oid->hash);
233 + object = lookup_object(the_repository, oid->hash);
234 if (object && object->flags & SHOWN)
235 return;
236
@@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q,
402 anonymize_sha1(&spec->oid) :
403 spec->oid.hash));
404 else {
405 - struct object *object = lookup_object(spec->oid.hash);
405 + struct object *object = lookup_object(the_repository,
406 + spec->oid.hash);
407 printf("M %06o :%d ", spec->mode,
408 get_object_mark(object));
409 }
builtin/fsck.c
+3 -2
@@ -410,7 +410,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
410 struct object *obj;
411
412 if (!is_null_oid(oid)) {
413 - obj = lookup_object(oid->hash);
413 + obj = lookup_object(the_repository, oid->hash);
414 if (obj && (obj->flags & HAS_OBJ)) {
415 if (timestamp && name_objects)
416 add_decoration(fsck_walk_options.object_names,
@@ -763,7 +763,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
763 const char *arg = argv[i];
764 struct object_id oid;
765 if (!get_oid(arg, &oid)) {
766 - struct object *obj = lookup_object(oid.hash);
766 + struct object *obj = lookup_object(the_repository,
767 + oid.hash);
768
769 if (!obj || !(obj->flags & HAS_OBJ)) {
770 if (is_promisor_object(&oid))
builtin/name-rev.c
+2 -1
@@ -379,7 +379,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
379 *(p+1) = 0;
380 if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
381 struct object *o =
382 - lookup_object(oid.hash);
382 + lookup_object(the_repository,
383 + oid.hash);
384 if (o)
385 name = get_rev_name(o, &buf);
386 }
builtin/prune.c
+1 -1
@@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
40 * Do we know about this object?
41 * It must have been reachable
42 */
43 - if (lookup_object(oid->hash))
43 + if (lookup_object(the_repository, oid->hash))
44 return 0;
45
46 if (lstat(fullpath, &st)) {
builtin/unpack-objects.c
+1 -1
@@ -331,7 +331,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
331 {
332 struct object *obj;
333 struct obj_buffer *obj_buffer;
334 - obj = lookup_object(base->hash);
334 + obj = lookup_object(the_repository, base->hash);
335 if (!obj)
336 return 0;
337 obj_buffer = lookup_object_buffer(obj);
commit.c
+1 -1
@@ -54,7 +54,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
54
55 struct commit *lookup_commit(const struct object_id *oid)
56 {
57 - struct object *obj = lookup_object(oid->hash);
57 + struct object *obj = lookup_object(the_repository, oid->hash);
58 if (!obj)
59 return create_object(the_repository, oid->hash,
60 alloc_commit_node(the_repository));
fetch-pack.c
+7 -6
@@ -362,7 +362,7 @@ static int find_common(struct fetch_pack_args *args,
362 * interested in the case we *know* the object is
363 * reachable and we have already scanned it.
364 */
365 - if (((o = lookup_object(remote->hash)) != NULL) &&
365 + if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
366 (o->flags & COMPLETE)) {
367 continue;
368 }
@@ -436,7 +436,7 @@ static int find_common(struct fetch_pack_args *args,
436 if (skip_prefix(line, "unshallow ", &arg)) {
437 if (get_oid_hex(arg, &oid))
438 die(_("invalid unshallow line: %s"), line);
439 - if (!lookup_object(oid.hash))
439 + if (!lookup_object(the_repository, oid.hash))
440 die(_("object not found: %s"), line);
441 /* make sure that it is parsed as shallow */
442 if (!parse_object(the_repository, &oid))
@@ -801,7 +801,8 @@ static int everything_local(struct fetch_pack_args *args,
801 * Don't mark them common yet; the server has to be told so first.
802 */
803 for (ref = *refs; ref; ref = ref->next) {
804 - struct object *o = deref_tag(lookup_object(ref->old_oid.hash),
804 + struct object *o = deref_tag(lookup_object(the_repository,
805 + ref->old_oid.hash),
806 NULL, 0);
807
808 if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -821,7 +822,7 @@ static int everything_local(struct fetch_pack_args *args,
822 const struct object_id *remote = &ref->old_oid;
823 struct object *o;
824
824 - o = lookup_object(remote->hash);
825 + o = lookup_object(the_repository, remote->hash);
826 if (!o || !(o->flags & COMPLETE)) {
827 retval = 0;
828 print_verbose(args, "want %s (%s)", oid_to_hex(remote),
@@ -1120,7 +1121,7 @@ static void add_wants(const struct ref *wants, struct strbuf *req_buf)
1121 * interested in the case we *know* the object is
1122 * reachable and we have already scanned it.
1123 */
1123 - if (((o = lookup_object(remote->hash)) != NULL) &&
1124 + if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
1125 (o->flags & COMPLETE)) {
1126 continue;
1127 }
@@ -1317,7 +1318,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
1318 if (skip_prefix(reader->line, "unshallow ", &arg)) {
1319 if (get_oid_hex(arg, &oid))
1320 die(_("invalid unshallow line: %s"), reader->line);
1320 - if (!lookup_object(oid.hash))
1321 + if (!lookup_object(the_repository, oid.hash))
1322 die(_("object not found: %s"), reader->line);
1323 /* make sure that it is parsed as shallow */
1324 if (!parse_object(the_repository, &oid))
http-push.c
+1 -1
@@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid)
722 {
723 struct object *obj;
724
725 - obj = lookup_object(oid->hash);
725 + obj = lookup_object(the_repository, oid->hash);
726 if (!obj)
727 obj = parse_object(the_repository, oid);
728
object.c
+4 -4
@@ -84,7 +84,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
84 * Look up the record for the given sha1 in the hash map stored in
85 * obj_hash. Return NULL if it was not found.
86 */
87 -struct object *lookup_object(const unsigned char *sha1)
87 +struct object *lookup_object_the_repository(const unsigned char *sha1)
88 {
89 unsigned int i, first;
90 struct object *obj;
@@ -179,7 +179,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
179
180 struct object *lookup_unknown_object(const unsigned char *sha1)
181 {
182 - struct object *obj = lookup_object(sha1);
182 + struct object *obj = lookup_object(the_repository, sha1);
183 if (!obj)
184 obj = create_object(the_repository, sha1,
185 alloc_object_node(the_repository));
@@ -255,7 +255,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
255 void *buffer;
256 struct object *obj;
257
258 - obj = lookup_object(oid->hash);
258 + obj = lookup_object(the_repository, oid->hash);
259 if (obj && obj->parsed)
260 return obj;
261
@@ -267,7 +267,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
267 return NULL;
268 }
269 parse_blob_buffer(lookup_blob(oid), NULL, 0);
270 - return lookup_object(oid->hash);
270 + return lookup_object(the_repository, oid->hash);
271 }
272
273 buffer = read_object_file(oid, &type, &size);
object.h
+2 -1
@@ -109,7 +109,8 @@ extern struct object *get_indexed_object(unsigned int);
109 * half-initialised objects, the caller is expected to initialize them
110 * by calling parse_object() on them.
111 */
112 -struct object *lookup_object(const unsigned char *sha1);
112 +#define lookup_object(r, s) lookup_object_##r(s)
113 +struct object *lookup_object_the_repository(const unsigned char *sha1);
114
115 extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
116
reachable.c
+2 -2
@@ -108,7 +108,7 @@ static int add_recent_loose(const struct object_id *oid,
108 const char *path, void *data)
109 {
110 struct stat st;
111 - struct object *obj = lookup_object(oid->hash);
111 + struct object *obj = lookup_object(the_repository, oid->hash);
112
113 if (obj && obj->flags & SEEN)
114 return 0;
@@ -133,7 +133,7 @@ static int add_recent_packed(const struct object_id *oid,
133 struct packed_git *p, uint32_t pos,
134 void *data)
135 {
136 - struct object *obj = lookup_object(oid->hash);
136 + struct object *obj = lookup_object(the_repository, oid->hash);
137
138 if (obj && obj->flags & SEEN)
139 return 0;
tag.c
+1 -1
@@ -94,7 +94,7 @@ struct object *deref_tag_noverify(struct object *o)
94
95 struct tag *lookup_tag(const struct object_id *oid)
96 {
97 - struct object *obj = lookup_object(oid->hash);
97 + struct object *obj = lookup_object(the_repository, oid->hash);
98 if (!obj)
99 return create_object(the_repository, oid->hash,
100 alloc_tag_node(the_repository));
tree.c
+1 -1
@@ -197,7 +197,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
197
198 struct tree *lookup_tree(const struct object_id *oid)
199 {
200 - struct object *obj = lookup_object(oid->hash);
200 + struct object *obj = lookup_object(the_repository, oid->hash);
201 if (!obj)
202 return create_object(the_repository, oid->hash,
203 alloc_tree_node(the_repository));
upload-pack.c
+1 -1
@@ -570,7 +570,7 @@ static int get_reachable_list(struct object_array *src,
570 if (parse_oid_hex(namebuf, &sha1, &p) || *p != '\n')
571 break;
572
573 - o = lookup_object(sha1.hash);
573 + o = lookup_object(the_repository, sha1.hash);
574 if (o && o->type == OBJ_COMMIT) {
575 o->flags &= ~TMP_MARK;
576 }