Skip to content

Commit dd15f4f

Browse files
bk2204gitster
authored andcommitted
builtin/show-index: set the algorithm for object IDs
In most cases, when we load the hash of an object into a struct object_id, we load it using one of the oid* or *_oid_hex functions. However, for git show-index, we read it in directly using fread. As a consequence, set the algorithm correctly so the objects can be used correctly both now and in the future. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1422844 commit dd15f4f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/show-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
7171
uint32_t off;
7272
} *entries;
7373
ALLOC_ARRAY(entries, nr);
74-
for (i = 0; i < nr; i++)
74+
for (i = 0; i < nr; i++) {
7575
if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
7676
die("unable to read sha1 %u/%u", i, nr);
77+
entries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);
78+
}
7779
for (i = 0; i < nr; i++)
7880
if (fread(&entries[i].crc, 4, 1, stdin) != 1)
7981
die("unable to read crc %u/%u", i, nr);

0 commit comments

Comments
 (0)