summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/object.c b/object.c
index 980ac5fcdf..06ba3a11d8 100644
--- a/object.c
+++ b/object.c
@@ -68,7 +68,7 @@ static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
*/
static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
{
- unsigned int j = hash_obj(obj->sha1, size);
+ unsigned int j = hash_obj(obj->oid.hash, size);
while (hash[j]) {
j++;
@@ -92,7 +92,7 @@ struct object *lookup_object(const unsigned char *sha1)
first = i = hash_obj(sha1, obj_hash_size);
while ((obj = obj_hash[i]) != NULL) {
- if (!hashcmp(sha1, obj->sha1))
+ if (!hashcmp(sha1, obj->oid.hash))
break;
i++;
if (i == obj_hash_size)
@@ -104,9 +104,7 @@ struct object *lookup_object(const unsigned char *sha1)
* that we do not need to walk the hash table the next
* time we look for it.
*/
- struct object *tmp = obj_hash[i];
- obj_hash[i] = obj_hash[first];
- obj_hash[first] = tmp;
+ SWAP(obj_hash[i], obj_hash[first]);
}
return obj;
}
@@ -145,7 +143,7 @@ void *create_object(const unsigned char *sha1, void *o)
obj->parsed = 0;
obj->used = 0;
obj->flags = 0;
- hashcpy(obj->sha1, sha1);
+ hashcpy(obj->oid.hash, sha1);
if (obj_hash_size - 1 <= nr_objs * 2)
grow_object_hash();
@@ -168,7 +166,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
else {
if (!quiet)
error("object %s is a %s, not a %s",
- sha1_to_hex(obj->sha1),
+ oid_to_hex(&obj->oid),
typename(obj->type), typename(type));
return NULL;
}
@@ -182,21 +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 *obj;
*eaten_p = 0;
obj = NULL;
if (type == OBJ_BLOB) {
- struct blob *blob = lookup_blob(sha1);
+ 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(sha1);
+ struct tree *tree = lookup_tree(oid);
if (tree) {
obj = &tree->object;
if (!tree->buffer)
@@ -208,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(sha1);
+ struct commit *commit = lookup_commit(oid);
if (commit) {
if (parse_commit_buffer(commit, buffer, size))
return NULL;
@@ -219,54 +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(sha1);
+ 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;
- obj = lookup_object(sha1);
+ 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(sha1), 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);
@@ -274,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;