{"thread":{"id":"64837","subject":"[RFC][PATCH 0/3] show-index: modernize and implement auto-detection of hash algorithm","startedAt":"2026-01-20T14:09:47Z","lastAt":"2026-01-30T17:07:10Z","messageCount":25,"participants":["Shreyansh Paliwal","Junio C Hamano","Patrick Steinhardt","Phillip Wood","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"534237","messageId":"20260120140901.517928-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":null,"subject":"[RFC][PATCH 0/3] show-index: modernize and implement auto-detection of hash algorithm","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-20T14:05:38Z","receivedAt":"2026-01-20T14:09:47Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"This patch series improves the current git show-index implementation,\nby adding automatic hash detection, removing global state variables,\nand wrapping error messages for better clarity.\n\nCurrently, when git show-index is run outside of a repository, it falls back\nto SHA-1 unless --object-format is explicitly provided, the first patch\nimplements automatic hash detection, but it only works when there are no\n64-bit offsets present in the index file.\nI am unsure if there is an appropriate way to detect such cases.\n\nAdditionally, please let me know if there are any tests that should be\nmade or modified for these changes, or if any documentation updates are\nexpected as well.\n\nDo let me know your thoughts on this.\n\nShreyansh Paliwal (3):\n  show-index: implement automatic hash detection\n  show-index: use gettext wrapping in error messages\n  show-index: remove global state variables\n\n builtin/show-index.c | 74 ++++++++++++++++++++++++++++----------------\n 1 file changed, 48 insertions(+), 26 deletions(-)\n\n-- \n2.52.0\n\n"},{"id":"534238","messageId":"20260120140901.517928-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260120140901.517928-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 1/3] show-index: implement automatic hash detection","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-20T14:05:39Z","receivedAt":"2026-01-20T14:09:55Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"When git show-index is run outside a repository,\nit currently falls back to SHA-1 unless the hash algorithm\nis explicitly specified via --object-format.\nThis can lead to failures when reading SHA-256 pack index files.\n\nTo prevent this add an automatic hash algorithm detection,\nas suggested by an existing TODO comment in the code.\n\nFor v2 index files, the fixed size can be computed and then,\nthe overall file size combined with the number of objects,\ncan be used to compute the hash size of the objects.\nSince SHA-1 and SHA-256 use fixed hash sizes (20 and 32 bytes,\nrespectively), the hash algorithm can be determined.\n\nThis detection is limited in scope. It only applies when the\nindex file does not contain any 64-bit offset entries, which introduce\nadditional variable-sized data into the file layout. When such offsets are\npresent, automatic detection becomes irrelevant, and the user is instead\nrequired to specify the hash algorithm explicitly using --object-format.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 45 +++++++++++++++++++++++++++++++++-----------\n 1 file changed, 34 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex 2c3e2940ce..be62edc57b 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -40,17 +40,6 @@ int cmd_show_index(int argc,\n \t\trepo_set_hash_algo(the_repository, hash_algo);\n \t}\n \n-\t/*\n-\t * Fallback to SHA1 if we are running outside of a repository.\n-\t *\n-\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n-\t *       the index file passed in and use that instead.\n-\t */\n-\tif (!the_hash_algo)\n-\t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n-\n-\thashsz = the_hash_algo->rawsz;\n-\n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n \t\tdie(\"unable to read header\");\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n@@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n \t\t\tdie(\"corrupt index file\");\n \t\tnr = n;\n \t}\n+\n+\t/* detection of hash algorithm\n+\tOnly works for small files, i.e without large offsets */\n+\tif(!the_hash_algo && version == 2) {\n+\t\tstruct stat st;\n+\t\tsize_t file_base_size;\n+\t\tsize_t table_size;\n+\t\tsize_t size_rem;\n+\t\tsize_t hash_size;\n+\n+\t\tif(fstat(0, &st) || !S_ISREG(st.st_mode))\n+\t\t\tdie(_(\"unable to detect hash from non-regular file\"));\n+\t\t\n+\t\tfile_base_size = 8 + (256 * 4);\n+\t\ttable_size = file_base_size + (nr * 4 * 4);\n+\t\tsize_rem = st.st_size - table_size;\n+\t\thash_size = size_rem / (nr + 2);\n+\n+\t\tif(hash_size == GIT_SHA1_RAWSZ) {\n+\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n+\t\t} else if(hash_size == GIT_SHA256_RAWSZ) {\n+\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA256);\n+\t\t} else {\n+\t\t\tdie(_(\"unable to detect hash algorithm, \"\n+\t\t\t\t\t\"use --object-format option\"));\n+\t\t}\n+\t}\n+\n+\t/* Final fallback to SHA1 */\n+\tif(!the_hash_algo)\n+\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n+\n+\thashsz = the_hash_algo->rawsz;\n+\n \tif (version == 1) {\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n-- \n2.52.0\n"},{"id":"534239","messageId":"20260120140901.517928-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260120140901.517928-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 2/3] show-index: use gettext wrapping in error messages","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-20T14:05:40Z","receivedAt":"2026-01-20T14:10:01Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"Previously, error messages were passed directly to die().\nAs suggested by the Git coding guidelines, wrap user-visible strings\nin the _() macro so they can be translated.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex be62edc57b..a9c2f18b73 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -41,23 +41,23 @@ int cmd_show_index(int argc,\n \t}\n \n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n-\t\tdie(\"unable to read header\");\n+\t\tdie(_(\"unable to read header\"));\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n \t\tif (version < 2 || version > 2)\n-\t\t\tdie(\"unknown index version\");\n+\t\t\tdie(_(\"unknown index version\"));\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t} else {\n \t\tversion = 1;\n \t\tif (fread(&top_index[2], 254 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t}\n \tnr = 0;\n \tfor (i = 0; i < 256; i++) {\n \t\tunsigned n = ntohl(top_index[i]);\n \t\tif (n < nr)\n-\t\t\tdie(\"corrupt index file\");\n+\t\t\tdie(_(\"corrupt index file\"));\n \t\tnr = n;\n \t}\n \n@@ -99,7 +99,7 @@ int cmd_show_index(int argc,\n \t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n \n \t\t\tif (fread(entry, 4 + hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read entry %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read entry %u/%u\"), i, nr);\n \t\t\toffset = ntohl(entry[0]);\n \t\t\tprintf(\"%u %s\\n\", offset, hash_to_hex((void *)(entry+1)));\n \t\t}\n@@ -113,15 +113,15 @@ int cmd_show_index(int argc,\n \t\tALLOC_ARRAY(entries, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read sha1 %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read sha1 %u/%u\"), i, nr);\n \t\t\tentries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);\n \t\t}\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read crc %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read crc %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].off, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read 32b offset %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read 32b offset %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tuint64_t offset;\n \t\t\tuint32_t off = ntohl(entries[i].off);\n@@ -130,9 +130,9 @@ int cmd_show_index(int argc,\n \t\t\t} else {\n \t\t\t\tuint32_t off64[2];\n \t\t\t\tif ((off & 0x7fffffff) != off64_nr)\n-\t\t\t\t\tdie(\"inconsistent 64b offset index\");\n+\t\t\t\t\tdie(_(\"inconsistent 64b offset index\"));\n \t\t\t\tif (fread(off64, 8, 1, stdin) != 1)\n-\t\t\t\t\tdie(\"unable to read 64b offset %u\", off64_nr);\n+\t\t\t\t\tdie(_(\"unable to read 64b offset %u\"), off64_nr);\n \t\t\t\toffset = (((uint64_t)ntohl(off64[0])) << 32) |\n \t\t\t\t\t\t     ntohl(off64[1]);\n \t\t\t\toff64_nr++;\n-- \n2.52.0\n\n"},{"id":"534240","messageId":"20260120140901.517928-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260120140901.517928-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 3/3] show-index: remove global state variables","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-20T14:05:41Z","receivedAt":"2026-01-20T14:10:05Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"As Git is in the process of removing global state,\nthis function still relies on the global variables,\nthe_repository and the_hash_algo.\n\nRemove the associated macro and the UNUSED attribute from\nthe repo parameter, and replace all uses of the_repository and\nthe_hash_algo with repo and repo->hash_algo, respectively.\n\nThis modernizes git show-index and makes it more compatible.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 19 +++++++++----------\n 1 file changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex a9c2f18b73..96adae14c0 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -16,7 +15,7 @@ static const char *const show_index_usage[] = {\n int cmd_show_index(int argc,\n \t\t   const char **argv,\n \t\t   const char *prefix,\n-\t\t   struct repository *repo UNUSED)\n+\t\t   struct repository *repo)\n {\n \tint i;\n \tunsigned nr;\n@@ -37,7 +36,7 @@ int cmd_show_index(int argc,\n \t\thash_algo = hash_algo_by_name(hash_name);\n \t\tif (hash_algo == GIT_HASH_UNKNOWN)\n \t\t\tdie(_(\"Unknown hash algorithm\"));\n-\t\trepo_set_hash_algo(the_repository, hash_algo);\n+\t\trepo_set_hash_algo(repo, hash_algo);\n \t}\n \n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n@@ -63,7 +62,7 @@ int cmd_show_index(int argc,\n \n \t/* detection of hash algorithm\n \tOnly works for small files, i.e without large offsets */\n-\tif(!the_hash_algo && version == 2) {\n+\tif(!repo->hash_algo && version == 2) {\n \t\tstruct stat st;\n \t\tsize_t file_base_size;\n \t\tsize_t table_size;\n@@ -79,9 +78,9 @@ int cmd_show_index(int argc,\n \t\thash_size = size_rem / (nr + 2);\n \n \t\tif(hash_size == GIT_SHA1_RAWSZ) {\n-\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n+\t\t\trepo_set_hash_algo(repo, GIT_HASH_SHA1);\n \t\t} else if(hash_size == GIT_SHA256_RAWSZ) {\n-\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA256);\n+\t\t\trepo_set_hash_algo(repo, GIT_HASH_SHA256);\n \t\t} else {\n \t\t\tdie(_(\"unable to detect hash algorithm, \"\n \t\t\t\t\t\"use --object-format option\"));\n@@ -89,10 +88,10 @@ int cmd_show_index(int argc,\n \t}\n \n \t/* Final fallback to SHA1 */\n-\tif(!the_hash_algo)\n-\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n+\tif(!repo->hash_algo)\n+\t\trepo_set_hash_algo(repo, GIT_HASH_SHA1);\n \n-\thashsz = the_hash_algo->rawsz;\n+\thashsz = repo->hash_algo->rawsz;\n \n \tif (version == 1) {\n \t\tfor (i = 0; i < nr; i++) {\n@@ -114,7 +113,7 @@ int cmd_show_index(int argc,\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n \t\t\t\tdie(_(\"unable to read sha1 %u/%u\"), i, nr);\n-\t\t\tentries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);\n+\t\t\tentries[i].oid.algo = hash_algo_by_ptr(repo->hash_algo);\n \t\t}\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n-- \n2.52.0\n\n"},{"id":"534275","messageId":"xmqqzf68yx75.fsf@gitster.g","threadId":"64837","inReplyTo":"20260120140901.517928-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-20T18:07:42Z","receivedAt":"2026-01-20T18:07:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n\n> @@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n>  \t\t\tdie(\"corrupt index file\");\n>  \t\tnr = n;\n>  \t}\n> +\n> +\t/* detection of hash algorithm\n> +\tOnly works for small files, i.e without large offsets */\n> +\tif(!the_hash_algo && version == 2) {\n\nWe have one SP between \"if\" (and other syntactic elements like\n\"while\") and the open parenthesis \"(\".  End-user controlled function\nnames lack this SP between <word> and \"(\".\n\nIf we turn what is inide of this block into a separate helper\nfunction, it would allow us to structure the logic better.\n\n\t/* Returns GIT_HASH_* constants, or GIT_HASH_UNKNOWN */\n\tstatic int auto_detect_hash_function(int fd)\n\nFor example, ...\n\n> +\t\tstruct stat st;\n> +\t\tsize_t file_base_size;\n> +\t\tsize_t table_size;\n> +\t\tsize_t size_rem;\n> +\t\tsize_t hash_size;\n> +\n> +\t\tif(fstat(0, &st) || !S_ISREG(st.st_mode))\n> +\t\t\tdie(_(\"unable to detect hash from non-regular file\"));\n\n... this \"die()\" does not have to be here.  We can just return\nGIT_HASH_UNKNOWN and let the caller fallback.  Does the existing\ncode correctly complain when the filestream is opened for a\nnon-regular file, or it just gets totally confused?\n\n> +\t\tfile_base_size = 8 + (256 * 4);\n> +\t\ttable_size = file_base_size + (nr * 4 * 4);\n> +\t\tsize_rem = st.st_size - table_size;\n> +\t\thash_size = size_rem / (nr + 2);\n> +\n> +\t\tif(hash_size == GIT_SHA1_RAWSZ) {\n> +\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> +\t\t} else if(hash_size == GIT_SHA256_RAWSZ) {\n> +\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA256);\n\nAnd instead of calling repo_set_hash_algo(), just return the\nconstants so that the caller can handle it.  And \n\n> +\t\t} else {\n> +\t\t\tdie(_(\"unable to detect hash algorithm, \"\n> +\t\t\t\t\t\"use --object-format option\"));\n\n... this also can return GIT_HASH_UNKNOWN, without complaining\nanything.\n\n> +\t\t}\n> +\t}\n\nSo, instead of inserting all of the above lines in cmd_show_index(),\nwe'd have something like the following ...\n\n\thash_func = auto_detect_hash_function(0);\n\tif (hash_func == GIT_HASH_UNKNOWN) {\n\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n\t\thash_func = GIT_HASH_SHA1;\n\t}\n\trepo_set_hash_algo(the_repository, hash_func);\n        hashsz = the_hash_algo->rawsz;\n\n... there.\n\nBy the way, what happens if we find SHA-256 also broken and end up\nchoosing another hash function that is 256-bit wide in the next hash\nrevamp?\n\nThanks.\n\n> +\n> +\t/* Final fallback to SHA1 */\n> +\tif(!the_hash_algo)\n> +\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> +\n> +\thashsz = the_hash_algo->rawsz;\n> +\n>  \tif (version == 1) {\n>  \t\tfor (i = 0; i < nr; i++) {\n>  \t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n"},{"id":"534318","messageId":"aXCJp_rGPetsXE8J@pks.im","threadId":"64837","inReplyTo":"xmqqzf68yx75.fsf@gitster.g","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-01-21T08:09:11Z","receivedAt":"2026-01-21T08:09:22Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:\n> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n> > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n[snip]\n> By the way, what happens if we find SHA-256 also broken and end up\n> choosing another hash function that is 256-bit wide in the next hash\n> revamp?\n\nYeah, agreed. The index unfortunately does not carry sufficient info to\nclearly identify the hash function that is in use, and second-guessing\nvia the hash length doesn't really seem like a sensible solution to me.\nIf we cannot tell for sure what the hash is, then we should rather ask\nthe user to specify the object format. And in fact we already do that,\nas we have the `--object-format=` option for git-show-index(1).\n\nI think if we wanted to fix properly this we should rather introduce\nindex v5 with a header that encodes the hash used by it. Like that we\nwouldn't have to guess anymore. Whether the hassle is worth it might be\na different question though.\n\nPatrick\n"},{"id":"534325","messageId":"20260121102956.759871-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"xmqqzf68yx75.fsf@gitster.g","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-21T10:28:34Z","receivedAt":"2026-01-21T10:30:15Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n> \n> > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n> >\t\t\tdie(\"corrupt index file\");\n> >\t\tnr = n;\n> >\t}\n> > +\n> > +\t/* detection of hash algorithm\n> > +\tOnly works for small files, i.e without large offsets */\n> > +\tif(!the_hash_algo && version == 2) {\n> \n> We have one SP between \"if\" (and other syntactic elements like\n> \"while\") and the open parenthesis \"(\".  End-user controlled function\n> names lack this SP between <word> and \"(\".\n> \n\nGot it, I will keep this in mind.\n\n> For example, ...\n> \n> > +\t\tstruct stat st;\n> > +\t\tsize_t file_base_size;\n> > +\t\tsize_t table_size;\n> > +\t\tsize_t size_rem;\n> > +\t\tsize_t hash_size;\n> > +\n> > +\t\tif(fstat(0, &st) || !S_ISREG(st.st_mode))\n> > +\t\t\tdie(_(\"unable to detect hash from non-regular file\"));\n> \n> ... this \"die()\" does not have to be here.  We can just return\n> GIT_HASH_UNKNOWN and let the caller fallback.  Does the existing\n> code correctly complain when the filestream is opened for a\n> non-regular file, or it just gets totally confused?\n> \n\nI believe there is no explicit check for\nirregular files in the current implementation.\n\n> > +\t\tfile_base_size = 8 + (256 * 4);\n> > +\t\ttable_size = file_base_size + (nr * 4 * 4);\n> > +\t\tsize_rem = st.st_size - table_size;\n> > +\t\thash_size = size_rem / (nr + 2);\n> > +\n> > +\t\tif(hash_size == GIT_SHA1_RAWSZ) {\n> > +\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> > +\t\t} else if(hash_size == GIT_SHA256_RAWSZ) {\n> > +\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA256);\n> \n> And instead of calling repo_set_hash_algo(), just return the\n> constants so that the caller can handle it.  And \n> \n> > +\t\t} else {\n> > +\t\t\tdie(_(\"unable to detect hash algorithm, \"\n> > +\t\t\t\t\t\"use --object-format option\"));\n> \n> ... this also can return GIT_HASH_UNKNOWN, without complaining\n> anything.\n> \n> > +\t\t}\n> > +\t}\n> \n> So, instead of inserting all of the above lines in cmd_show_index(),\n> we'd have something like the following ...\n> \n> \thash_func = auto_detect_hash_function(0);\n> \tif (hash_func == GIT_HASH_UNKNOWN) {\n> \t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n> \t\thash_func = GIT_HASH_SHA1;\n> \t}\n> \trepo_set_hash_algo(the_repository, hash_func);\n>         hashsz = the_hash_algo->rawsz;\n> \n> ... there.\n> \n\nYes this is surely a much better approach than before,\nI will implement this as a seperate helper function in v2\nif we go ahead with the detection logic.\n"},{"id":"534326","messageId":"20260121103431.793004-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"aXCJp_rGPetsXE8J@pks.im","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-21T10:31:47Z","receivedAt":"2026-01-21T10:34:42Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:\n> > Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n> > > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n> [snip]\n> > By the way, what happens if we find SHA-256 also broken and end up\n> > choosing another hash function that is 256-bit wide in the next hash\n> > revamp?\n> \n> Yeah, agreed. The index unfortunately does not carry sufficient info to\n> clearly identify the hash function that is in use, and second-guessing\n> via the hash length doesn't really seem like a sensible solution to me.\n> If we cannot tell for sure what the hash is, then we should rather ask\n> the user to specify the object format. And in fact we already do that,\n> as we have the `--object-format=` option for git-show-index(1).\n\nYes this is exactly why I was peculiar about this patch and the\nTODO comment, also why I sent it out as an RFC.\n\nI initially assumed that in the near future we’re unlikely to move away\nfrom SHA-256 to another hash, but I agree that relying\non hash length is still a heuristic that won't be a good approach\nin the long term as well as it creates ambiguity in the large files\ncontaining 64-bit offsets.\n\nSo should we drop this thought entirely and just make sure\nthat if git show-index is run outside a repo,\nit should throw an error asking the the user\nto use --object-format option rather than silently\nfalling back to SHA-1 which is the current approach.\n\n> I think if we wanted to fix properly this we should rather introduce\n> index v5 with a header that encodes the hash used by it. Like that we\n> wouldn't have to guess anymore. Whether the hassle is worth it might be\n> a different question though.\n\nYes, I agree that the best fix for long term would be an index\nthat contains header encoded with hash, but I guess\nit would require many changes in the whole pack index flow.\n\nBest,\nShreyansh\n\n"},{"id":"534327","messageId":"7b5dd0c4-0ca0-458e-89db-621a70dac9ae@gmail.com","threadId":"64837","inReplyTo":"20260120140901.517928-4-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 3/3] show-index: remove global state variables","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-01-21T10:39:57Z","receivedAt":"2026-01-21T10:40:00Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 20/01/2026 14:05, Shreyansh Paliwal wrote:\n> As Git is in the process of removing global state,\n> this function still relies on the global variables,\n> the_repository and the_hash_algo.\n> \n> Remove the associated macro and the UNUSED attribute from\n> the repo parameter, and replace all uses of the_repository and\n> the_hash_algo with repo and repo->hash_algo, respectively.\n\nI don't think that is a good idea because repo will be NULL outside of a \nrepository. For a lot of commands that does not matter because they \nrequire a repository to run but judging from the first patch in this \nseries this command is supposed to be able to run outside a repository.\n\nI'm increasingly of the opinion that adding a repository argument to the \nbuiltin commands was a mistake as they all just use a single repository \nso using \"the_repository\" seems perfectly reasonable. It leads to \nproblems like the segfault in this patch and takes attention away from \nthe much more useful task of moving our library code away from using \n\"the_repository\". If you're interested in contributing to that effort \nthen there are a number of instances of \"the_repository\" in wt-status.c \nthat can be trivially replaced by the repository instance in \"struct \nwt_status\" or the repository passed to the function. I'm not sure how \neasy it is to remove them all - you might need to change the code to \npass a repository instance down the call chain in a few cases but there \nare certainly quite a few that can be easily and usefully cleaned up.\n\nThanks\n\nPhillip\n\n> This modernizes git show-index and makes it more compatible.\n> \n> Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n> ---\n>   builtin/show-index.c | 19 +++++++++----------\n>   1 file changed, 9 insertions(+), 10 deletions(-)\n> \n> diff --git a/builtin/show-index.c b/builtin/show-index.c\n> index a9c2f18b73..96adae14c0 100644\n> --- a/builtin/show-index.c\n> +++ b/builtin/show-index.c\n> @@ -1,4 +1,3 @@\n> -#define USE_THE_REPOSITORY_VARIABLE\n>   #define DISABLE_SIGN_COMPARE_WARNINGS\n>   \n>   #include \"builtin.h\"\n> @@ -16,7 +15,7 @@ static const char *const show_index_usage[] = {\n>   int cmd_show_index(int argc,\n>   \t\t   const char **argv,\n>   \t\t   const char *prefix,\n> -\t\t   struct repository *repo UNUSED)\n> +\t\t   struct repository *repo)\n>   {\n>   \tint i;\n>   \tunsigned nr;\n> @@ -37,7 +36,7 @@ int cmd_show_index(int argc,\n>   \t\thash_algo = hash_algo_by_name(hash_name);\n>   \t\tif (hash_algo == GIT_HASH_UNKNOWN)\n>   \t\t\tdie(_(\"Unknown hash algorithm\"));\n> -\t\trepo_set_hash_algo(the_repository, hash_algo);\n> +\t\trepo_set_hash_algo(repo, hash_algo);\n>   \t}\n>   \n>   \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n> @@ -63,7 +62,7 @@ int cmd_show_index(int argc,\n>   \n>   \t/* detection of hash algorithm\n>   \tOnly works for small files, i.e without large offsets */\n> -\tif(!the_hash_algo && version == 2) {\n> +\tif(!repo->hash_algo && version == 2) {\n>   \t\tstruct stat st;\n>   \t\tsize_t file_base_size;\n>   \t\tsize_t table_size;\n> @@ -79,9 +78,9 @@ int cmd_show_index(int argc,\n>   \t\thash_size = size_rem / (nr + 2);\n>   \n>   \t\tif(hash_size == GIT_SHA1_RAWSZ) {\n> -\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> +\t\t\trepo_set_hash_algo(repo, GIT_HASH_SHA1);\n>   \t\t} else if(hash_size == GIT_SHA256_RAWSZ) {\n> -\t\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA256);\n> +\t\t\trepo_set_hash_algo(repo, GIT_HASH_SHA256);\n>   \t\t} else {\n>   \t\t\tdie(_(\"unable to detect hash algorithm, \"\n>   \t\t\t\t\t\"use --object-format option\"));\n> @@ -89,10 +88,10 @@ int cmd_show_index(int argc,\n>   \t}\n>   \n>   \t/* Final fallback to SHA1 */\n> -\tif(!the_hash_algo)\n> -\t\trepo_set_hash_algo(the_repository, GIT_HASH_SHA1);\n> +\tif(!repo->hash_algo)\n> +\t\trepo_set_hash_algo(repo, GIT_HASH_SHA1);\n>   \n> -\thashsz = the_hash_algo->rawsz;\n> +\thashsz = repo->hash_algo->rawsz;\n>   \n>   \tif (version == 1) {\n>   \t\tfor (i = 0; i < nr; i++) {\n> @@ -114,7 +113,7 @@ int cmd_show_index(int argc,\n>   \t\tfor (i = 0; i < nr; i++) {\n>   \t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n>   \t\t\t\tdie(_(\"unable to read sha1 %u/%u\"), i, nr);\n> -\t\t\tentries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);\n> +\t\t\tentries[i].oid.algo = hash_algo_by_ptr(repo->hash_algo);\n>   \t\t}\n>   \t\tfor (i = 0; i < nr; i++)\n>   \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n\n"},{"id":"534331","messageId":"20260121124754.848110-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"7b5dd0c4-0ca0-458e-89db-621a70dac9ae@gmail.com","subject":"Re: [PATCH 3/3] show-index: remove global state variables","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-21T12:47:20Z","receivedAt":"2026-01-21T12:48:07Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> On 20/01/2026 14:05, Shreyansh Paliwal wrote:\n> > As Git is in the process of removing global state,\n> > this function still relies on the global variables,\n> > the_repository and the_hash_algo.\n> > \n> > Remove the associated macro and the UNUSED attribute from\n> > the repo parameter, and replace all uses of the_repository and\n> > the_hash_algo with repo and repo->hash_algo, respectively.\n> \n> I don't think that is a good idea because repo will be NULL outside of a \n> repository. For a lot of commands that does not matter because they \n> require a repository to run but judging from the first patch in this \n> series this command is supposed to be able to run outside a repository.\n> \n> I'm increasingly of the opinion that adding a repository argument to the \n> builtin commands was a mistake as they all just use a single repository \n> so using \"the_repository\" seems perfectly reasonable. It leads to \n> problems like the segfault in this patch and takes attention away from \n> the much more useful task of moving our library code away from using \n\nThat makes a lot of sense, especially for the commands\nwhich are meant to run outside the repo as well.\nIn hindsight, the NULL repo issue and the segfault risk\nshould have been obvious to me, particularly given that I started\nby creating the hash detection for no-repo cases :)\n\nAnyways I will drop this patch in the next version.\n\n> \"the_repository\". If you're interested in contributing to that effort \n> then there are a number of instances of \"the_repository\" in wt-status.c \n> that can be trivially replaced by the repository instance in \"struct \n> wt_status\" or the repository passed to the function. I'm not sure how \n> easy it is to remove them all - you might need to change the code to \n> pass a repository instance down the call chain in a few cases but there \n> are certainly quite a few that can be easily and usefully cleaned up.\n\nYes sure, I will take a look and see where I can contribute in wt-status.c,\ntowards reducing global-state usage.\n\nBest,\nShreyansh\n"},{"id":"534367","messageId":"xmqq4ioevq0n.fsf@gitster.g","threadId":"64837","inReplyTo":"7b5dd0c4-0ca0-458e-89db-621a70dac9ae@gmail.com","subject":"Re: [PATCH 3/3] show-index: remove global state variables","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-21T17:23:20Z","receivedAt":"2026-01-21T17:23:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> I'm increasingly of the opinion that adding a repository argument to the \n> builtin commands was a mistake as they all just use a single repository \n> so using \"the_repository\" seems perfectly reasonable. It leads to \n> problems like the segfault in this patch and takes attention away from \n> the much more useful task of moving our library code away from using \n> \"the_repository\".\n\nVery well said ;-)\n"},{"id":"534526","messageId":"aXMh0pYw2ZrptCNj@pks.im","threadId":"64837","inReplyTo":"20260121103431.793004-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-01-23T07:22:58Z","receivedAt":"2026-01-23T07:23:04Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Jan 21, 2026 at 04:01:47PM +0530, Shreyansh Paliwal wrote:\n> > On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:\n> > > Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n> > > > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,\n> > [snip]\n> > > By the way, what happens if we find SHA-256 also broken and end up\n> > > choosing another hash function that is 256-bit wide in the next hash\n> > > revamp?\n> > \n> > Yeah, agreed. The index unfortunately does not carry sufficient info to\n> > clearly identify the hash function that is in use, and second-guessing\n> > via the hash length doesn't really seem like a sensible solution to me.\n> > If we cannot tell for sure what the hash is, then we should rather ask\n> > the user to specify the object format. And in fact we already do that,\n> > as we have the `--object-format=` option for git-show-index(1).\n> \n> Yes this is exactly why I was peculiar about this patch and the\n> TODO comment, also why I sent it out as an RFC.\n> \n> I initially assumed that in the near future we’re unlikely to move away\n> from SHA-256 to another hash, but I agree that relying\n> on hash length is still a heuristic that won't be a good approach\n> in the long term as well as it creates ambiguity in the large files\n> containing 64-bit offsets.\n> \n> So should we drop this thought entirely and just make sure\n> that if git show-index is run outside a repo,\n> it should throw an error asking the the user\n> to use --object-format option rather than silently\n> falling back to SHA-1 which is the current approach.\n\nThat would be a regression for users that currently _can_ run\ngit-show-index(1) outside of a repository with a SHA-1 based index. It's\nnot going to be a common use case, but I wouldn't be surprised if there\nwas at least one user out there that we'd break with such a change.\n\nPatrick\n"},{"id":"534555","messageId":"20260123161017.37827-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"aXMh0pYw2ZrptCNj@pks.im","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-23T16:08:48Z","receivedAt":"2026-01-23T16:11:12Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> That would be a regression for users that currently _can_ run\n> git-show-index(1) outside of a repository with a SHA-1 based index. It's\n> not going to be a common use case, but I wouldn't be surprised if there\n> was at least one user out there that we'd break with such a change.\n\nThat makes sense, but relying on a silent SHA-1 fallback purely because we\nare outside of a repository still feels a bit ambiguous to me. It works today\nmostly because SHA-1 has historically been the default, but if in future\ngit introduces additional hash functions or if SHA-256 indexes become\nmore relevant to this particular usage.\n\nThough, I think based on the discussion so far,\nwe can only show a warning like this along with the SHA-1 fallback like this,\n\n    warning(_(\"assuming SHA-1; use --object-format to override\"));\n\nDo you think if this would be appropriate, or if anything \nbetter can be done to handle this or\nis it just better to leave the behavior as-is.\nLet me know :)\n\nBest,\nShreyansh\n"},{"id":"534578","messageId":"aXPaHWV62HEfHyy_@fruit.crustytoothpaste.net","threadId":"64837","inReplyTo":"aXCJp_rGPetsXE8J@pks.im","subject":"Re: [PATCH 1/3] show-index: implement automatic hash detection","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-01-23T20:29:17Z","receivedAt":"2026-01-23T20:29:25Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2026-01-21 at 08:09:11, Patrick Steinhardt wrote:\n> I think if we wanted to fix properly this we should rather introduce\n> index v5 with a header that encodes the hash used by it. Like that we\n> wouldn't have to guess anymore. Whether the hassle is worth it might be\n> a different question though.\n\nIndex v3, which will be used during interoperability, will encode the\nhash algorithm and can be used for single-hash implementations as well\nas multi-hash implementations.\n\nThere's an implementation in my `sha256-interop` branch at\nhttps://github.com/bk2204/git.git and we could simply enable it by\ndefault at some point in the future.\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"534818","messageId":"20260129153948.224156-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260120140901.517928-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-29T15:36:55Z","receivedAt":"2026-01-29T15:40:12Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"When 'git show-index' is run outside of a\nrepository and no hashing algorithm is\nspecified via --object-format, it silently\nfalls back to SHA-1, relying on the\nhistorical default.\n\nThis works for existing SHA-1 based\nindex files, but the behavior can be ambiguous\nand confusing when the input index file uses a\ndifferent hash algorithm, such as SHA-256.\n\nAdd a warning when this fallback happens\nto make the assumption explicit and to\nguide users toward using --object-format\nwhen needed.\n\nAdditionally, wrap user-facing die() messages\nwith _() so they can be translated via gettext.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 33 ++++++++++++++++++---------------\n 1 file changed, 18 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex 2c3e2940ce..14147c2ff2 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -36,39 +36,42 @@ int cmd_show_index(int argc,\n \tif (hash_name) {\n \t\thash_algo = hash_algo_by_name(hash_name);\n \t\tif (hash_algo == GIT_HASH_UNKNOWN)\n-\t\t\tdie(_(\"Unknown hash algorithm\"));\n+\t\t\tdie(_(\"unknown hash algorithm\"));\n \t\trepo_set_hash_algo(the_repository, hash_algo);\n \t}\n \n \t/*\n \t * Fallback to SHA1 if we are running outside of a repository.\n \t *\n-\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n-\t *       the index file passed in and use that instead.\n+\t * TODO: If a future implementation of index file version encodes the hash\n+\t *       algorithm in its header, enable show-index to infer it from the\n+\t *       header rather than relying on repository context or a default fallback.\n \t */\n-\tif (!the_hash_algo)\n+\tif (!the_hash_algo) {\n+\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n \t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n+\t}\n \n \thashsz = the_hash_algo->rawsz;\n \n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n-\t\tdie(\"unable to read header\");\n+\t\tdie(_(\"unable to read header\"));\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n \t\tif (version < 2 || version > 2)\n-\t\t\tdie(\"unknown index version\");\n+\t\t\tdie(_(\"unknown index version\"));\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t} else {\n \t\tversion = 1;\n \t\tif (fread(&top_index[2], 254 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t}\n \tnr = 0;\n \tfor (i = 0; i < 256; i++) {\n \t\tunsigned n = ntohl(top_index[i]);\n \t\tif (n < nr)\n-\t\t\tdie(\"corrupt index file\");\n+\t\t\tdie(_(\"corrupt index file\"));\n \t\tnr = n;\n \t}\n \tif (version == 1) {\n@@ -76,7 +79,7 @@ int cmd_show_index(int argc,\n \t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n \n \t\t\tif (fread(entry, 4 + hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read entry %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read entry %u/%u\"), i, nr);\n \t\t\toffset = ntohl(entry[0]);\n \t\t\tprintf(\"%u %s\\n\", offset, hash_to_hex((void *)(entry+1)));\n \t\t}\n@@ -90,15 +93,15 @@ int cmd_show_index(int argc,\n \t\tALLOC_ARRAY(entries, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read sha1 %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read sha1 %u/%u\"), i, nr);\n \t\t\tentries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);\n \t\t}\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read crc %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read crc %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].off, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read 32b offset %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read 32b offset %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tuint64_t offset;\n \t\t\tuint32_t off = ntohl(entries[i].off);\n@@ -107,9 +110,9 @@ int cmd_show_index(int argc,\n \t\t\t} else {\n \t\t\t\tuint32_t off64[2];\n \t\t\t\tif ((off & 0x7fffffff) != off64_nr)\n-\t\t\t\t\tdie(\"inconsistent 64b offset index\");\n+\t\t\t\t\tdie(_(\"inconsistent 64b offset index\"));\n \t\t\t\tif (fread(off64, 8, 1, stdin) != 1)\n-\t\t\t\t\tdie(\"unable to read 64b offset %u\", off64_nr);\n+\t\t\t\t\tdie(_(\"unable to read 64b offset %u\"), off64_nr);\n \t\t\t\toffset = (((uint64_t)ntohl(off64[0])) << 32) |\n \t\t\t\t\t\t     ntohl(off64[1]);\n \t\t\t\toff64_nr++;\n-- \n2.52.0\n"},{"id":"534843","messageId":"xmqq5x8k9g4b.fsf@gitster.g","threadId":"64837","inReplyTo":"20260129153948.224156-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-29T23:03:00Z","receivedAt":"2026-01-29T23:03:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n\n> When 'git show-index' is run outside of a\n> repository and no hashing algorithm is\n> specified via --object-format, it silently\n> falls back to SHA-1, relying on the\n> historical default.\n>\n> This works for existing SHA-1 based\n> index files, but the behavior can be ambiguous\n> and confusing when the input index file uses a\n> different hash algorithm, such as SHA-256.\n>\n> Add a warning when this fallback happens\n> to make the assumption explicit and to\n> guide users toward using --object-format\n> when needed.\n\nLine wrapping at 50 columns certainly makes the lines narrower than\n80 column limit, but let's not go to the extreme.  We recommend that\nthe lines are still less than 80-columns after being quoted a few\ntimes in e-mail exchange (as you can see, I lost 2 columns by\nquoting once in the above), which means that around ~70 columns is\nthe practical fill-column.\n\n> Additionally, wrap user-facing die() messages\n> with _() so they can be translated via gettext.\n\nIt is somewhat distracting that such \"while at it\" changes dominate\nthis ~100-line patch, whose \"primary change\" is a mere three lines\nwe can see here: \n\n> -\tif (!the_hash_algo)\n> +\tif (!the_hash_algo) {\n> +\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n>  \t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n> +\t}\n\n\nCan we push the \"while at it\" message changes to a separate patch, a\npreparatory clean-up, on top of which another primary patch adds the\nabove warning?  Alternatively, have the primary patch that adds the\nabove warning and does nothing else, followed by a post clean-up patch\nto tweak the existing error messages?\n\nThanks.\n"},{"id":"534844","messageId":"aXvpSPpfvulKu57P@fruit.crustytoothpaste.net","threadId":"64837","inReplyTo":"20260129153948.224156-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2026-01-29T23:12:08Z","receivedAt":"2026-01-29T23:12:10Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:\n>  \t/*\n>  \t * Fallback to SHA1 if we are running outside of a repository.\n>  \t *\n> -\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n> -\t *       the index file passed in and use that instead.\n> +\t * TODO: If a future implementation of index file version encodes the hash\n> +\t *       algorithm in its header, enable show-index to infer it from the\n> +\t *       header rather than relying on repository context or a default fallback.\n>  \t */\n> -\tif (!the_hash_algo)\n> +\tif (!the_hash_algo) {\n> +\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n>  \t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n\nIf we're going to start producing a warning, can we also learn a\n`--quiet` option to silence it?\n-- \nbrian m. carlson (they/them)\nToronto, Ontario, CA\n"},{"id":"534854","messageId":"20260130085949.253788-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"xmqq5x8k9g4b.fsf@gitster.g","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-30T08:59:22Z","receivedAt":"2026-01-30T09:00:01Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> > When 'git show-index' is run outside of a\n> > repository and no hashing algorithm is\n> > specified via --object-format, it silently\n> > falls back to SHA-1, relying on the\n> > historical default.\n> >\n> > This works for existing SHA-1 based\n> > index files, but the behavior can be ambiguous\n> > and confusing when the input index file uses a\n> > different hash algorithm, such as SHA-256.\n> >\n> > Add a warning when this fallback happens\n> > to make the assumption explicit and to\n> > guide users toward using --object-format\n> > when needed.\n> \n> Line wrapping at 50 columns certainly makes the lines narrower than\n> 80 column limit, but let's not go to the extreme.  We recommend that\n> the lines are still less than 80-columns after being quoted a few\n> times in e-mail exchange (as you can see, I lost 2 columns by\n> quoting once in the above), which means that around ~70 columns is\n> the practical fill-column.\n\nUnderstood. I Will make sure to keep message wrapping around ~70 columns.\n\n> > Additionally, wrap user-facing die() messages\n> > with _() so they can be translated via gettext.\n> \n> It is somewhat distracting that such \"while at it\" changes dominate\n> this ~100-line patch, whose \"primary change\" is a mere three lines\n> we can see here: \n> \n> > -\tif (!the_hash_algo)\n> > +\tif (!the_hash_algo) {\n> > +\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n> >\t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n> > +\t}\n> \n> \n> Can we push the \"while at it\" message changes to a separate patch, a\n> preparatory clean-up, on top of which another primary patch adds the\n> above warning?  Alternatively, have the primary patch that adds the\n> above warning and does nothing else, followed by a post clean-up patch\n> to tweak the existing error messages?\n\nYes, agreed. I’ll split the changes into separate patches again, as in\nthe original RFC series, and send a v2.\n\nBest,\nShreyansh\n"},{"id":"534855","messageId":"20260130090525.254665-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"aXvpSPpfvulKu57P@fruit.crustytoothpaste.net","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-30T09:04:53Z","receivedAt":"2026-01-30T09:05:37Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:\n> >\t/*\n> >\t * Fallback to SHA1 if we are running outside of a repository.\n> >\t *\n> > -\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n> > -\t *       the index file passed in and use that instead.\n> > +\t * TODO: If a future implementation of index file version encodes the hash\n> > +\t *       algorithm in its header, enable show-index to infer it from the\n> > +\t *       header rather than relying on repository context or a default fallback.\n> >\t */\n> > -\tif (!the_hash_algo)\n> > +\tif (!the_hash_algo) {\n> > +\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n> >\t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n> \n> If we're going to start producing a warning, can we also learn a\n> `--quiet` option to silence it?\n\nHi,\n\nThat is a good point.\nHowever, the warning is only shown for a particular usecase: when \n'git show-index' is run outside of a repository and --object-format\nis not specified. Given that narrow scope, I’m wondering whether\nadding a dedicated --quiet option for only this warning would be worthwhile.\n\nLet me know what you think :)\n\nBest,\nShreyansh\n"},{"id":"534873","messageId":"aXy0bife-Ubi9gnn@pks.im","threadId":"64837","inReplyTo":"20260130090525.254665-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-01-30T13:40:15Z","receivedAt":"2026-01-30T13:40:31Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jan 30, 2026 at 02:34:53PM +0530, Shreyansh Paliwal wrote:\n> > On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:\n> > >\t/*\n> > >\t * Fallback to SHA1 if we are running outside of a repository.\n> > >\t *\n> > > -\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n> > > -\t *       the index file passed in and use that instead.\n> > > +\t * TODO: If a future implementation of index file version encodes the hash\n> > > +\t *       algorithm in its header, enable show-index to infer it from the\n> > > +\t *       header rather than relying on repository context or a default fallback.\n> > >\t */\n> > > -\tif (!the_hash_algo)\n> > > +\tif (!the_hash_algo) {\n> > > +\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n> > >\t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n> > \n> > If we're going to start producing a warning, can we also learn a\n> > `--quiet` option to silence it?\n> \n> Hi,\n> \n> That is a good point.\n> However, the warning is only shown for a particular usecase: when \n> 'git show-index' is run outside of a repository and --object-format\n> is not specified. Given that narrow scope, I’m wondering whether\n> adding a dedicated --quiet option for only this warning would be worthwhile.\n> \n> Let me know what you think :)\n\nI also wonder whether \"--quiet\" might be a bit _too_ generic in this\ncontext. I would rather want to use this flag for something that you\nactually have a good reason to silence, instead of only for a warning.\n\nIn theory, the user already has the ability to silence the warning: they\ncan simply pass \"--object-format=sha256\". If you think that's not enough\nI'd buid on top of our `advice_if_enabled()` infra, so that the warning\ncan be globally disabled by setting a config option.\n\nThanks!\n\nPatrick\n"},{"id":"534882","messageId":"20260130153603.290196-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260129153948.224156-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH V2 0/2] show-index: add warning and wrap error messages with gettext","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-30T15:31:22Z","receivedAt":"2026-01-30T15:36:22Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"'git show-index' relies on implicit assumption in the absence\nof repository context to fall back to SHA-1 as the hashing\nalgorithm.\n\npatch 1/2: add a warning when this fallback happens.\n\npatch 2/2: cleanup by adding gettext wrapping to all\nuser-facing error messages in show-index.c.\n\nShreyansh Paliwal (2):\n  show-index: warn when falling back to SHA-1 outside a repository\n  show-index: use gettext wrapping in user facing error messages\n\n builtin/show-index.c | 31 +++++++++++++++++--------------\n 1 file changed, 17 insertions(+), 14 deletions(-)\n\n---\nChanges in V2:\n - Split the original patch into two separate patches for better\n    clarity and distinction.\n - Improved line wrapping to around ~70 columns.\n-- \n2.52.0\n"},{"id":"534883","messageId":"20260130153603.290196-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260130153603.290196-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH V2 1/2] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-30T15:31:23Z","receivedAt":"2026-01-30T15:36:27Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"When 'git show-index' is run outside of a repository and no hashing\nalgorithm is specified via --object-format, it silently falls back\nto SHA-1, relying on the historical default.\n\nThis works for existing SHA-1 based index files, but the behavior can\nbe ambiguous and confusing when the input index file uses a different\nhash algorithm, such as SHA-256.\n\nAdd a warning when this fallback happens to make the assumption\nexplicit and to guide users toward using --object-format when needed.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 9 ++++++---\n 1 file changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex 2c3e2940ce..45795da2da 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -43,11 +43,14 @@ int cmd_show_index(int argc,\n \t/*\n \t * Fallback to SHA1 if we are running outside of a repository.\n \t *\n-\t * TODO: Figure out and implement a way to detect the hash algorithm in use by the\n-\t *       the index file passed in and use that instead.\n+\t * TODO: If a future implementation of index file version encodes the hash\n+\t *       algorithm in its header, enable show-index to infer it from the\n+\t *       header rather than relying on repository context or a default fallback.\n \t */\n-\tif (!the_hash_algo)\n+\tif (!the_hash_algo) {\n+\t\twarning(_(\"assuming SHA-1; use --object-format to override\"));\n \t\trepo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);\n+\t}\n \n \thashsz = the_hash_algo->rawsz;\n \n-- \n2.52.0\n\n"},{"id":"534884","messageId":"20260130153603.290196-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"64837","inReplyTo":"20260130153603.290196-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH V2 2/2] show-index: use gettext wrapping in user facing error messages","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-01-30T15:31:24Z","receivedAt":"2026-01-30T15:36:31Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"Multiple 'die()' calls in show-index.c use literal strings directly.\n\nWrap all user-facing 'die()' messages with '_()' so they can be translated\nvia gettext, this ensures better support for users.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/show-index.c | 22 +++++++++++-----------\n 1 file changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex 45795da2da..24f0230967 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -55,23 +55,23 @@ int cmd_show_index(int argc,\n \thashsz = the_hash_algo->rawsz;\n \n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\n-\t\tdie(\"unable to read header\");\n+\t\tdie(_(\"unable to read header\"));\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n \t\tif (version < 2 || version > 2)\n-\t\t\tdie(\"unknown index version\");\n+\t\t\tdie(_(\"unknown index version\"));\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t} else {\n \t\tversion = 1;\n \t\tif (fread(&top_index[2], 254 * 4, 1, stdin) != 1)\n-\t\t\tdie(\"unable to read index\");\n+\t\t\tdie(_(\"unable to read index\"));\n \t}\n \tnr = 0;\n \tfor (i = 0; i < 256; i++) {\n \t\tunsigned n = ntohl(top_index[i]);\n \t\tif (n < nr)\n-\t\t\tdie(\"corrupt index file\");\n+\t\t\tdie(_(\"corrupt index file\"));\n \t\tnr = n;\n \t}\n \tif (version == 1) {\n@@ -79,7 +79,7 @@ int cmd_show_index(int argc,\n \t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n \n \t\t\tif (fread(entry, 4 + hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read entry %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read entry %u/%u\"), i, nr);\n \t\t\toffset = ntohl(entry[0]);\n \t\t\tprintf(\"%u %s\\n\", offset, hash_to_hex((void *)(entry+1)));\n \t\t}\n@@ -93,15 +93,15 @@ int cmd_show_index(int argc,\n \t\tALLOC_ARRAY(entries, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read sha1 %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read sha1 %u/%u\"), i, nr);\n \t\t\tentries[i].oid.algo = hash_algo_by_ptr(the_hash_algo);\n \t\t}\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read crc %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read crc %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].off, 4, 1, stdin) != 1)\n-\t\t\t\tdie(\"unable to read 32b offset %u/%u\", i, nr);\n+\t\t\t\tdie(_(\"unable to read 32b offset %u/%u\"), i, nr);\n \t\tfor (i = 0; i < nr; i++) {\n \t\t\tuint64_t offset;\n \t\t\tuint32_t off = ntohl(entries[i].off);\n@@ -110,9 +110,9 @@ int cmd_show_index(int argc,\n \t\t\t} else {\n \t\t\t\tuint32_t off64[2];\n \t\t\t\tif ((off & 0x7fffffff) != off64_nr)\n-\t\t\t\t\tdie(\"inconsistent 64b offset index\");\n+\t\t\t\t\tdie(_(\"inconsistent 64b offset index\"));\n \t\t\t\tif (fread(off64, 8, 1, stdin) != 1)\n-\t\t\t\t\tdie(\"unable to read 64b offset %u\", off64_nr);\n+\t\t\t\t\tdie(_(\"unable to read 64b offset %u\"), off64_nr);\n \t\t\t\toffset = (((uint64_t)ntohl(off64[0])) << 32) |\n \t\t\t\t\t\t     ntohl(off64[1]);\n \t\t\t\toff64_nr++;\n-- \n2.52.0\n\n"},{"id":"534898","messageId":"xmqqms1v6nlv.fsf@gitster.g","threadId":"64837","inReplyTo":"aXy0bife-Ubi9gnn@pks.im","subject":"Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-30T17:01:48Z","receivedAt":"2026-01-30T17:01:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> I also wonder whether \"--quiet\" might be a bit _too_ generic in this\n> context. I would rather want to use this flag for something that you\n> actually have a good reason to silence, instead of only for a warning.\n>\n> In theory, the user already has the ability to silence the warning: they\n> can simply pass \"--object-format=sha256\". If you think that's not enough\n> I'd buid on top of our `advice_if_enabled()` infra, so that the warning\n> can be globally disabled by setting a config option.\n\nI like the \"use --object-format then you would never see this\nwarning\" very much.  It is possible that we may want to squelch\nany and all warning and error messages, not limited to this one,\nin which case it is an option to add \"--quiet\" to the command, but I\nsomehow feel that it is outside the topic of this change.\n\nThanks.\n"},{"id":"534899","messageId":"xmqqikcj6ncz.fsf@gitster.g","threadId":"64837","inReplyTo":"20260130153603.290196-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH V2 0/2] show-index: add warning and wrap error messages with gettext","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-30T17:07:08Z","receivedAt":"2026-01-30T17:07:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n\n> Changes in V2:\n>  - Split the original patch into two separate patches for better\n>     clarity and distinction.\n>  - Improved line wrapping to around ~70 columns.\n\nQueued.  Thanks.\n"}]}