object: allow lookup_object to handle arbitrary repositories
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
94c09a7197cde15587318dbb60cdc591d443f45c
2 files changed
+8
-10
object.c
+7
-8
@@ -84,21 +84,20 @@ 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_the_repository(const unsigned char *sha1)
87
+struct object *lookup_object(struct repository *r, const unsigned char *sha1)
88
{
89
unsigned int i, first;
90
struct object *obj;
91
92
- if (!the_repository->parsed_objects->obj_hash)
92
+ if (!r->parsed_objects->obj_hash)
93
return NULL;
94
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) {
97
if (!hashcmp(sha1, obj->oid.hash))
98
break;
99
i++;
101
- if (i == the_repository->parsed_objects->obj_hash_size)
100
+ if (i == r->parsed_objects->obj_hash_size)
101
i = 0;
102
}
103
if (obj && i != first) {
@@ -107,8 +106,8 @@ struct object *lookup_object_the_repository(const unsigned char *sha1)
106
* that we do not need to walk the hash table the next
107
* time we look for it.
108
*/
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]);
111
}
112
return obj;
113
}
object.h
+1
-2
@@ -109,8 +109,7 @@ 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
-#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);
113
114
extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
115