180
return obj;
181
}
182
183
-struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
183
+struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
184
{
185
- struct object_id oid;
185
struct object *obj;
186
*eaten_p = 0;
187
189
- hashcpy(oid.hash, sha1);
190
-
188
obj = NULL;
189
if (type == OBJ_BLOB) {
193
- struct blob *blob = lookup_blob(&oid);
190
+ struct blob *blob = lookup_blob(oid);
191
if (blob) {
192
if (parse_blob_buffer(blob, buffer, size))
193
return NULL;
194
obj = &blob->object;
195
}
196
} else if (type == OBJ_TREE) {
200
- struct tree *tree = lookup_tree(&oid);
197
+ struct tree *tree = lookup_tree(oid);
198
if (tree) {
199
obj = &tree->object;
200
if (!tree->buffer)
206
}
207
}
208
} else if (type == OBJ_COMMIT) {
212
- struct commit *commit = lookup_commit(&oid);
209
+ struct commit *commit = lookup_commit(oid);
210
if (commit) {
211
if (parse_commit_buffer(commit, buffer, size))
212
return NULL;
217
obj = &commit->object;
218
}
219
} else if (type == OBJ_TAG) {
223
- struct tag *tag = lookup_tag(&oid);
220
+ struct tag *tag = lookup_tag(oid);
221
if (tag) {
222
if (parse_tag_buffer(tag, buffer, size))
223
return NULL;
224
obj = &tag->object;
225
}
226
} else {
230
- warning("object %s has unknown type id %d", sha1_to_hex(sha1), type);
227
+ warning("object %s has unknown type id %d", oid_to_hex(oid), type);
228
obj = NULL;
229
}
230
return obj;
231
}
232
236
-struct object *parse_object_or_die(const unsigned char *sha1,
233
+struct object *parse_object_or_die(const struct object_id *oid,
234
const char *name)
235
{
239
- struct object *o = parse_object(sha1);
236
+ struct object *o = parse_object(oid);
237
if (o)
238
return o;
239
243
- die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1));
240
+ die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
241
}
242
246
-struct object *parse_object(const unsigned char *sha1)
243
+struct object *parse_object(const struct object_id *oid)
244
{
245
unsigned long size;
246
enum object_type type;
247
int eaten;
251
- const unsigned char *repl = lookup_replace_object(sha1);
248
+ const unsigned char *repl = lookup_replace_object(oid->hash);
249
void *buffer;
250
struct object *obj;
254
- struct object_id oid;
255
-
256
- hashcpy(oid.hash, sha1);
251
258
- obj = lookup_object(oid.hash);
252
+ obj = lookup_object(oid->hash);
253
if (obj && obj->parsed)
254
return obj;
255
256
if ((obj && obj->type == OBJ_BLOB) ||
263
- (!obj && has_sha1_file(sha1) &&
264
- sha1_object_info(sha1, NULL) == OBJ_BLOB)) {
257
+ (!obj && has_object_file(oid) &&
258
+ sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
259
if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
266
- error("sha1 mismatch %s", sha1_to_hex(repl));
260
+ error("sha1 mismatch %s", oid_to_hex(oid));
261
return NULL;
262
}
269
- parse_blob_buffer(lookup_blob(&oid), NULL, 0);
270
- return lookup_object(sha1);
263
+ parse_blob_buffer(lookup_blob(oid), NULL, 0);
264
+ return lookup_object(oid->hash);
265
}
266
273
- buffer = read_sha1_file(sha1, &type, &size);
267
+ buffer = read_sha1_file(oid->hash, &type, &size);
268
if (buffer) {
269
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
270
free(buffer);
272
return NULL;
273
}
274
281
- obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
275
+ obj = parse_object_buffer(oid, type, size, buffer, &eaten);
276
if (!eaten)
277
free(buffer);
278
return obj;