Convert the code that looks up cached objects to use struct object_id. Adjust the lookup for empty trees to use the_hash_algo. Note that we don't need to be concerned about the hard-coded object ID in the empty_tree object since we never use it. Signed-off-by: brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> --- sha1_file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sha1_file.c b/sha1_file.c index 4328c61285..11c840f89c 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -107,7 +107,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = { * application). */ static struct cached_object { - unsigned char sha1[20]; + struct object_id oid; enum object_type type; void *buf; unsigned long size; @@ -115,22 +115,22 @@ static struct cached_object { static int cached_object_nr, cached_object_alloc; static struct cached_object empty_tree = { - EMPTY_TREE_SHA1_BIN_LITERAL, + { EMPTY_TREE_SHA1_BIN_LITERAL }, OBJ_TREE, "", 0 }; -static struct cached_object *find_cached_object(const unsigned char *sha1) +static struct cached_object *find_cached_object(const struct object_id *oid) { int i; struct cached_object *co = cached_objects; for (i = 0; i < cached_object_nr; i++, co++) { - if (!hashcmp(co->sha1, sha1)) + if (!oidcmp(&co->oid, oid)) return co; } - if (!hashcmp(sha1, empty_tree.sha1)) + if (!oidcmp(oid, the_hash_algo->empty_tree)) return &empty_tree; return NULL; } @@ -1248,7 +1248,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi oi = &blank_oi; if (!(flags & OBJECT_INFO_SKIP_CACHED)) { - struct cached_object *co = find_cached_object(real->hash); + struct cached_object *co = find_cached_object(real); if (co) { if (oi->typep) *(oi->typep) = co->type; @@ -1357,7 +1357,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, struct cached_object *co; hash_object_file(buf, len, type_name(type), oid); - if (has_sha1_file(oid->hash) || find_cached_object(oid->hash)) + if (has_sha1_file(oid->hash) || find_cached_object(oid)) return 0; ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); co = &cached_objects[cached_object_nr++]; @@ -1365,7 +1365,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, co->type = type; co->buf = xmalloc(len); memcpy(co->buf, buf, len); - hashcpy(co->sha1, oid->hash); + oidcpy(&co->oid, oid); return 0; }