object: convert parse_object* to take struct object_id

Make parse_object, parse_object_or_die, and parse_object_buffer take a
pointer to struct object_id.  Remove the temporary variables inserted
earlier, since they are no longer necessary.  Transform all of the
callers using the following semantic patch:

@@
expression E1;
@@
- parse_object(E1.hash)
+ parse_object(&E1)

@@
expression E1;
@@
- parse_object(E1->hash)
+ parse_object(E1)

@@
expression E1, E2;
@@
- parse_object_or_die(E1.hash, E2)
+ parse_object_or_die(&E1, E2)

@@
expression E1, E2;
@@
- parse_object_or_die(E1->hash, E2)
+ parse_object_or_die(E1, E2)

@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1.hash, E2, E3, E4, E5)
+ parse_object_buffer(&E1, E2, E3, E4, E5)

@@
expression E1, E2, E3, E4, E5;
@@
- parse_object_buffer(E1->hash, E2, E3, E4, E5)
+ parse_object_buffer(E1, E2, E3, E4, E5)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2017-05-06 22:10:38 +00:00
committed by Junio C Hamano
parent a9dbc17910
commit c251c83df2
38 changed files with 107 additions and 108 deletions

View File

@ -180,24 +180,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
return obj;
}
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
{
struct object_id oid;
struct object *obj;
*eaten_p = 0;
hashcpy(oid.hash, sha1);
obj = NULL;
if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(&oid);
struct blob *blob = lookup_blob(oid);
if (blob) {
if (parse_blob_buffer(blob, buffer, size))
return NULL;
obj = &blob->object;
}
} else if (type == OBJ_TREE) {
struct tree *tree = lookup_tree(&oid);
struct tree *tree = lookup_tree(oid);
if (tree) {
obj = &tree->object;
if (!tree->buffer)
@ -209,7 +206,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
}
}
} else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(&oid);
struct commit *commit = lookup_commit(oid);
if (commit) {
if (parse_commit_buffer(commit, buffer, size))
return NULL;
@ -220,57 +217,54 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
obj = &commit->object;
}
} else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(&oid);
struct tag *tag = lookup_tag(oid);
if (tag) {
if (parse_tag_buffer(tag, buffer, size))
return NULL;
obj = &tag->object;
}
} else {
warning("object %s has unknown type id %d", sha1_to_hex(sha1), type);
warning("object %s has unknown type id %d", oid_to_hex(oid), type);
obj = NULL;
}
return obj;
}
struct object *parse_object_or_die(const unsigned char *sha1,
struct object *parse_object_or_die(const struct object_id *oid,
const char *name)
{
struct object *o = parse_object(sha1);
struct object *o = parse_object(oid);
if (o)
return o;
die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1));
die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
}
struct object *parse_object(const unsigned char *sha1)
struct object *parse_object(const struct object_id *oid)
{
unsigned long size;
enum object_type type;
int eaten;
const unsigned char *repl = lookup_replace_object(sha1);
const unsigned char *repl = lookup_replace_object(oid->hash);
void *buffer;
struct object *obj;
struct object_id oid;
hashcpy(oid.hash, sha1);
obj = lookup_object(oid.hash);
obj = lookup_object(oid->hash);
if (obj && obj->parsed)
return obj;
if ((obj && obj->type == OBJ_BLOB) ||
(!obj && has_sha1_file(sha1) &&
sha1_object_info(sha1, NULL) == OBJ_BLOB)) {
(!obj && has_object_file(oid) &&
sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
error("sha1 mismatch %s", sha1_to_hex(repl));
error("sha1 mismatch %s", oid_to_hex(oid));
return NULL;
}
parse_blob_buffer(lookup_blob(&oid), NULL, 0);
return lookup_object(sha1);
parse_blob_buffer(lookup_blob(oid), NULL, 0);
return lookup_object(oid->hash);
}
buffer = read_sha1_file(sha1, &type, &size);
buffer = read_sha1_file(oid->hash, &type, &size);
if (buffer) {
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
free(buffer);
@ -278,7 +272,7 @@ struct object *parse_object(const unsigned char *sha1)
return NULL;
}
obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
obj = parse_object_buffer(oid, type, size, buffer, &eaten);
if (!eaten)
free(buffer);
return obj;