@@ -43,40 +43,43 @@ int cmd_show_index(int argc,
4343 /*
4444 * Fallback to SHA1 if we are running outside of a repository.
4545 *
46- * TODO: Figure out and implement a way to detect the hash algorithm in use by the
47- * the index file passed in and use that instead.
46+ * TODO: If a future implementation of index file version encodes the hash
47+ * algorithm in its header, enable show-index to infer it from the
48+ * header rather than relying on repository context or a default fallback.
4849 */
49- if (!the_hash_algo )
50+ if (!the_hash_algo ) {
51+ warning (_ ("assuming SHA-1; use --object-format to override" ));
5052 repo_set_hash_algo (the_repository , GIT_HASH_DEFAULT );
53+ }
5154
5255 hashsz = the_hash_algo -> rawsz ;
5356
5457 if (fread (top_index , 2 * 4 , 1 , stdin ) != 1 )
55- die ("unable to read header" );
58+ die (_ ( "unable to read header" ) );
5659 if (top_index [0 ] == htonl (PACK_IDX_SIGNATURE )) {
5760 version = ntohl (top_index [1 ]);
5861 if (version < 2 || version > 2 )
59- die ("unknown index version" );
62+ die (_ ( "unknown index version" ) );
6063 if (fread (top_index , 256 * 4 , 1 , stdin ) != 1 )
61- die ("unable to read index" );
64+ die (_ ( "unable to read index" ) );
6265 } else {
6366 version = 1 ;
6467 if (fread (& top_index [2 ], 254 * 4 , 1 , stdin ) != 1 )
65- die ("unable to read index" );
68+ die (_ ( "unable to read index" ) );
6669 }
6770 nr = 0 ;
6871 for (i = 0 ; i < 256 ; i ++ ) {
6972 unsigned n = ntohl (top_index [i ]);
7073 if (n < nr )
71- die ("corrupt index file" );
74+ die (_ ( "corrupt index file" ) );
7275 nr = n ;
7376 }
7477 if (version == 1 ) {
7578 for (i = 0 ; i < nr ; i ++ ) {
7679 unsigned int offset , entry [(GIT_MAX_RAWSZ + 4 ) / sizeof (unsigned int )];
7780
7881 if (fread (entry , 4 + hashsz , 1 , stdin ) != 1 )
79- die ("unable to read entry %u/%u" , i , nr );
82+ die (_ ( "unable to read entry %u/%u" ) , i , nr );
8083 offset = ntohl (entry [0 ]);
8184 printf ("%u %s\n" , offset , hash_to_hex ((void * )(entry + 1 )));
8285 }
@@ -90,15 +93,15 @@ int cmd_show_index(int argc,
9093 ALLOC_ARRAY (entries , nr );
9194 for (i = 0 ; i < nr ; i ++ ) {
9295 if (fread (entries [i ].oid .hash , hashsz , 1 , stdin ) != 1 )
93- die ("unable to read sha1 %u/%u" , i , nr );
96+ die (_ ( "unable to read sha1 %u/%u" ) , i , nr );
9497 entries [i ].oid .algo = hash_algo_by_ptr (the_hash_algo );
9598 }
9699 for (i = 0 ; i < nr ; i ++ )
97100 if (fread (& entries [i ].crc , 4 , 1 , stdin ) != 1 )
98- die ("unable to read crc %u/%u" , i , nr );
101+ die (_ ( "unable to read crc %u/%u" ) , i , nr );
99102 for (i = 0 ; i < nr ; i ++ )
100103 if (fread (& entries [i ].off , 4 , 1 , stdin ) != 1 )
101- die ("unable to read 32b offset %u/%u" , i , nr );
104+ die (_ ( "unable to read 32b offset %u/%u" ) , i , nr );
102105 for (i = 0 ; i < nr ; i ++ ) {
103106 uint64_t offset ;
104107 uint32_t off = ntohl (entries [i ].off );
@@ -107,9 +110,9 @@ int cmd_show_index(int argc,
107110 } else {
108111 uint32_t off64 [2 ];
109112 if ((off & 0x7fffffff ) != off64_nr )
110- die ("inconsistent 64b offset index" );
113+ die (_ ( "inconsistent 64b offset index" ) );
111114 if (fread (off64 , 8 , 1 , stdin ) != 1 )
112- die ("unable to read 64b offset %u" , off64_nr );
115+ die (_ ( "unable to read 64b offset %u" ) , off64_nr );
113116 offset = (((uint64_t )ntohl (off64 [0 ])) << 32 ) |
114117 ntohl (off64 [1 ]);
115118 off64_nr ++ ;
0 commit comments