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>

brian m. carlson committed May 2, 2018 at 00:26 UTC 62ba93eaa9dfac60c17e362220b3f1dd183bf5ac
1 file changed +8 -8
sha1_file.c
+8 -8
@@ -119,7 +119,7 @@ const char *empty_blob_oid_hex(void)
119 * application).
120 */
121 static struct cached_object {
122 - unsigned char sha1[20];
122 + struct object_id oid;
123 enum object_type type;
124 void *buf;
125 unsigned long size;
@@ -127,22 +127,22 @@ static struct cached_object {
127 static int cached_object_nr, cached_object_alloc;
128
129 static struct cached_object empty_tree = {
130 - EMPTY_TREE_SHA1_BIN_LITERAL,
130 + { EMPTY_TREE_SHA1_BIN_LITERAL },
131 OBJ_TREE,
132 "",
133 0
134 };
135
136 -static struct cached_object *find_cached_object(const unsigned char *sha1)
136 +static struct cached_object *find_cached_object(const struct object_id *oid)
137 {
138 int i;
139 struct cached_object *co = cached_objects;
140
141 for (i = 0; i < cached_object_nr; i++, co++) {
142 - if (!hashcmp(co->sha1, sha1))
142 + if (!oidcmp(&co->oid, oid))
143 return co;
144 }
145 - if (!hashcmp(sha1, empty_tree.sha1))
145 + if (!oidcmp(oid, the_hash_algo->empty_tree))
146 return &empty_tree;
147 return NULL;
148 }
@@ -1260,7 +1260,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
1260 oi = &blank_oi;
1261
1262 if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
1263 - struct cached_object *co = find_cached_object(real->hash);
1263 + struct cached_object *co = find_cached_object(real);
1264 if (co) {
1265 if (oi->typep)
1266 *(oi->typep) = co->type;
@@ -1369,7 +1369,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1369 struct cached_object *co;
1370
1371 hash_object_file(buf, len, type_name(type), oid);
1372 - if (has_sha1_file(oid->hash) || find_cached_object(oid->hash))
1372 + if (has_sha1_file(oid->hash) || find_cached_object(oid))
1373 return 0;
1374 ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
1375 co = &cached_objects[cached_object_nr++];
@@ -1377,7 +1377,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1377 co->type = type;
1378 co->buf = xmalloc(len);
1379 memcpy(co->buf, buf, len);
1380 - hashcpy(co->sha1, oid->hash);
1380 + oidcpy(&co->oid, oid);
1381 return 0;
1382 }
1383