threads / rfc / 64837

RFC patch, 3 partsshow-index: modernize and implement auto-detection of hash algorithm

Subject: [RFC][PATCH 0/3] show-index: modernize and implement auto-detection of hash algorithm

## tl;dr

25 messages between Jan 20, 2026 and Jan 30, 2026. Diffs are folded; open one to read it.

replies: 24people: 5as markdown or json

Shreyansh Paliwal· Jan 20, 2026, 14:05 UTC · lore

This patch series improves the current git show-index implementation, by adding automatic hash detection, removing global state variables, and wrapping error messages for better clarity.

Currently, when git show-index is run outside of a repository, it falls back to SHA-1 unless --object-format is explicitly provided, the first patch implements automatic hash detection, but it only works when there are no 64-bit offsets present in the index file. I am unsure if there is an appropriate way to detect such cases.

Additionally, please let me know if there are any tests that should be made or modified for these changes, or if any documentation updates are expected as well.

Do let me know your thoughts on this.
Shreyansh Paliwal (3):
  show-index: implement automatic hash detection
  show-index: use gettext wrapping in error messages
  show-index: remove global state variables
 builtin/show-index.c | 74 ++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 26 deletions(-)
-- 
2.52.0
Shreyansh Paliwal· Jan 20, 2026, 14:05 UTC · re: Shreyansh Paliwal · lore

[PATCH 1/3] show-index: implement automatic hash detection

When git show-index is run outside a repository, it currently falls back to SHA-1 unless the hash algorithm is explicitly specified via --object-format. This can lead to failures when reading SHA-256 pack index files.

To prevent this add an automatic hash algorithm detection, as suggested by an existing TODO comment in the code.

For v2 index files, the fixed size can be computed and then, the overall file size combined with the number of objects, can be used to compute the hash size of the objects. Since SHA-1 and SHA-256 use fixed hash sizes (20 and 32 bytes, respectively), the hash algorithm can be determined.

This detection is limited in scope. It only applies when the index file does not contain any 64-bit offset entries, which introduce additional variable-sized data into the file layout. When such offsets are present, automatic detection becomes irrelevant, and the user is instead required to specify the hash algorithm explicitly using --object-format.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 45 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 11 deletions(-)
Show changes to builtin/show-index.c +34 −11
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 2c3e2940ce..be62edc57b 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -40,17 +40,6 @@ int cmd_show_index(int argc,
 		repo_set_hash_algo(the_repository, hash_algo);
 	}
 
-	/*
-	 * Fallback to SHA1 if we are running outside of a repository.
-	 *
-	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
-	 *       the index file passed in and use that instead.
-	 */
-	if (!the_hash_algo)
-		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
-
-	hashsz = the_hash_algo->rawsz;
-
 	if (fread(top_index, 2 * 4, 1, stdin) != 1)
 		die("unable to read header");
 	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
@@ -71,6 +60,40 @@ int cmd_show_index(int argc,
 			die("corrupt index file");
 		nr = n;
 	}
