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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 26, 2021 at 01:02 UTC dd15f4f4570f9fed3012132adf9bf95cd921442b
1 file changed +3 -1
builtin/show-index.c
+3 -1
@@ -71,9 +71,11 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
71 uint32_t off;
72 } *entries;
73 ALLOC_ARRAY(entries, nr);
74 - for (i = 0; i < nr; i++)
74 + for (i = 0; i < nr; i++) {
75 if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
76 die("unable to read sha1 %u/%u", i, nr);
77 + entries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);
78 + }
79 for (i = 0; i < nr; i++)
80 if (fread(&entries[i].crc, 4, 1, stdin) != 1)
81 die("unable to read crc %u/%u", i, nr);