sha1_file: convert cached object code to struct object_id

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@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
brian m. carlson 2018-05-02 00:26:03 +00:00 committed by Junio C Hamano
parent d8448522d8
commit 62ba93eaa9
1 changed files with 8 additions and 8 deletions

View File

@ -119,7 +119,7 @@ const char *empty_blob_oid_hex(void)
* application). * application).
*/ */
static struct cached_object { static struct cached_object {
unsigned char sha1[20]; struct object_id oid;
enum object_type type; enum object_type type;
void *buf; void *buf;
unsigned long size; unsigned long size;
@ -127,22 +127,22 @@ static struct cached_object {
static int cached_object_nr, cached_object_alloc; static int cached_object_nr, cached_object_alloc;


static struct cached_object empty_tree = { static struct cached_object empty_tree = {
EMPTY_TREE_SHA1_BIN_LITERAL, { EMPTY_TREE_SHA1_BIN_LITERAL },
OBJ_TREE, OBJ_TREE,
"", "",
0 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; int i;
struct cached_object *co = cached_objects; struct cached_object *co = cached_objects;


for (i = 0; i < cached_object_nr; i++, co++) { for (i = 0; i < cached_object_nr; i++, co++) {
if (!hashcmp(co->sha1, sha1)) if (!oidcmp(&co->oid, oid))
return co; return co;
} }
if (!hashcmp(sha1, empty_tree.sha1)) if (!oidcmp(oid, the_hash_algo->empty_tree))
return &empty_tree; return &empty_tree;
return NULL; return NULL;
} }
@ -1260,7 +1260,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
oi = &blank_oi; oi = &blank_oi;


if (!(flags & OBJECT_INFO_SKIP_CACHED)) { 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 (co) {
if (oi->typep) if (oi->typep)
*(oi->typep) = co->type; *(oi->typep) = co->type;
@ -1369,7 +1369,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
struct cached_object *co; struct cached_object *co;


hash_object_file(buf, len, type_name(type), oid); 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; return 0;
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc); ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
co = &cached_objects[cached_object_nr++]; co = &cached_objects[cached_object_nr++];
@ -1377,7 +1377,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
co->type = type; co->type = type;
co->buf = xmalloc(len); co->buf = xmalloc(len);
memcpy(co->buf, buf, len); memcpy(co->buf, buf, len);
hashcpy(co->sha1, oid->hash); oidcpy(&co->oid, oid);
return 0; return 0;
} }