Skip to content

Commit 94c09a7

Browse files
stefanbellergitster
authored andcommitted
object: allow lookup_object to handle arbitrary repositories
Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a962da1 commit 94c09a7

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

object.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,20 @@ 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_the_repository(const unsigned char *sha1)
87+
struct object *lookup_object(struct repository *r, const unsigned char *sha1)
8888
{
8989
unsigned int i, first;
9090
struct object *obj;
9191

92-
if (!the_repository->parsed_objects->obj_hash)
92+
if (!r->parsed_objects->obj_hash)
9393
return NULL;
9494

95-
first = i = hash_obj(sha1,
96-
the_repository->parsed_objects->obj_hash_size);
97-
while ((obj = the_repository->parsed_objects->obj_hash[i]) != NULL) {
95+
first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
96+
while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
9897
if (!hashcmp(sha1, obj->oid.hash))
9998
break;
10099
i++;
101-
if (i == the_repository->parsed_objects->obj_hash_size)
100+
if (i == r->parsed_objects->obj_hash_size)
102101
i = 0;
103102
}
104103
if (obj && i != first) {
@@ -107,8 +106,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)
107106
* that we do not need to walk the hash table the next
108107
* time we look for it.
109108
*/
110-
SWAP(the_repository->parsed_objects->obj_hash[i],
111-
the_repository->parsed_objects->obj_hash[first]);
109+
SWAP(r->parsed_objects->obj_hash[i],
110+
r->parsed_objects->obj_hash[first]);
112111
}
113112
return obj;
114113
}

object.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ extern struct object *get_indexed_object(unsigned int);
109109
* half-initialised objects, the caller is expected to initialize them
110110
* by calling parse_object() on them.
111111
*/
112-
#define lookup_object(r, s) lookup_object_##r(s)
113-
struct object *lookup_object_the_repository(const unsigned char *sha1);
112+
struct object *lookup_object(struct repository *r, const unsigned char *sha1);
114113

115114
extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
116115

0 commit comments

Comments
 (0)