Skip to content

Commit 62ba93e

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d844852 commit 62ba93e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

sha1_file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,30 @@ const char *empty_blob_oid_hex(void)
119119
* application).
120120
*/
121121
static struct cached_object {
122-
unsigned char sha1[20];
122+
struct object_id oid;
123123
enum object_type type;
124124
void *buf;
125125
unsigned long size;
126126
} *cached_objects;
127127
static int cached_object_nr, cached_object_alloc;
128128

129129
static struct cached_object empty_tree = {
130-
EMPTY_TREE_SHA1_BIN_LITERAL,
130+
{ EMPTY_TREE_SHA1_BIN_LITERAL },
131131
OBJ_TREE,
132132
"",
133133
0
134134
};
135135

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)
137137
{
138138
int i;
139139
struct cached_object *co = cached_objects;
140140

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

12621262
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);
12641264
if (co) {
12651265
if (oi->typep)
12661266
*(oi->typep) = co->type;
@@ -1369,15 +1369,15 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
13691369
struct cached_object *co;
13701370

13711371
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))
13731373
return 0;
13741374
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
13751375
co = &cached_objects[cached_object_nr++];
13761376
co->size = len;
13771377
co->type = type;
13781378
co->buf = xmalloc(len);
13791379
memcpy(co->buf, buf, len);
1380-
hashcpy(co->sha1, oid->hash);
1380+
oidcpy(&co->oid, oid);
13811381
return 0;
13821382
}
13831383

0 commit comments

Comments
 (0)