object.c: allow parse_object_buffer 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 108ed1a3d88b04bb7a6d0b0a0e7c642a28a7845a
2 files changed +10 -11
object.c
+9 -9
@@ -185,21 +185,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
185 return obj;
186 }
187
188 -struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
188 +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
189 {
190 struct object *obj;
191 *eaten_p = 0;
192
193 obj = NULL;
194 if (type == OBJ_BLOB) {
195 - struct blob *blob = lookup_blob(the_repository, oid);
195 + struct blob *blob = lookup_blob(r, oid);
196 if (blob) {
197 if (parse_blob_buffer(blob, buffer, size))
198 return NULL;
199 obj = &blob->object;
200 }
201 } else if (type == OBJ_TREE) {
202 - struct tree *tree = lookup_tree(the_repository, oid);
202 + struct tree *tree = lookup_tree(r, oid);
203 if (tree) {
204 obj = &tree->object;
205 if (!tree->buffer)
@@ -211,20 +211,20 @@ struct object *parse_object_buffer_the_repository(const struct object_id *oid, e
211 }
212 }
213 } else if (type == OBJ_COMMIT) {
214 - struct commit *commit = lookup_commit(the_repository, oid);
214 + struct commit *commit = lookup_commit(r, oid);
215 if (commit) {
216 - if (parse_commit_buffer(the_repository, commit, buffer, size, 1))
216 + if (parse_commit_buffer(r, commit, buffer, size, 1))
217 return NULL;
218 - if (!get_cached_commit_buffer(the_repository, commit, NULL)) {
219 - set_commit_buffer(the_repository, commit, buffer, size);
218 + if (!get_cached_commit_buffer(r, commit, NULL)) {
219 + set_commit_buffer(r, commit, buffer, size);
220 *eaten_p = 1;
221 }
222 obj = &commit->object;
223 }
224 } else if (type == OBJ_TAG) {
225 - struct tag *tag = lookup_tag(the_repository, oid);
225 + struct tag *tag = lookup_tag(r, oid);
226 if (tag) {
227 - if (parse_tag_buffer(the_repository, tag, buffer, size))
227 + if (parse_tag_buffer(r, tag, buffer, size))
228 return NULL;
229 obj = &tag->object;
230 }
object.h
+1 -2
@@ -138,8 +138,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name
138 * parsing it. eaten_p indicates if the object has a borrowed copy
139 * of buffer and the caller should not free() it.
140 */
141 -#define parse_object_buffer(r, o, t, s, b, e) parse_object_buffer_##r(o, t, s, b, e)
142 -struct object *parse_object_buffer_the_repository(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
141 +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
142
143 /** Returns the object, with potentially excess memory allocated. **/
144 struct object *lookup_unknown_object(const unsigned char *sha1);