]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/show-index: set the algorithm for object IDs
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 26 Apr 2021 01:02:57 +0000 (01:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Apr 2021 07:31:39 +0000 (16:31 +0900)
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>
builtin/show-index.c

index 8106b03a6b3243c4d8c5e86e9b668727598696ed..0e0b9fb95bc11395fecb3718cbe85fd7a0bea903 100644 (file)
@@ -71,9 +71,11 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
                        uint32_t off;
                } *entries;
                ALLOC_ARRAY(entries, nr);
-               for (i = 0; i < nr; i++)
+               for (i = 0; i < nr; i++) {
                        if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
                                die("unable to read sha1 %u/%u", i, nr);
+                       entries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);
+               }
                for (i = 0; i < nr; i++)
                        if (fread(&entries[i].crc, 4, 1, stdin) != 1)
                                die("unable to read crc %u/%u", i, nr);