object.c: allow parse_object to handle arbitrary repositories
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
8e4b0b6047e3cfbe627de6694c2eeae6904b41a1
2 files changed
+8
-9
object.c
+7
-7
@@ -245,28 +245,28 @@ struct object *parse_object_or_die(const struct object_id *oid,
245
die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
246
}
247
248
-struct object *parse_object_the_repository(const struct object_id *oid)
248
+struct object *parse_object(struct repository *r, const struct object_id *oid)
249
{
250
unsigned long size;
251
enum object_type type;
252
int eaten;
253
- const struct object_id *repl = lookup_replace_object(the_repository, oid);
253
+ const struct object_id *repl = lookup_replace_object(r, oid);
254
void *buffer;
255
struct object *obj;
256
257
- obj = lookup_object(the_repository, oid->hash);
257
+ obj = lookup_object(r, oid->hash);
258
if (obj && obj->parsed)
259
return obj;
260
261
if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
262
(!obj && has_object_file(oid) &&
263
- oid_object_info(the_repository, oid, NULL) == OBJ_BLOB)) {
263
+ oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
264
if (check_object_signature(repl, NULL, 0, NULL) < 0) {
265
error("sha1 mismatch %s", oid_to_hex(oid));
266
return NULL;
267
}
268
- parse_blob_buffer(lookup_blob(the_repository, oid), NULL, 0);
269
- return lookup_object(the_repository, oid->hash);
268
+ parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
269
+ return lookup_object(r, oid->hash);
270
}
271
272
buffer = read_object_file(oid, &type, &size);
@@ -277,7 +277,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
277
return NULL;
278
}
279
280
- obj = parse_object_buffer(the_repository, oid, type, size,
280
+ obj = parse_object_buffer(r, oid, type, size,
281
buffer, &eaten);
282
if (!eaten)
283
free(buffer);
object.h
+1
-2
@@ -124,8 +124,7 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
124
*
125
* Returns NULL if the object is missing or corrupt.
126
*/
127
-#define parse_object(r, oid) parse_object_##r(oid)
128
-struct object *parse_object_the_repository(const struct object_id *oid);
127
+struct object *parse_object(struct repository *r, const struct object_id *oid);
128
129
/*
130
* Like parse_object, but will die() instead of returning NULL. If the