Skip to content

Commit 5abddd1

Browse files
stefanbellergitster
authored andcommitted
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>
1 parent 109cd76 commit 5abddd1

File tree

15 files changed

+31
-26
lines changed

15 files changed

+31
-26
lines changed

blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const char *blob_type = "blob";
77

88
struct blob *lookup_blob(const struct object_id *oid)
99
{
10-
struct object *obj = lookup_object(oid->hash);
10+
struct object *obj = lookup_object(the_repository, oid->hash);
1111
if (!obj)
1212
return create_object(the_repository, oid->hash,
1313
alloc_blob_node(the_repository));

builtin/fast-export.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void export_blob(const struct object_id *oid)
230230
if (is_null_oid(oid))
231231
return;
232232

233-
object = lookup_object(oid->hash);
233+
object = lookup_object(the_repository, oid->hash);
234234
if (object && object->flags & SHOWN)
235235
return;
236236

@@ -402,7 +402,8 @@ static void show_filemodify(struct diff_queue_struct *q,
402402
anonymize_sha1(&spec->oid) :
403403
spec->oid.hash));
404404
else {
405-
struct object *object = lookup_object(spec->oid.hash);
405+
struct object *object = lookup_object(the_repository,
406+
spec->oid.hash);
406407
printf("M %06o :%d ", spec->mode,
407408
get_object_mark(object));
408409
}

builtin/fsck.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
410410
struct object *obj;
411411

412412
if (!is_null_oid(oid)) {
413-
obj = lookup_object(oid->hash);
413+
obj = lookup_object(the_repository, oid->hash);
414414
if (obj && (obj->flags & HAS_OBJ)) {
415415
if (timestamp && name_objects)
416416
add_decoration(fsck_walk_options.object_names,
@@ -763,7 +763,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
763763
const char *arg = argv[i];
764764
struct object_id oid;
765765
if (!get_oid(arg, &oid)) {
766-
struct object *obj = lookup_object(oid.hash);
766+
struct object *obj = lookup_object(the_repository,
767+
oid.hash);
767768

768769
if (!obj || !(obj->flags & HAS_OBJ)) {
769770
if (is_promisor_object(&oid))

builtin/name-rev.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ static void name_rev_line(char *p, struct name_ref_data *data)
379379
*(p+1) = 0;
380380
if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) {
381381
struct object *o =
382-
lookup_object(oid.hash);
382+
lookup_object(the_repository,
383+
oid.hash);
383384
if (o)
384385
name = get_rev_name(o, &buf);
385386
}

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
4040
* Do we know about this object?
4141
* It must have been reachable
4242
*/
43-
if (lookup_object(oid->hash))
43+
if (lookup_object(the_repository, oid->hash))
4444
return 0;
4545

4646
if (lstat(fullpath, &st)) {

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
331331
{
332332
struct object *obj;
333333
struct obj_buffer *obj_buffer;
334-
obj = lookup_object(base->hash);
334+
obj = lookup_object(the_repository, base->hash);
335335
if (!obj)
336336
return 0;
337337
obj_buffer = lookup_object_buffer(obj);

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref
5454

5555
struct commit *lookup_commit(const struct object_id *oid)
5656
{
57-
struct object *obj = lookup_object(oid->hash);
57+
struct object *obj = lookup_object(the_repository, oid->hash);
5858
if (!obj)
5959
return create_object(the_repository, oid->hash,
6060
alloc_commit_node(the_repository));

fetch-pack.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int find_common(struct fetch_pack_args *args,
362362
* interested in the case we *know* the object is
363363
* reachable and we have already scanned it.
364364
*/
365-
if (((o = lookup_object(remote->hash)) != NULL) &&
365+
if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
366366
(o->flags & COMPLETE)) {
367367
continue;
368368
}
@@ -436,7 +436,7 @@ static int find_common(struct fetch_pack_args *args,
436436
if (skip_prefix(line, "unshallow ", &arg)) {
437437
if (get_oid_hex(arg, &oid))
438438
die(_("invalid unshallow line: %s"), line);
439-
if (!lookup_object(oid.hash))
439+
if (!lookup_object(the_repository, oid.hash))
440440
die(_("object not found: %s"), line);
441441
/* make sure that it is parsed as shallow */
442442
if (!parse_object(the_repository, &oid))
@@ -801,7 +801,8 @@ static int everything_local(struct fetch_pack_args *args,
801801
* Don't mark them common yet; the server has to be told so first.
802802
*/
803803
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),
805806
NULL, 0);
806807

807808
if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
@@ -821,7 +822,7 @@ static int everything_local(struct fetch_pack_args *args,
821822
const struct object_id *remote = &ref->old_oid;
822823
struct object *o;
823824

824-
o = lookup_object(remote->hash);
825+
o = lookup_object(the_repository, remote->hash);
825826
if (!o || !(o->flags & COMPLETE)) {
826827
retval = 0;
827828
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)
11201121
* interested in the case we *know* the object is
11211122
* reachable and we have already scanned it.
11221123
*/
1123-
if (((o = lookup_object(remote->hash)) != NULL) &&
1124+
if (((o = lookup_object(the_repository, remote->hash)) != NULL) &&
11241125
(o->flags & COMPLETE)) {
11251126
continue;
11261127
}
@@ -1317,7 +1318,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
13171318
if (skip_prefix(reader->line, "unshallow ", &arg)) {
13181319
if (get_oid_hex(arg, &oid))
13191320
die(_("invalid unshallow line: %s"), reader->line);
1320-
if (!lookup_object(oid.hash))
1321+
if (!lookup_object(the_repository, oid.hash))
13211322
die(_("object not found: %s"), reader->line);
13221323
/* make sure that it is parsed as shallow */
13231324
if (!parse_object(the_repository, &oid))

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static void one_remote_object(const struct object_id *oid)
722722
{
723723
struct object *obj;
724724

725-
obj = lookup_object(oid->hash);
725+
obj = lookup_object(the_repository, oid->hash);
726726
if (!obj)
727727
obj = parse_object(the_repository, oid);
728728

object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i
8484
* Look up the record for the given sha1 in the hash map stored in
8585
* obj_hash. Return NULL if it was not found.
8686
*/
87-
struct object *lookup_object(const unsigned char *sha1)
87+
struct object *lookup_object_the_repository(const unsigned char *sha1)
8888
{
8989
unsigned int i, first;
9090
struct object *obj;
@@ -179,7 +179,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
179179

180180
struct object *lookup_unknown_object(const unsigned char *sha1)
181181
{
182-
struct object *obj = lookup_object(sha1);
182+
struct object *obj = lookup_object(the_repository, sha1);
183183
if (!obj)
184184
obj = create_object(the_repository, sha1,
185185
alloc_object_node(the_repository));
@@ -255,7 +255,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
255255
void *buffer;
256256
struct object *obj;
257257

258-
obj = lookup_object(oid->hash);
258+
obj = lookup_object(the_repository, oid->hash);
259259
if (obj && obj->parsed)
260260
return obj;
261261

@@ -267,7 +267,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
267267
return NULL;
268268
}
269269
parse_blob_buffer(lookup_blob(oid), NULL, 0);
270-
return lookup_object(oid->hash);
270+
return lookup_object(the_repository, oid->hash);
271271
}
272272

273273
buffer = read_object_file(oid, &type, &size);

0 commit comments

Comments
 (0)