+
+	/* detection of hash algorithm
+	Only works for small files, i.e without large offsets */
+	if(!the_hash_algo && version == 2) {
+		struct stat st;
+		size_t file_base_size;
+		size_t table_size;
+		size_t size_rem;
+		size_t hash_size;
+
+		if(fstat(0, &st) || !S_ISREG(st.st_mode))
+			die(_("unable to detect hash from non-regular file"));
+		
+		file_base_size = 8 + (256 * 4);
+		table_size = file_base_size + (nr * 4 * 4);
+		size_rem = st.st_size - table_size;
+		hash_size = size_rem / (nr + 2);
+
+		if(hash_size == GIT_SHA1_RAWSZ) {
+			repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+		} else if(hash_size == GIT_SHA256_RAWSZ) {
+			repo_set_hash_algo(the_repository, GIT_HASH_SHA256);
+		} else {
+			die(_("unable to detect hash algorithm, "
+					"use --object-format option"));
+		}
+	}
+
+	/* Final fallback to SHA1 */
+	if(!the_hash_algo)
+		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
+	hashsz = the_hash_algo->rawsz;
+
 	if (version == 1) {
 		for (i = 0; i < nr; i++) {
 			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
-- 
2.52.0
Junio C Hamano· Jan 20, 2026, 18:07 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
Show 8 quoted lines
> @@ -71,6 +60,40 @@ int cmd_show_index(int argc,
>  			die("corrupt index file");
>  		nr = n;
>  	}
> +
> +	/* detection of hash algorithm
> +	Only works for small files, i.e without large offsets */
> +	if(!the_hash_algo && version == 2) {

We have one SP between "if" (and other syntactic elements like "while") and the open parenthesis "(". End-user controlled function names lack this SP between <word> and "(".

If we turn what is inide of this block into a separate helper function, it would allow us to structure the logic better.

	/* Returns GIT_HASH_* constants, or GIT_HASH_UNKNOWN */
	static int auto_detect_hash_function(int fd)
For example, ...
Show 8 quoted lines
> +		struct stat st;
> +		size_t file_base_size;
> +		size_t table_size;
> +		size_t size_rem;
> +		size_t hash_size;
> +
> +		if(fstat(0, &st) || !S_ISREG(st.st_mode))
> +			die(_("unable to detect hash from non-regular file"));

... this "die()" does not have to be here. We can just return GIT_HASH_UNKNOWN and let the caller fallback. Does the existing code correctly complain when the filestream is opened for a non-regular file, or it just gets totally confused?

Show 9 quoted lines
> +		file_base_size = 8 + (256 * 4);
> +		table_size = file_base_size + (nr * 4 * 4);
> +		size_rem = st.st_size - table_size;
> +		hash_size = size_rem / (nr + 2);
> +
> +		if(hash_size == GIT_SHA1_RAWSZ) {
> +			repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> +		} else if(hash_size == GIT_SHA256_RAWSZ) {
> +			repo_set_hash_algo(the_repository, GIT_HASH_SHA256);

And instead of calling repo_set_hash_algo(), just return the constants so that the caller can handle it. And

> +		} else {
> +			die(_("unable to detect hash algorithm, "
> +					"use --object-format option"));

... this also can return GIT_HASH_UNKNOWN, without complaining anything.

> +		}
> +	}

So, instead of inserting all of the above lines in cmd_show_index(), we'd have something like the following ...

	hash_func = auto_detect_hash_function(0);
	if (hash_func == GIT_HASH_UNKNOWN) {
		warning(_("assuming SHA-1; use --object-format to override"));
		hash_func = GIT_HASH_SHA1;
	}
	repo_set_hash_algo(the_repository, hash_func);
        hashsz = the_hash_algo->rawsz;
... there.

By the way, what happens if we find SHA-256 also broken and end up choosing another hash function that is 256-bit wide in the next hash revamp?

Thanks.
Show 10 quoted lines
> +
> +	/* Final fallback to SHA1 */
> +	if(!the_hash_algo)
> +		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> +
> +	hashsz = the_hash_algo->rawsz;
> +
>  	if (version == 1) {
>  		for (i = 0; i < nr; i++) {
>  			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
Patrick Steinhardt· Jan 21, 2026, 08:09 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:
> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,
[snip]
> By the way, what happens if we find SHA-256 also broken and end up
> choosing another hash function that is 256-bit wide in the next hash
> revamp?

Yeah, agreed. The index unfortunately does not carry sufficient info to clearly identify the hash function that is in use, and second-guessing via the hash length doesn't really seem like a sensible solution to me. If we cannot tell for sure what the hash is, then we should rather ask the user to specify the object format. And in fact we already do that, as we have the `--object-format=` option for git-show-index(1).

I think if we wanted to fix properly this we should rather introduce index v5 with a header that encodes the hash used by it. Like that we wouldn't have to guess anymore. Whether the hassle is worth it might be a different question though.

Patrick
Shreyansh Paliwal· Jan 21, 2026, 10:31 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

Show 14 quoted lines
> On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:
> > Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> > > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,
> [snip]
> > By the way, what happens if we find SHA-256 also broken and end up
> > choosing another hash function that is 256-bit wide in the next hash
> > revamp?
> 
> Yeah, agreed. The index unfortunately does not carry sufficient info to
> clearly identify the hash function that is in use, and second-guessing
> via the hash length doesn't really seem like a sensible solution to me.
> If we cannot tell for sure what the hash is, then we should rather ask
> the user to specify the object format. And in fact we already do that,
> as we have the `--object-format=` option for git-show-index(1).

Yes this is exactly why I was peculiar about this patch and the TODO comment, also why I sent it out as an RFC.

I initially assumed that in the near future we’re unlikely to move away from SHA-256 to another hash, but I agree that relying on hash length is still a heuristic that won't be a good approach in the long term as well as it creates ambiguity in the large files containing 64-bit offsets.

So should we drop this thought entirely and just make sure that if git show-index is run outside a repo, it should throw an error asking the the user to use --object-format option rather than silently falling back to SHA-1 which is the current approach.

> I think if we wanted to fix properly this we should rather introduce
> index v5 with a header that encodes the hash used by it. Like that we
> wouldn't have to guess anymore. Whether the hassle is worth it might be
> a different question though.

Yes, I agree that the best fix for long term would be an index that contains header encoded with hash, but I guess it would require many changes in the whole pack index flow.

Best, Shreyansh

Patrick Steinhardt· Jan 23, 2026, 07:22 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

On Wed, Jan 21, 2026 at 04:01:47PM +0530, Shreyansh Paliwal wrote:
Show 29 quoted lines
> > On Tue, Jan 20, 2026 at 10:07:42AM -0800, Junio C Hamano wrote:
> > > Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> > > > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,
> > [snip]
> > > By the way, what happens if we find SHA-256 also broken and end up
> > > choosing another hash function that is 256-bit wide in the next hash
> > > revamp?
> > 
> > Yeah, agreed. The index unfortunately does not carry sufficient info to
> > clearly identify the hash function that is in use, and second-guessing
> > via the hash length doesn't really seem like a sensible solution to me.
> > If we cannot tell for sure what the hash is, then we should rather ask
> > the user to specify the object format. And in fact we already do that,
> > as we have the `--object-format=` option for git-show-index(1).
> 
> Yes this is exactly why I was peculiar about this patch and the
> TODO comment, also why I sent it out as an RFC.
> 
> I initially assumed that in the near future we’re unlikely to move away
> from SHA-256 to another hash, but I agree that relying
> on hash length is still a heuristic that won't be a good approach
> in the long term as well as it creates ambiguity in the large files
> containing 64-bit offsets.
> 
> So should we drop this thought entirely and just make sure
> that if git show-index is run outside a repo,
> it should throw an error asking the the user
> to use --object-format option rather than silently
> falling back to SHA-1 which is the current approach.

That would be a regression for users that currently _can_ run git-show-index(1) outside of a repository with a SHA-1 based index. It's not going to be a common use case, but I wouldn't be surprised if there was at least one user out there that we'd break with such a change.

Patrick
Shreyansh Paliwal· Jan 23, 2026, 16:08 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

> That would be a regression for users that currently _can_ run
> git-show-index(1) outside of a repository with a SHA-1 based index. It's
> not going to be a common use case, but I wouldn't be surprised if there
> was at least one user out there that we'd break with such a change.

That makes sense, but relying on a silent SHA-1 fallback purely because we are outside of a repository still feels a bit ambiguous to me. It works today mostly because SHA-1 has historically been the default, but if in future git introduces additional hash functions or if SHA-256 indexes become more relevant to this particular usage.

Though, I think based on the discussion so far, we can only show a warning like this along with the SHA-1 fallback like this,

    warning(_("assuming SHA-1; use --object-format to override"));

Do you think if this would be appropriate, or if anything better can be done to handle this or is it just better to leave the behavior as-is. Let me know :)

Best, Shreyansh

brian m. carlson· Jan 23, 2026, 20:29 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

On 2026-01-21 at 08:09:11, Patrick Steinhardt wrote:
> I think if we wanted to fix properly this we should rather introduce
> index v5 with a header that encodes the hash used by it. Like that we
> wouldn't have to guess anymore. Whether the hassle is worth it might be
> a different question though.

Index v3, which will be used during interoperability, will encode the hash algorithm and can be used for single-hash implementations as well as multi-hash implementations.

There's an implementation in my `sha256-interop` branch at https://github.com/bk2204/git.git and we could simply enable it by default at some point in the future.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Shreyansh Paliwal· Jan 21, 2026, 10:28 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/3] show-index: implement automatic hash detection

Show 15 quoted lines
> Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> 
> > @@ -71,6 +60,40 @@ int cmd_show_index(int argc,
> >			die("corrupt index file");
> >		nr = n;
> >	}
> > +
> > +	/* detection of hash algorithm
> > +	Only works for small files, i.e without large offsets */
> > +	if(!the_hash_algo && version == 2) {
> 
> We have one SP between "if" (and other syntactic elements like
> "while") and the open parenthesis "(".  End-user controlled function
> names lack this SP between <word> and "(".
> 
Got it, I will keep this in mind.
Show 16 quoted lines
> For example, ...
> 
> > +		struct stat st;
> > +		size_t file_base_size;
> > +		size_t table_size;
> > +		size_t size_rem;
> > +		size_t hash_size;
> > +
> > +		if(fstat(0, &st) || !S_ISREG(st.st_mode))
> > +			die(_("unable to detect hash from non-regular file"));
> 
> ... this "die()" does not have to be here.  We can just return
> GIT_HASH_UNKNOWN and let the caller fallback.  Does the existing
> code correctly complain when the filestream is opened for a
> non-regular file, or it just gets totally confused?
> 

I believe there is no explicit check for irregular files in the current implementation.

Show 36 quoted lines
> > +		file_base_size = 8 + (256 * 4);
> > +		table_size = file_base_size + (nr * 4 * 4);
> > +		size_rem = st.st_size - table_size;
> > +		hash_size = size_rem / (nr + 2);
> > +
> > +		if(hash_size == GIT_SHA1_RAWSZ) {
> > +			repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> > +		} else if(hash_size == GIT_SHA256_RAWSZ) {
> > +			repo_set_hash_algo(the_repository, GIT_HASH_SHA256);
> 
> And instead of calling repo_set_hash_algo(), just return the
> constants so that the caller can handle it.  And 
> 
> > +		} else {
> > +			die(_("unable to detect hash algorithm, "
> > +					"use --object-format option"));
> 
> ... this also can return GIT_HASH_UNKNOWN, without complaining
> anything.
> 
> > +		}
> > +	}
> 
> So, instead of inserting all of the above lines in cmd_show_index(),
> we'd have something like the following ...
> 
> 	hash_func = auto_detect_hash_function(0);
> 	if (hash_func == GIT_HASH_UNKNOWN) {
> 		warning(_("assuming SHA-1; use --object-format to override"));
> 		hash_func = GIT_HASH_SHA1;
> 	}
> 	repo_set_hash_algo(the_repository, hash_func);
>         hashsz = the_hash_algo->rawsz;
> 
> ... there.
> 

Yes this is surely a much better approach than before, I will implement this as a seperate helper function in v2 if we go ahead with the detection logic.

Shreyansh Paliwal· Jan 20, 2026, 14:05 UTC · re: Shreyansh Paliwal · lore

[PATCH 2/3] show-index: use gettext wrapping in error messages

Previously, error messages were passed directly to die(). As suggested by the Git coding guidelines, wrap user-visible strings in the _() macro so they can be translated.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
Show changes to builtin/show-index.c +11 −11
diff --git a/builtin/show-index.c b/builtin/show-index.c
index be62edc57b..a9c2f18b73 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -41,23 +41,23 @@ int cmd_show_index(int argc,
 	}
 
 	if (fread(top_index, 2 * 4, 1, stdin) != 1)
-		die("unable to read header");
+		die(_("unable to read header"));
 	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
 		version = ntohl(top_index[1]);
 		if (version < 2 || version > 2)
-			die("unknown index version");
+			die(_("unknown index version"));
 		if (fread(top_index, 256 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	} else {
 		version = 1;
 		if (fread(&top_index[2], 254 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	}
 	nr = 0;
 	for (i = 0; i < 256; i++) {
 		unsigned n = ntohl(top_index[i]);
 		if (n < nr)
-			die("corrupt index file");
+			die(_("corrupt index file"));
 		nr = n;
 	}
 
@@ -99,7 +99,7 @@ int cmd_show_index(int argc,
 			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
 
 			if (fread(entry, 4 + hashsz, 1, stdin) != 1)
-				die("unable to read entry %u/%u", i, nr);
+				die(_("unable to read entry %u/%u"), i, nr);
 			offset = ntohl(entry[0]);
 			printf("%u %s\n", offset, hash_to_hex((void *)(entry+1)));
 		}
@@ -113,15 +113,15 @@ int cmd_show_index(int argc,
 		ALLOC_ARRAY(entries, nr);
 		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);
+				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);
+				die(_("unable to read crc %u/%u"), i, nr);
 		for (i = 0; i < nr; i++)
 			if (fread(&entries[i].off, 4, 1, stdin) != 1)
-				die("unable to read 32b offset %u/%u", i, nr);
+				die(_("unable to read 32b offset %u/%u"), i, nr);
 		for (i = 0; i < nr; i++) {
 			uint64_t offset;
 			uint32_t off = ntohl(entries[i].off);
@@ -130,9 +130,9 @@ int cmd_show_index(int argc,
 			} else {
 				uint32_t off64[2];
 				if ((off & 0x7fffffff) != off64_nr)
-					die("inconsistent 64b offset index");
+					die(_("inconsistent 64b offset index"));
 				if (fread(off64, 8, 1, stdin) != 1)
-					die("unable to read 64b offset %u", off64_nr);
+					die(_("unable to read 64b offset %u"), off64_nr);
 				offset = (((uint64_t)ntohl(off64[0])) << 32) |
 						     ntohl(off64[1]);
 				off64_nr++;
-- 
2.52.0
Shreyansh Paliwal· Jan 20, 2026, 14:05 UTC · re: Shreyansh Paliwal · lore

[PATCH 3/3] show-index: remove global state variables

As Git is in the process of removing global state, this function still relies on the global variables, the_repository and the_hash_algo.

Remove the associated macro and the UNUSED attribute from the repo parameter, and replace all uses of the_repository and the_hash_algo with repo and repo->hash_algo, respectively.

This modernizes git show-index and makes it more compatible.
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
Show changes to builtin/show-index.c +9 −10
diff --git a/builtin/show-index.c b/builtin/show-index.c
index a9c2f18b73..96adae14c0 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "builtin.h"
@@ -16,7 +15,7 @@ static const char *const show_index_usage[] = {
 int cmd_show_index(int argc,
 		   const char **argv,
 		   const char *prefix,
-		   struct repository *repo UNUSED)
+		   struct repository *repo)
 {
 	int i;
 	unsigned nr;
@@ -37,7 +36,7 @@ int cmd_show_index(int argc,
 		hash_algo = hash_algo_by_name(hash_name);
 		if (hash_algo == GIT_HASH_UNKNOWN)
 			die(_("Unknown hash algorithm"));
-		repo_set_hash_algo(the_repository, hash_algo);
+		repo_set_hash_algo(repo, hash_algo);
 	}
 
 	if (fread(top_index, 2 * 4, 1, stdin) != 1)
@@ -63,7 +62,7 @@ int cmd_show_index(int argc,
 
 	/* detection of hash algorithm
 	Only works for small files, i.e without large offsets */
-	if(!the_hash_algo && version == 2) {
+	if(!repo->hash_algo && version == 2) {
 		struct stat st;
 		size_t file_base_size;
 		size_t table_size;
@@ -79,9 +78,9 @@ int cmd_show_index(int argc,
 		hash_size = size_rem / (nr + 2);
 
 		if(hash_size == GIT_SHA1_RAWSZ) {
-			repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+			repo_set_hash_algo(repo, GIT_HASH_SHA1);
 		} else if(hash_size == GIT_SHA256_RAWSZ) {
-			repo_set_hash_algo(the_repository, GIT_HASH_SHA256);
+			repo_set_hash_algo(repo, GIT_HASH_SHA256);
 		} else {
 			die(_("unable to detect hash algorithm, "
 					"use --object-format option"));
@@ -89,10 +88,10 @@ int cmd_show_index(int argc,
 	}
 
 	/* Final fallback to SHA1 */
-	if(!the_hash_algo)
-		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+	if(!repo->hash_algo)
+		repo_set_hash_algo(repo, GIT_HASH_SHA1);
 
-	hashsz = the_hash_algo->rawsz;
+	hashsz = repo->hash_algo->rawsz;
 
 	if (version == 1) {
 		for (i = 0; i < nr; i++) {
@@ -114,7 +113,7 @@ int cmd_show_index(int argc,
 		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);
+			entries[i].oid.algo = hash_algo_by_ptr(repo->hash_algo);
 		}
 		for (i = 0; i < nr; i++)
 			if (fread(&entries[i].crc, 4, 1, stdin) != 1)
-- 
2.52.0
Phillip Wood· Jan 21, 2026, 10:39 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH 3/3] show-index: remove global state variables

On 20/01/2026 14:05, Shreyansh Paliwal wrote:
Show 7 quoted lines
> As Git is in the process of removing global state,
> this function still relies on the global variables,
> the_repository and the_hash_algo.
> 
> Remove the associated macro and the UNUSED attribute from
> the repo parameter, and replace all uses of the_repository and
> the_hash_algo with repo and repo->hash_algo, respectively.

I don't think that is a good idea because repo will be NULL outside of a repository. For a lot of commands that does not matter because they require a repository to run but judging from the first patch in this series this command is supposed to be able to run outside a repository.

I'm increasingly of the opinion that adding a repository argument to the builtin commands was a mistake as they all just use a single repository so using "the_repository" seems perfectly reasonable. It leads to problems like the segfault in this patch and takes attention away from the much more useful task of moving our library code away from using "the_repository". If you're interested in contributing to that effort then there are a number of instances of "the_repository" in wt-status.c that can be trivially replaced by the repository instance in "struct wt_status" or the repository passed to the function. I'm not sure how easy it is to remove them all - you might need to change the code to pass a repository instance down the call chain in a few cases but there are certainly quite a few that can be easily and usefully cleaned up.

Thanks
Phillip
Show 78 quoted lines
> This modernizes git show-index and makes it more compatible.
> 
> Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
> ---
>   builtin/show-index.c | 19 +++++++++----------
>   1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/builtin/show-index.c b/builtin/show-index.c
> index a9c2f18b73..96adae14c0 100644
> --- a/builtin/show-index.c
> +++ b/builtin/show-index.c
> @@ -1,4 +1,3 @@
> -#define USE_THE_REPOSITORY_VARIABLE
>   #define DISABLE_SIGN_COMPARE_WARNINGS
>   
>   #include "builtin.h"
> @@ -16,7 +15,7 @@ static const char *const show_index_usage[] = {
>   int cmd_show_index(int argc,
>   		   const char **argv,
>   		   const char *prefix,
> -		   struct repository *repo UNUSED)
> +		   struct repository *repo)
>   {
>   	int i;
>   	unsigned nr;
> @@ -37,7 +36,7 @@ int cmd_show_index(int argc,
>   		hash_algo = hash_algo_by_name(hash_name);
>   		if (hash_algo == GIT_HASH_UNKNOWN)
>   			die(_("Unknown hash algorithm"));
> -		repo_set_hash_algo(the_repository, hash_algo);
> +		repo_set_hash_algo(repo, hash_algo);
>   	}
>   
>   	if (fread(top_index, 2 * 4, 1, stdin) != 1)
> @@ -63,7 +62,7 @@ int cmd_show_index(int argc,
>   
>   	/* detection of hash algorithm
>   	Only works for small files, i.e without large offsets */
> -	if(!the_hash_algo && version == 2) {
> +	if(!repo->hash_algo && version == 2) {
>   		struct stat st;
>   		size_t file_base_size;
>   		size_t table_size;
> @@ -79,9 +78,9 @@ int cmd_show_index(int argc,
>   		hash_size = size_rem / (nr + 2);
>   
>   		if(hash_size == GIT_SHA1_RAWSZ) {
> -			repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> +			repo_set_hash_algo(repo, GIT_HASH_SHA1);
>   		} else if(hash_size == GIT_SHA256_RAWSZ) {
> -			repo_set_hash_algo(the_repository, GIT_HASH_SHA256);
> +			repo_set_hash_algo(repo, GIT_HASH_SHA256);
>   		} else {
>   			die(_("unable to detect hash algorithm, "
>   					"use --object-format option"));
> @@ -89,10 +88,10 @@ int cmd_show_index(int argc,
>   	}
>   
>   	/* Final fallback to SHA1 */
> -	if(!the_hash_algo)
> -		repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
> +	if(!repo->hash_algo)
> +		repo_set_hash_algo(repo, GIT_HASH_SHA1);
>   
> -	hashsz = the_hash_algo->rawsz;
> +	hashsz = repo->hash_algo->rawsz;
>   
>   	if (version == 1) {
>   		for (i = 0; i < nr; i++) {
> @@ -114,7 +113,7 @@ int cmd_show_index(int argc,
>   		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);
> +			entries[i].oid.algo = hash_algo_by_ptr(repo->hash_algo);
>   		}
>   		for (i = 0; i < nr; i++)
>   			if (fread(&entries[i].crc, 4, 1, stdin) != 1)
Shreyansh Paliwal· Jan 21, 2026, 12:47 UTC · re: Phillip Wood · lore

Re: [PATCH 3/3] show-index: remove global state variables

Show 19 quoted lines
> On 20/01/2026 14:05, Shreyansh Paliwal wrote:
> > As Git is in the process of removing global state,
> > this function still relies on the global variables,
> > the_repository and the_hash_algo.
> > 
> > Remove the associated macro and the UNUSED attribute from
> > the repo parameter, and replace all uses of the_repository and
> > the_hash_algo with repo and repo->hash_algo, respectively.
> 
> I don't think that is a good idea because repo will be NULL outside of a 
> repository. For a lot of commands that does not matter because they 
> require a repository to run but judging from the first patch in this 
> series this command is supposed to be able to run outside a repository.
> 
> I'm increasingly of the opinion that adding a repository argument to the 
> builtin commands was a mistake as they all just use a single repository 
> so using "the_repository" seems perfectly reasonable. It leads to 
> problems like the segfault in this patch and takes attention away from 
> the much more useful task of moving our library code away from using 

That makes a lot of sense, especially for the commands which are meant to run outside the repo as well. In hindsight, the NULL repo issue and the segfault risk should have been obvious to me, particularly given that I started by creating the hash detection for no-repo cases :)

Anyways I will drop this patch in the next version.
Show 7 quoted lines
> "the_repository". If you're interested in contributing to that effort 
> then there are a number of instances of "the_repository" in wt-status.c 
> that can be trivially replaced by the repository instance in "struct 
> wt_status" or the repository passed to the function. I'm not sure how 
> easy it is to remove them all - you might need to change the code to 
> pass a repository instance down the call chain in a few cases but there 
> are certainly quite a few that can be easily and usefully cleaned up.

Yes sure, I will take a look and see where I can contribute in wt-status.c, towards reducing global-state usage.

Best, Shreyansh

Junio C Hamano· Jan 21, 2026, 17:23 UTC · re: Phillip Wood · lore

Re: [PATCH 3/3] show-index: remove global state variables

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 6 quoted lines
> I'm increasingly of the opinion that adding a repository argument to the 
> builtin commands was a mistake as they all just use a single repository 
> so using "the_repository" seems perfectly reasonable. It leads to 
> problems like the segfault in this patch and takes attention away from 
> the much more useful task of moving our library code away from using 
> "the_repository".
Very well said ;-)
Shreyansh Paliwal· Jan 29, 2026, 15:36 UTC · re: Shreyansh Paliwal · lore

[PATCH] show-index: warn when falling back to SHA-1 outside a repository

When 'git show-index' is run outside of a repository and no hashing algorithm is specified via --object-format, it silently falls back to SHA-1, relying on the historical default.

This works for existing SHA-1 based index files, but the behavior can be ambiguous and confusing when the input index file uses a different hash algorithm, such as SHA-256.

Add a warning when this fallback happens to make the assumption explicit and to guide users toward using --object-format when needed.

Additionally, wrap user-facing die() messages with _() so they can be translated via gettext.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
Show changes to builtin/show-index.c +18 −15
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 2c3e2940ce..14147c2ff2 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -36,39 +36,42 @@ int cmd_show_index(int argc,
 	if (hash_name) {
 		hash_algo = hash_algo_by_name(hash_name);
 		if (hash_algo == GIT_HASH_UNKNOWN)
-			die(_("Unknown hash algorithm"));
+			die(_("unknown hash algorithm"));
 		repo_set_hash_algo(the_repository, hash_algo);
 	}
 
 	/*
 	 * Fallback to SHA1 if we are running outside of a repository.
 	 *
-	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
-	 *       the index file passed in and use that instead.
+	 * TODO: If a future implementation of index file version encodes the hash
+	 *       algorithm in its header, enable show-index to infer it from the
+	 *       header rather than relying on repository context or a default fallback.
 	 */
-	if (!the_hash_algo)
+	if (!the_hash_algo) {
+		warning(_("assuming SHA-1; use --object-format to override"));
 		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
+	}
 
 	hashsz = the_hash_algo->rawsz;
 
 	if (fread(top_index, 2 * 4, 1, stdin) != 1)
-		die("unable to read header");
+		die(_("unable to read header"));
 	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
 		version = ntohl(top_index[1]);
 		if (version < 2 || version > 2)
-			die("unknown index version");
+			die(_("unknown index version"));
 		if (fread(top_index, 256 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	} else {
 		version = 1;
 		if (fread(&top_index[2], 254 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	}
 	nr = 0;
 	for (i = 0; i < 256; i++) {
 		unsigned n = ntohl(top_index[i]);
 		if (n < nr)
-			die("corrupt index file");
+			die(_("corrupt index file"));
 		nr = n;
 	}
 	if (version == 1) {
@@ -76,7 +79,7 @@ int cmd_show_index(int argc,
 			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
 
 			if (fread(entry, 4 + hashsz, 1, stdin) != 1)
-				die("unable to read entry %u/%u", i, nr);
+				die(_("unable to read entry %u/%u"), i, nr);
 			offset = ntohl(entry[0]);
 			printf("%u %s\n", offset, hash_to_hex((void *)(entry+1)));
 		}
@@ -90,15 +93,15 @@ int cmd_show_index(int argc,
 		ALLOC_ARRAY(entries, nr);
 		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);
+				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);
+				die(_("unable to read crc %u/%u"), i, nr);
 		for (i = 0; i < nr; i++)
 			if (fread(&entries[i].off, 4, 1, stdin) != 1)
-				die("unable to read 32b offset %u/%u", i, nr);
+				die(_("unable to read 32b offset %u/%u"), i, nr);
 		for (i = 0; i < nr; i++) {
 			uint64_t offset;
 			uint32_t off = ntohl(entries[i].off);
@@ -107,9 +110,9 @@ int cmd_show_index(int argc,
 			} else {
 				uint32_t off64[2];
 				if ((off & 0x7fffffff) != off64_nr)
-					die("inconsistent 64b offset index");
+					die(_("inconsistent 64b offset index"));
 				if (fread(off64, 8, 1, stdin) != 1)
-					die("unable to read 64b offset %u", off64_nr);
+					die(_("unable to read 64b offset %u"), off64_nr);
 				offset = (((uint64_t)ntohl(off64[0])) << 32) |
 						     ntohl(off64[1]);
 				off64_nr++;
-- 
2.52.0
Junio C Hamano· Jan 29, 2026, 23:03 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
Show 15 quoted lines
> When 'git show-index' is run outside of a
> repository and no hashing algorithm is
> specified via --object-format, it silently
> falls back to SHA-1, relying on the
> historical default.
>
> This works for existing SHA-1 based
> index files, but the behavior can be ambiguous
> and confusing when the input index file uses a
> different hash algorithm, such as SHA-256.
>
> Add a warning when this fallback happens
> to make the assumption explicit and to
> guide users toward using --object-format
> when needed.

Line wrapping at 50 columns certainly makes the lines narrower than 80 column limit, but let's not go to the extreme. We recommend that the lines are still less than 80-columns after being quoted a few times in e-mail exchange (as you can see, I lost 2 columns by quoting once in the above), which means that around ~70 columns is the practical fill-column.

> Additionally, wrap user-facing die() messages
> with _() so they can be translated via gettext.

It is somewhat distracting that such "while at it" changes dominate this ~100-line patch, whose "primary change" is a mere three lines we can see here:

Show 5 quoted lines
> -	if (!the_hash_algo)
> +	if (!the_hash_algo) {
> +		warning(_("assuming SHA-1; use --object-format to override"));
>  		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
> +	}

Can we push the "while at it" message changes to a separate patch, a preparatory clean-up, on top of which another primary patch adds the above warning? Alternatively, have the primary patch that adds the above warning and does nothing else, followed by a post clean-up patch to tweak the existing error messages?

Thanks.
Shreyansh Paliwal· Jan 30, 2026, 08:59 UTC · re: Junio C Hamano · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

Show 22 quoted lines
> > When 'git show-index' is run outside of a
> > repository and no hashing algorithm is
> > specified via --object-format, it silently
> > falls back to SHA-1, relying on the
> > historical default.
> >
> > This works for existing SHA-1 based
> > index files, but the behavior can be ambiguous
> > and confusing when the input index file uses a
> > different hash algorithm, such as SHA-256.
> >
> > Add a warning when this fallback happens
> > to make the assumption explicit and to
> > guide users toward using --object-format
> > when needed.
> 
> Line wrapping at 50 columns certainly makes the lines narrower than
> 80 column limit, but let's not go to the extreme.  We recommend that
> the lines are still less than 80-columns after being quoted a few
> times in e-mail exchange (as you can see, I lost 2 columns by
> quoting once in the above), which means that around ~70 columns is
> the practical fill-column.
Understood. I Will make sure to keep message wrapping around ~70 columns.
Show 19 quoted lines
> > Additionally, wrap user-facing die() messages
> > with _() so they can be translated via gettext.
> 
> It is somewhat distracting that such "while at it" changes dominate
> this ~100-line patch, whose "primary change" is a mere three lines
> we can see here: 
> 
> > -	if (!the_hash_algo)
> > +	if (!the_hash_algo) {
> > +		warning(_("assuming SHA-1; use --object-format to override"));
> >		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
> > +	}
> 
> 
> Can we push the "while at it" message changes to a separate patch, a
> preparatory clean-up, on top of which another primary patch adds the
> above warning?  Alternatively, have the primary patch that adds the
> above warning and does nothing else, followed by a post clean-up patch
> to tweak the existing error messages?

Yes, agreed. I’ll split the changes into separate patches again, as in the original RFC series, and send a v2.

Best, Shreyansh

brian m. carlson· Jan 29, 2026, 23:12 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:
Show 13 quoted lines
>  	/*
>  	 * Fallback to SHA1 if we are running outside of a repository.
>  	 *
> -	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
> -	 *       the index file passed in and use that instead.
> +	 * TODO: If a future implementation of index file version encodes the hash
> +	 *       algorithm in its header, enable show-index to infer it from the
> +	 *       header rather than relying on repository context or a default fallback.
>  	 */
> -	if (!the_hash_algo)
> +	if (!the_hash_algo) {
> +		warning(_("assuming SHA-1; use --object-format to override"));
>  		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);

If we're going to start producing a warning, can we also learn a `--quiet` option to silence it?

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Shreyansh Paliwal· Jan 30, 2026, 09:04 UTC · re: brian m. carlson · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

Show 17 quoted lines
> On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:
> >	/*
> >	 * Fallback to SHA1 if we are running outside of a repository.
> >	 *
> > -	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
> > -	 *       the index file passed in and use that instead.
> > +	 * TODO: If a future implementation of index file version encodes the hash
> > +	 *       algorithm in its header, enable show-index to infer it from the
> > +	 *       header rather than relying on repository context or a default fallback.
> >	 */
> > -	if (!the_hash_algo)
> > +	if (!the_hash_algo) {
> > +		warning(_("assuming SHA-1; use --object-format to override"));
> >		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
> 
> If we're going to start producing a warning, can we also learn a
> `--quiet` option to silence it?
Hi,

That is a good point. However, the warning is only shown for a particular usecase: when 'git show-index' is run outside of a repository and --object-format is not specified. Given that narrow scope, I’m wondering whether adding a dedicated --quiet option for only this warning would be worthwhile.

Let me know what you think :)

Best, Shreyansh

Patrick Steinhardt· Jan 30, 2026, 13:40 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

On Fri, Jan 30, 2026 at 02:34:53PM +0530, Shreyansh Paliwal wrote:
Show 27 quoted lines
> > On 2026-01-29 at 15:36:55, Shreyansh Paliwal wrote:
> > >	/*
> > >	 * Fallback to SHA1 if we are running outside of a repository.
> > >	 *
> > > -	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
> > > -	 *       the index file passed in and use that instead.
> > > +	 * TODO: If a future implementation of index file version encodes the hash
> > > +	 *       algorithm in its header, enable show-index to infer it from the
> > > +	 *       header rather than relying on repository context or a default fallback.
> > >	 */
> > > -	if (!the_hash_algo)
> > > +	if (!the_hash_algo) {
> > > +		warning(_("assuming SHA-1; use --object-format to override"));
> > >		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
> > 
> > If we're going to start producing a warning, can we also learn a
> > `--quiet` option to silence it?
> 
> Hi,
> 
> That is a good point.
> However, the warning is only shown for a particular usecase: when 
> 'git show-index' is run outside of a repository and --object-format
> is not specified. Given that narrow scope, I’m wondering whether
> adding a dedicated --quiet option for only this warning would be worthwhile.
> 
> Let me know what you think :)

I also wonder whether "--quiet" might be a bit _too_ generic in this context. I would rather want to use this flag for something that you actually have a good reason to silence, instead of only for a warning.

In theory, the user already has the ability to silence the warning: they can simply pass "--object-format=sha256". If you think that's not enough I'd buid on top of our `advice_if_enabled()` infra, so that the warning can be globally disabled by setting a config option.

Thanks!
Patrick
Junio C Hamano· Jan 30, 2026, 17:01 UTC · re: Patrick Steinhardt · lore

Re: [PATCH] show-index: warn when falling back to SHA-1 outside a repository

Patrick Steinhardt <ps@pks.im> writes:
Show 8 quoted lines
> I also wonder whether "--quiet" might be a bit _too_ generic in this
> context. I would rather want to use this flag for something that you
> actually have a good reason to silence, instead of only for a warning.
>
> In theory, the user already has the ability to silence the warning: they
> can simply pass "--object-format=sha256". If you think that's not enough
> I'd buid on top of our `advice_if_enabled()` infra, so that the warning
> can be globally disabled by setting a config option.

I like the "use --object-format then you would never see this warning" very much. It is possible that we may want to squelch any and all warning and error messages, not limited to this one, in which case it is an option to add "--quiet" to the command, but I somehow feel that it is outside the topic of this change.

Thanks.
Shreyansh Paliwal· Jan 30, 2026, 15:31 UTC · re: Shreyansh Paliwal · lore

[PATCH V2 0/2] show-index: add warning and wrap error messages with gettext

'git show-index' relies on implicit assumption in the absence of repository context to fall back to SHA-1 as the hashing algorithm.

patch 1/2: add a warning when this fallback happens.

patch 2/2: cleanup by adding gettext wrapping to all user-facing error messages in show-index.c.

Shreyansh Paliwal (2):
  show-index: warn when falling back to SHA-1 outside a repository
  show-index: use gettext wrapping in user facing error messages
 builtin/show-index.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
---
Changes in V2:
 - Split the original patch into two separate patches for better
    clarity and distinction.
 - Improved line wrapping to around ~70 columns.
-- 
2.52.0
Shreyansh Paliwal· Jan 30, 2026, 15:31 UTC · re: Shreyansh Paliwal · lore

[PATCH V2 1/2] show-index: warn when falling back to SHA-1 outside a repository

When 'git show-index' is run outside of a repository and no hashing algorithm is specified via --object-format, it silently falls back to SHA-1, relying on the historical default.

This works for existing SHA-1 based index files, but the behavior can be ambiguous and confusing when the input index file uses a different hash algorithm, such as SHA-256.

Add a warning when this fallback happens to make the assumption explicit and to guide users toward using --object-format when needed.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Show changes to builtin/show-index.c +6 −3
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 2c3e2940ce..45795da2da 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -43,11 +43,14 @@ int cmd_show_index(int argc,
 	/*
 	 * Fallback to SHA1 if we are running outside of a repository.
 	 *
-	 * TODO: Figure out and implement a way to detect the hash algorithm in use by the
-	 *       the index file passed in and use that instead.
+	 * TODO: If a future implementation of index file version encodes the hash
+	 *       algorithm in its header, enable show-index to infer it from the
+	 *       header rather than relying on repository context or a default fallback.
 	 */
-	if (!the_hash_algo)
+	if (!the_hash_algo) {
+		warning(_("assuming SHA-1; use --object-format to override"));
 		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
+	}
 
 	hashsz = the_hash_algo->rawsz;
 
-- 
2.52.0
Shreyansh Paliwal· Jan 30, 2026, 15:31 UTC · re: Shreyansh Paliwal · lore

[PATCH V2 2/2] show-index: use gettext wrapping in user facing error messages

Multiple 'die()' calls in show-index.c use literal strings directly.

Wrap all user-facing 'die()' messages with '_()' so they can be translated via gettext, this ensures better support for users.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 builtin/show-index.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
Show changes to builtin/show-index.c +11 −11
diff --git a/builtin/show-index.c b/builtin/show-index.c
index 45795da2da..24f0230967 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -55,23 +55,23 @@ int cmd_show_index(int argc,
 	hashsz = the_hash_algo->rawsz;
 
 	if (fread(top_index, 2 * 4, 1, stdin) != 1)
-		die("unable to read header");
+		die(_("unable to read header"));
 	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
 		version = ntohl(top_index[1]);
 		if (version < 2 || version > 2)
-			die("unknown index version");
+			die(_("unknown index version"));
 		if (fread(top_index, 256 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	} else {
 		version = 1;
 		if (fread(&top_index[2], 254 * 4, 1, stdin) != 1)
-			die("unable to read index");
+			die(_("unable to read index"));
 	}
 	nr = 0;
 	for (i = 0; i < 256; i++) {
 		unsigned n = ntohl(top_index[i]);
 		if (n < nr)
-			die("corrupt index file");
+			die(_("corrupt index file"));
 		nr = n;
 	}
 	if (version == 1) {
@@ -79,7 +79,7 @@ int cmd_show_index(int argc,
 			unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
 
 			if (fread(entry, 4 + hashsz, 1, stdin) != 1)
-				die("unable to read entry %u/%u", i, nr);
+				die(_("unable to read entry %u/%u"), i, nr);
 			offset = ntohl(entry[0]);
 			printf("%u %s\n", offset, hash_to_hex((void *)(entry+1)));
 		}
@@ -93,15 +93,15 @@ int cmd_show_index(int argc,
 		ALLOC_ARRAY(entries, nr);
 		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);
+				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);
+				die(_("unable to read crc %u/%u"), i, nr);
 		for (i = 0; i < nr; i++)
 			if (fread(&entries[i].off, 4, 1, stdin) != 1)
-				die("unable to read 32b offset %u/%u", i, nr);
+				die(_("unable to read 32b offset %u/%u"), i, nr);
 		for (i = 0; i < nr; i++) {
 			uint64_t offset;
 			uint32_t off = ntohl(entries[i].off);
@@ -110,9 +110,9 @@ int cmd_show_index(int argc,
 			} else {
 				uint32_t off64[2];
 				if ((off & 0x7fffffff) != off64_nr)
-					die("inconsistent 64b offset index");
+					die(_("inconsistent 64b offset index"));
 				if (fread(off64, 8, 1, stdin) != 1)
-					die("unable to read 64b offset %u", off64_nr);
+					die(_("unable to read 64b offset %u"), off64_nr);
 				offset = (((uint64_t)ntohl(off64[0])) << 32) |
 						     ntohl(off64[1]);
 				off64_nr++;
-- 
2.52.0
Junio C Hamano· Jan 30, 2026, 17:07 UTC · re: Shreyansh Paliwal · lore

Re: [PATCH V2 0/2] show-index: add warning and wrap error messages with gettext

Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> Changes in V2:
>  - Split the original patch into two separate patches for better
>     clarity and distinction.
>  - Improved line wrapping to around ~70 columns.
Queued.  Thanks.

← back to recent threads