All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] setup: use SHA-256 when experimental features are enabled
@ 2026-12-01  6:47 Toon Claes
  2026-12-01  7:59 ` Patrick Steinhardt
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Toon Claes @ 2026-12-01  6:47 UTC (permalink / raw)
  To: git; +Cc: brian m. carlson, Toon Claes

In 793b14e1c8 (setup: use "reftable" format when experimental features
are enabled, 2025-07-04), git-init(1) learned to create new repositories
with the reftable backend when "feature.experimental" is enabled, so
that users can test the format that is planned to become the default in
Git 3.0. The SHA-256 object format is also planned to become the default
in Git 3.0, but "feature.experimental" does not affect the object
format, so new repositories still use SHA-1.

Teach "feature.experimental" to also make SHA-256 the default object
format for new repositories. As with the ref storage format, this
default can still be overridden by setting "init.defaultObjectFormat",
setting the GIT_DEFAULT_HASH environment variable, or passing
"--object-format=".

Signed-off-by: Toon Claes <toon@iotcl.com>
---
With the release of Git 3.0 being planned, I noticed SHA-256 isn't
default-selected when "feature.experimental" is set. This small patch
fixes that.

This follows what Patrick did for the reftable backend in [1], which
made "feature.experimental" select the reftable format for new
repositories.

There is a related topic in flight, bc/setup-default-hash-algo [2],
which fixes the default hash algorithm not being applied by git-init(1)
in WITH_BREAKING_CHANGES builds. It touches the same area of setup.c,
but this patch does not depend on it and both merge cleanly together.

[1]: https://lore.kernel.org/git/20250703-pks-reftable-default-backend-v2-0-5a27e72a8c5e@pks.im/
[2]: https://lore.kernel.org/git/20261124225952.1616547-1-sandals@crustytoothpaste.net/

Laters,
Toon
---
 Documentation/config/feature.adoc |  6 ++++++
 setup.c                           | 11 +++++++----
 t/t0001-init.sh                   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/Documentation/config/feature.adoc b/Documentation/config/feature.adoc
index e258770591..57e24724b4 100644
--- a/Documentation/config/feature.adoc
+++ b/Documentation/config/feature.adoc
@@ -30,6 +30,12 @@ the reftable format for storing references. This new format solves issues with
 case-insensitive filesystems, compresses better and performs significantly
 better with many use cases. Refer to Documentation/technical/reftable.adoc for
 more information on this new storage format.
++
+* `init.defaultObjectFormat=sha256` causes newly initialized repositories to use
+the SHA-256 object format. SHA-256 is planned to become the default hash
+algorithm in Git 3.0. Note that repositories using SHA-256 cannot interoperate
+with SHA-1 repositories, so some forges and third-party tools may not support
+them yet.
 
 feature.manyFiles::
 	Enable config options that optimize for repos with many files in the
diff --git a/setup.c b/setup.c
index f9c03b6c47..d4c263d599 100644
--- a/setup.c
+++ b/setup.c
@@ -2850,13 +2850,16 @@ static int read_default_format_config(const char *key, const char *value,
 	}
 
 	/*
-	 * Enable the reftable format when "features.experimental" is enabled.
-	 * "init.defaultRefStorageFormat" takes precedence over this setting.
+	 * Enable the reftable format and the SHA-256 object format when
+	 * "features.experimental" is enabled. "init.defaultRefStorageFormat"
+	 * and "init.defaultObjectFormat" take precedence over this setting.
 	 */
 	if (!strcmp(key, "feature.experimental") &&
-	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
 	    git_config_bool(key, value)) {
-		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
+		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
+		if (cfg->hash == GIT_HASH_UNKNOWN)
+			cfg->hash = GIT_HASH_SHA256;
 		ret = 0;
 		goto out;
 	}
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 9e57a06cea..da73ae7395 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -575,6 +575,40 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
 	test_cmp expected actual
 '
 
+test_expect_success 'init with feature.experimental=true uses sha256' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git init repo
+	) &&
+	echo sha256 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'init.defaultObjectFormat overrides feature.experimental=true' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	test_config_global init.defaultObjectFormat sha1 &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git init repo
+	) &&
+	echo sha1 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'GIT_DEFAULT_HASH overrides feature.experimental=true' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	GIT_DEFAULT_HASH=sha1 git init repo &&
+	echo sha1 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success '--object-format overrides GIT_DEFAULT_HASH' '
 	test_when_finished "rm -rf repo" &&
 	GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo &&

---
base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2
change-id: 20261201-toon-init-experimental-sha256-e7c30b2ef129


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] setup: use SHA-256 when experimental features are enabled
  2026-12-01  6:47 [PATCH] setup: use SHA-256 when experimental features are enabled Toon Claes
@ 2026-12-01  7:59 ` Patrick Steinhardt
  2026-12-01  8:04   ` Patrick Steinhardt
  2026-12-02  7:02   ` Toon Claes
  2026-12-01 23:19 ` brian m. carlson
  2026-12-03 16:11 ` [PATCH v2] " Toon Claes
  2 siblings, 2 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2026-12-01  7:59 UTC (permalink / raw)
  To: Toon Claes; +Cc: git, brian m. carlson

On Tue, Dec 01, 2026 at 07:47:09AM +0100, Toon Claes wrote:
> In 793b14e1c8 (setup: use "reftable" format when experimental features
> are enabled, 2025-07-04), git-init(1) learned to create new repositories
> with the reftable backend when "feature.experimental" is enabled, so
> that users can test the format that is planned to become the default in
> Git 3.0. The SHA-256 object format is also planned to become the default
> in Git 3.0, but "feature.experimental" does not affect the object
> format, so new repositories still use SHA-1.

Huh, interesting, I thought that "feature.experimental" already did
this!

> Teach "feature.experimental" to also make SHA-256 the default object
> format for new repositories. As with the ref storage format, this
> default can still be overridden by setting "init.defaultObjectFormat",
> setting the GIT_DEFAULT_HASH environment variable, or passing
> "--object-format=".

This makes a ton of sense. Now that we're moving closer to Git 3.0 we
should make sure to give upcoming breaking changes more exposure.

> diff --git a/setup.c b/setup.c
> index f9c03b6c47..d4c263d599 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -2850,13 +2850,16 @@ static int read_default_format_config(const char *key, const char *value,
>  	}
>  
>  	/*
> -	 * Enable the reftable format when "features.experimental" is enabled.
> -	 * "init.defaultRefStorageFormat" takes precedence over this setting.
> +	 * Enable the reftable format and the SHA-256 object format when
> +	 * "features.experimental" is enabled. "init.defaultRefStorageFormat"
> +	 * and "init.defaultObjectFormat" take precedence over this setting.
>  	 */
>  	if (!strcmp(key, "feature.experimental") &&
> -	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
>  	    git_config_bool(key, value)) {
> -		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> +		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
> +			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> +		if (cfg->hash == GIT_HASH_UNKNOWN)
> +			cfg->hash = GIT_HASH_SHA256;

Looks straight-forward. And this function still knows to properly
override the hash in case "init.defaultObjectFormat" was set. Good.

> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index 9e57a06cea..da73ae7395 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -575,6 +575,40 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
>  	test_cmp expected actual
>  '
>  
> +test_expect_success 'init with feature.experimental=true uses sha256' '
> +	test_when_finished "rm -rf repo" &&
> +	test_config_global feature.experimental true &&
> +	(
> +		sane_unset GIT_DEFAULT_HASH &&
> +		git init repo
> +	) &&
> +	echo sha256 >expect &&
> +	git -C repo rev-parse --show-object-format >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'init.defaultObjectFormat overrides feature.experimental=true' '
> +	test_when_finished "rm -rf repo" &&
> +	test_config_global feature.experimental true &&
> +	test_config_global init.defaultObjectFormat sha1 &&
> +	(
> +		sane_unset GIT_DEFAULT_HASH &&
> +		git init repo
> +	) &&
> +	echo sha1 >expect &&
> +	git -C repo rev-parse --show-object-format >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'GIT_DEFAULT_HASH overrides feature.experimental=true' '
> +	test_when_finished "rm -rf repo" &&
> +	test_config_global feature.experimental true &&
> +	GIT_DEFAULT_HASH=sha1 git init repo &&
> +	echo sha1 >expect &&
> +	git -C repo rev-parse --show-object-format >actual &&
> +	test_cmp expect actual
> +'

We could also verify that "--object-format=sha256" overrides
"feature.experimental", but eventually it becomes excessive.

Another thing we might want to test is whether git-clone(1) works as
expected with "feature.experimental" set when cloning a SHA1 repo. But
I'm somewhat sure that our test suite would probably catch such an issue
if it didn't.

So overall this looks good to me, thanks!

Patrick

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] setup: use SHA-256 when experimental features are enabled
  2026-12-01  7:59 ` Patrick Steinhardt
@ 2026-12-01  8:04   ` Patrick Steinhardt
  2026-12-02  7:02   ` Toon Claes
  1 sibling, 0 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2026-12-01  8:04 UTC (permalink / raw)
  To: Toon Claes; +Cc: git, brian m. carlson

On Tue, Dec 01, 2026 at 08:59:19AM +0100, Patrick Steinhardt wrote:
> On Tue, Dec 01, 2026 at 07:47:09AM +0100, Toon Claes wrote:
> > In 793b14e1c8 (setup: use "reftable" format when experimental features
> > are enabled, 2025-07-04), git-init(1) learned to create new repositories
> > with the reftable backend when "feature.experimental" is enabled, so
> > that users can test the format that is planned to become the default in
> > Git 3.0. The SHA-256 object format is also planned to become the default
> > in Git 3.0, but "feature.experimental" does not affect the object
> > format, so new repositories still use SHA-1.
> 
> Huh, interesting, I thought that "feature.experimental" already did
> this!
> 
> > Teach "feature.experimental" to also make SHA-256 the default object
> > format for new repositories. As with the ref storage format, this
> > default can still be overridden by setting "init.defaultObjectFormat",
> > setting the GIT_DEFAULT_HASH environment variable, or passing
> > "--object-format=".
> 
> This makes a ton of sense. Now that we're moving closer to Git 3.0 we
> should make sure to give upcoming breaking changes more exposure.
> 
> > diff --git a/setup.c b/setup.c
> > index f9c03b6c47..d4c263d599 100644
> > --- a/setup.c
> > +++ b/setup.c
> > @@ -2850,13 +2850,16 @@ static int read_default_format_config(const char *key, const char *value,
> >  	}
> >  
> >  	/*
> > -	 * Enable the reftable format when "features.experimental" is enabled.
> > -	 * "init.defaultRefStorageFormat" takes precedence over this setting.
> > +	 * Enable the reftable format and the SHA-256 object format when
> > +	 * "features.experimental" is enabled. "init.defaultRefStorageFormat"
> > +	 * and "init.defaultObjectFormat" take precedence over this setting.
> >  	 */
> >  	if (!strcmp(key, "feature.experimental") &&
> > -	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
> >  	    git_config_bool(key, value)) {
> > -		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> > +		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
> > +			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> > +		if (cfg->hash == GIT_HASH_UNKNOWN)
> > +			cfg->hash = GIT_HASH_SHA256;
> 
> Looks straight-forward. And this function still knows to properly
> override the hash in case "init.defaultObjectFormat" was set. Good.
> 
> > diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> > index 9e57a06cea..da73ae7395 100755
> > --- a/t/t0001-init.sh
> > +++ b/t/t0001-init.sh
> > @@ -575,6 +575,40 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
> >  	test_cmp expected actual
> >  '
> >  
> > +test_expect_success 'init with feature.experimental=true uses sha256' '
> > +	test_when_finished "rm -rf repo" &&
> > +	test_config_global feature.experimental true &&
> > +	(
> > +		sane_unset GIT_DEFAULT_HASH &&
> > +		git init repo
> > +	) &&
> > +	echo sha256 >expect &&
> > +	git -C repo rev-parse --show-object-format >actual &&
> > +	test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'init.defaultObjectFormat overrides feature.experimental=true' '
> > +	test_when_finished "rm -rf repo" &&
> > +	test_config_global feature.experimental true &&
> > +	test_config_global init.defaultObjectFormat sha1 &&
> > +	(
> > +		sane_unset GIT_DEFAULT_HASH &&
> > +		git init repo
> > +	) &&
> > +	echo sha1 >expect &&
> > +	git -C repo rev-parse --show-object-format >actual &&
> > +	test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'GIT_DEFAULT_HASH overrides feature.experimental=true' '
> > +	test_when_finished "rm -rf repo" &&
> > +	test_config_global feature.experimental true &&
> > +	GIT_DEFAULT_HASH=sha1 git init repo &&
> > +	echo sha1 >expect &&
> > +	git -C repo rev-parse --show-object-format >actual &&
> > +	test_cmp expect actual
> > +'
> 
> We could also verify that "--object-format=sha256" overrides
> "feature.experimental", but eventually it becomes excessive.
> 
> Another thing we might want to test is whether git-clone(1) works as
> expected with "feature.experimental" set when cloning a SHA1 repo. But
> I'm somewhat sure that our test suite would probably catch such an issue
> if it didn't.
> 
> So overall this looks good to me, thanks!

Ah, one more note: this should probably land after [1], as we would
otherwise potentially reinitialize a repository with the wrong hash if
"feature.experimental" was set.

Patrick

[1]: <20261124225952.1616547-1-sandals@crustytoothpaste.net>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] setup: use SHA-256 when experimental features are enabled
  2026-12-01  6:47 [PATCH] setup: use SHA-256 when experimental features are enabled Toon Claes
  2026-12-01  7:59 ` Patrick Steinhardt
@ 2026-12-01 23:19 ` brian m. carlson
  2026-12-03 16:11 ` [PATCH v2] " Toon Claes
  2 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2026-12-01 23:19 UTC (permalink / raw)
  To: Toon Claes; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2973 bytes --]

On 2026-12-01 at 06:47:09, Toon Claes wrote:
> In 793b14e1c8 (setup: use "reftable" format when experimental features
> are enabled, 2025-07-04), git-init(1) learned to create new repositories
> with the reftable backend when "feature.experimental" is enabled, so
> that users can test the format that is planned to become the default in
> Git 3.0. The SHA-256 object format is also planned to become the default
> in Git 3.0, but "feature.experimental" does not affect the object
> format, so new repositories still use SHA-1.
> 
> Teach "feature.experimental" to also make SHA-256 the default object
> format for new repositories. As with the ref storage format, this
> default can still be overridden by setting "init.defaultObjectFormat",
> setting the GIT_DEFAULT_HASH environment variable, or passing
> "--object-format=".
> 
> Signed-off-by: Toon Claes <toon@iotcl.com>
> ---
> With the release of Git 3.0 being planned, I noticed SHA-256 isn't
> default-selected when "feature.experimental" is set. This small patch
> fixes that.
> 
> This follows what Patrick did for the reftable backend in [1], which
> made "feature.experimental" select the reftable format for new
> repositories.
> 
> There is a related topic in flight, bc/setup-default-hash-algo [2],
> which fixes the default hash algorithm not being applied by git-init(1)
> in WITH_BREAKING_CHANGES builds. It touches the same area of setup.c,
> but this patch does not depend on it and both merge cleanly together.

This seems like a sensible patch and a sensible default.  It looks good
to me.

> diff --git a/setup.c b/setup.c
> index f9c03b6c47..d4c263d599 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -2850,13 +2850,16 @@ static int read_default_format_config(const char *key, const char *value,
>  	}
>  
>  	/*
> -	 * Enable the reftable format when "features.experimental" is enabled.
> -	 * "init.defaultRefStorageFormat" takes precedence over this setting.
> +	 * Enable the reftable format and the SHA-256 object format when
> +	 * "features.experimental" is enabled. "init.defaultRefStorageFormat"
> +	 * and "init.defaultObjectFormat" take precedence over this setting.
>  	 */
>  	if (!strcmp(key, "feature.experimental") &&
> -	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
>  	    git_config_bool(key, value)) {
> -		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> +		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
> +			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
> +		if (cfg->hash == GIT_HASH_UNKNOWN)
> +			cfg->hash = GIT_HASH_SHA256;

I was curious as to whether this would actually ever be set to
`GIT_HASH_UNKNOWN` and therefore whether this would actually work, given
the conversation I recently had with Junio, but the tests you wrote
answered that question for me, so thank you for those.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Speaking for myself only

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] setup: use SHA-256 when experimental features are enabled
  2026-12-01  7:59 ` Patrick Steinhardt
  2026-12-01  8:04   ` Patrick Steinhardt
@ 2026-12-02  7:02   ` Toon Claes
  1 sibling, 0 replies; 7+ messages in thread
From: Toon Claes @ 2026-12-02  7:02 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, brian m. carlson

Patrick Steinhardt <ps@pks.im> writes:

> On Tue, Dec 01, 2026 at 07:47:09AM +0100, Toon Claes wrote:
>> In 793b14e1c8 (setup: use "reftable" format when experimental features
>> are enabled, 2025-07-04), git-init(1) learned to create new repositories
>> with the reftable backend when "feature.experimental" is enabled, so
>> that users can test the format that is planned to become the default in
>> Git 3.0. The SHA-256 object format is also planned to become the default
>> in Git 3.0, but "feature.experimental" does not affect the object
>> format, so new repositories still use SHA-1.
>
> Huh, interesting, I thought that "feature.experimental" already did
> this!

Well yes, I was surprised as well.

>> Teach "feature.experimental" to also make SHA-256 the default object
>> format for new repositories. As with the ref storage format, this
>> default can still be overridden by setting "init.defaultObjectFormat",
>> setting the GIT_DEFAULT_HASH environment variable, or passing
>> "--object-format=".
>
> This makes a ton of sense. Now that we're moving closer to Git 3.0 we
> should make sure to give upcoming breaking changes more exposure.
>
>> diff --git a/setup.c b/setup.c
>> index f9c03b6c47..d4c263d599 100644
>> --- a/setup.c
>> +++ b/setup.c
>> @@ -2850,13 +2850,16 @@ static int read_default_format_config(const char *key, const char *value,
>>  	}
>>  
>>  	/*
>> -	 * Enable the reftable format when "features.experimental" is enabled.
>> -	 * "init.defaultRefStorageFormat" takes precedence over this setting.
>> +	 * Enable the reftable format and the SHA-256 object format when
>> +	 * "features.experimental" is enabled. "init.defaultRefStorageFormat"
>> +	 * and "init.defaultObjectFormat" take precedence over this setting.
>>  	 */
>>  	if (!strcmp(key, "feature.experimental") &&
>> -	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
>>  	    git_config_bool(key, value)) {
>> -		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
>> +		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
>> +			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
>> +		if (cfg->hash == GIT_HASH_UNKNOWN)
>> +			cfg->hash = GIT_HASH_SHA256;
>
> Looks straight-forward. And this function still knows to properly
> override the hash in case "init.defaultObjectFormat" was set. Good.
>
>> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
>> index 9e57a06cea..da73ae7395 100755
>> --- a/t/t0001-init.sh
>> +++ b/t/t0001-init.sh
>> @@ -575,6 +575,40 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
>>  	test_cmp expected actual
>>  '
>>  
>> +test_expect_success 'init with feature.experimental=true uses sha256' '
>> +	test_when_finished "rm -rf repo" &&
>> +	test_config_global feature.experimental true &&
>> +	(
>> +		sane_unset GIT_DEFAULT_HASH &&
>> +		git init repo
>> +	) &&
>> +	echo sha256 >expect &&
>> +	git -C repo rev-parse --show-object-format >actual &&
>> +	test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'init.defaultObjectFormat overrides feature.experimental=true' '
>> +	test_when_finished "rm -rf repo" &&
>> +	test_config_global feature.experimental true &&
>> +	test_config_global init.defaultObjectFormat sha1 &&
>> +	(
>> +		sane_unset GIT_DEFAULT_HASH &&
>> +		git init repo
>> +	) &&
>> +	echo sha1 >expect &&
>> +	git -C repo rev-parse --show-object-format >actual &&
>> +	test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'GIT_DEFAULT_HASH overrides feature.experimental=true' '
>> +	test_when_finished "rm -rf repo" &&
>> +	test_config_global feature.experimental true &&
>> +	GIT_DEFAULT_HASH=sha1 git init repo &&
>> +	echo sha1 >expect &&
>> +	git -C repo rev-parse --show-object-format >actual &&
>> +	test_cmp expect actual
>> +'
>
> We could also verify that "--object-format=sha256" overrides
> "feature.experimental", but eventually it becomes excessive.

I'm not convinced there is any value in adding such test.

> Another thing we might want to test is whether git-clone(1) works as
> expected with "feature.experimental" set when cloning a SHA1 repo. But
> I'm somewhat sure that our test suite would probably catch such an issue
> if it didn't.

Euhm, that's actually not a bad idea, because test-lib.sh sets
GIT_DEFAULT_HASH, so I'm not sure such test case already exists.

-- 
Laters,
Toon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] setup: use SHA-256 when experimental features are enabled
  2026-12-01  6:47 [PATCH] setup: use SHA-256 when experimental features are enabled Toon Claes
  2026-12-01  7:59 ` Patrick Steinhardt
  2026-12-01 23:19 ` brian m. carlson
@ 2026-12-03 16:11 ` Toon Claes
  2026-12-04 14:06   ` Patrick Steinhardt
  2 siblings, 1 reply; 7+ messages in thread
From: Toon Claes @ 2026-12-03 16:11 UTC (permalink / raw)
  To: git; +Cc: brian m. carlson, Patrick Steinhardt, Toon Claes

In 793b14e1c8 (setup: use "reftable" format when experimental features
are enabled, 2025-07-04), git-init(1) learned to create new repositories
with the reftable backend when "feature.experimental" is enabled, so
that users can test the format that is planned to become the default in
Git 3.0. The SHA-256 object format is also planned to become the default
in Git 3.0, but "feature.experimental" does not affect the object
format, so new repositories still use SHA-1.

Teach "feature.experimental" to also make SHA-256 the default object
format for new repositories. As with the ref storage format, this
default can still be overridden by setting "init.defaultObjectFormat",
setting the GIT_DEFAULT_HASH environment variable, or passing
"--object-format=".

Existing repositories must keep their object format. This change
builds on "setup: fix hash algorithm detection", which makes sure
re-running git-init(1) in an existing repository does not pick up the
configured default hash. Without that fix, enabling
"feature.experimental" and re-initializing a SHA-1 repository writes
"extensions.objectFormat = sha256" to its config, after which the
repository is broken:

    $ git init --object-format=sha1 repo
    $ git -C repo commit --allow-empty -m initial
    $ git config set --global feature.experimental true
    $ git init repo
    $ git -C repo log
    fatal: your current branch appears to be broken

Add a test for this case. Also add a test that cloning a SHA-1
repository with "feature.experimental" enabled results in a SHA-1
clone. The test suite exports GIT_DEFAULT_HASH, which takes precedence
over the config, so no existing clone test covers this.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
With the release of Git 3.0 being planned, I noticed SHA-256 isn't
default-selected when "feature.experimental" is set. This small patch
fixes that.

This follows what Patrick did for the reftable backend in [1], which
made "feature.experimental" select the reftable format for new
repositories.

This patch is built on top of bc/setup-default-hash-algo [2]. Without
that topic, re-running git-init(1) in an existing SHA-1 repository with
"feature.experimental" enabled switches the repository to SHA-256 and
breaks it.

[1]: https://lore.kernel.org/git/20250703-pks-reftable-default-backend-v2-0-5a27e72a8c5e@pks.im/
[2]: https://lore.kernel.org/git/20261124225952.1616547-1-sandals@crustytoothpaste.net/

Laters,
Toon
---
Changes in v2:
- Rebase onto bc/setup-default-hash-algo, so re-initializing an
  existing repository does not change its object format.
- Add a test that re-initializing a SHA-1 repository with
  "feature.experimental" enabled keeps SHA-1.
- Add a test that cloning a SHA-1 repository with "feature.experimental"
  enabled results in a SHA-1 clone.
- Fix the "features.experimental" typo in the comment that is touched.
- Link to v1: https://patch.msgid.link/20261201-toon-init-experimental-sha256-v1-1-eecd8454be9e@iotcl.com
---
 Documentation/config/feature.adoc |  6 ++++
 setup.c                           | 11 ++++---
 t/t0001-init.sh                   | 66 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/Documentation/config/feature.adoc b/Documentation/config/feature.adoc
index e258770591..57e24724b4 100644
--- a/Documentation/config/feature.adoc
+++ b/Documentation/config/feature.adoc
@@ -30,6 +30,12 @@ the reftable format for storing references. This new format solves issues with
 case-insensitive filesystems, compresses better and performs significantly
 better with many use cases. Refer to Documentation/technical/reftable.adoc for
 more information on this new storage format.
++
+* `init.defaultObjectFormat=sha256` causes newly initialized repositories to use
+the SHA-256 object format. SHA-256 is planned to become the default hash
+algorithm in Git 3.0. Note that repositories using SHA-256 cannot interoperate
+with SHA-1 repositories, so some forges and third-party tools may not support
+them yet.
 
 feature.manyFiles::
 	Enable config options that optimize for repos with many files in the
diff --git a/setup.c b/setup.c
index 6109d2ad52..8be3364466 100644
--- a/setup.c
+++ b/setup.c
@@ -2840,13 +2840,16 @@ static int read_default_format_config(const char *key, const char *value,
 	}
 
 	/*
-	 * Enable the reftable format when "features.experimental" is enabled.
-	 * "init.defaultRefStorageFormat" takes precedence over this setting.
+	 * Enable the reftable format and the SHA-256 object format when
+	 * "feature.experimental" is enabled. "init.defaultRefStorageFormat"
+	 * and "init.defaultObjectFormat" take precedence over this setting.
 	 */
 	if (!strcmp(key, "feature.experimental") &&
-	    cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN &&
 	    git_config_bool(key, value)) {
-		cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
+		if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
+			cfg->ref_storage_format = REF_STORAGE_FORMAT_REFTABLE;
+		if (cfg->hash == GIT_HASH_UNKNOWN)
+			cfg->hash = GIT_HASH_SHA256;
 		ret = 0;
 		goto out;
 	}
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 58271c8fac..38f92a3b7c 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -586,6 +586,72 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
 	test_cmp expected actual
 '
 
+test_expect_success 'init with feature.experimental=true uses sha256' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git init repo
+	) &&
+	echo sha256 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'init.defaultObjectFormat overrides feature.experimental=true' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	test_config_global init.defaultObjectFormat sha1 &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git init repo
+	) &&
+	echo sha1 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'GIT_DEFAULT_HASH overrides feature.experimental=true' '
+	test_when_finished "rm -rf repo" &&
+	test_config_global feature.experimental true &&
+	GIT_DEFAULT_HASH=sha1 git init repo &&
+	echo sha1 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 're-init with feature.experimental=true keeps sha1' '
+	test_when_finished "rm -rf repo" &&
+	git init --object-format=sha1 repo &&
+	test_commit -C repo initial &&
+	test_config_global feature.experimental true &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git init repo
+	) &&
+	echo sha1 >expect &&
+	git -C repo rev-parse --show-object-format >actual &&
+	test_cmp expect actual &&
+	git -C repo fsck
+'
+
+test_expect_success 'clone of sha1 repository with feature.experimental=true' '
+	test_when_finished "rm -rf src dst" &&
+	git init --object-format=sha1 src &&
+	test_commit -C src initial &&
+	test_config_global feature.experimental true &&
+	(
+		sane_unset GIT_DEFAULT_HASH &&
+		git clone --no-local src dst
+	) &&
+	echo sha1 >expect &&
+	git -C dst rev-parse --show-object-format >actual &&
+	test_cmp expect actual &&
+	git -C src rev-parse HEAD >expect &&
+	git -C dst rev-parse HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success '--object-format overrides GIT_DEFAULT_HASH' '
 	test_when_finished "rm -rf repo" &&
 	GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo &&

---
base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2
change-id: 20261201-toon-init-experimental-sha256-e7c30b2ef129
prerequisite-message-id: <20261124225952.1616547-1-sandals@crustytoothpaste.net>
prerequisite-patch-id: 4dd7a75a74ae223c219aa0bb195308b40538d87e


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] setup: use SHA-256 when experimental features are enabled
  2026-12-03 16:11 ` [PATCH v2] " Toon Claes
@ 2026-12-04 14:06   ` Patrick Steinhardt
  0 siblings, 0 replies; 7+ messages in thread
From: Patrick Steinhardt @ 2026-12-04 14:06 UTC (permalink / raw)
  To: Toon Claes; +Cc: git, brian m. carlson

On Thu, Dec 03, 2026 at 05:11:02PM +0100, Toon Claes wrote:
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index 58271c8fac..38f92a3b7c 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -586,6 +586,72 @@ test_expect_success 'init warns about invalid init.defaultObjectFormat' '
[snip]
> +test_expect_success 're-init with feature.experimental=true keeps sha1' '
> +	test_when_finished "rm -rf repo" &&
> +	git init --object-format=sha1 repo &&
> +	test_commit -C repo initial &&
> +	test_config_global feature.experimental true &&
> +	(
> +		sane_unset GIT_DEFAULT_HASH &&
> +		git init repo
> +	) &&
> +	echo sha1 >expect &&
> +	git -C repo rev-parse --show-object-format >actual &&
> +	test_cmp expect actual &&
> +	git -C repo fsck
> +'
> +
> +test_expect_success 'clone of sha1 repository with feature.experimental=true' '
> +	test_when_finished "rm -rf src dst" &&
> +	git init --object-format=sha1 src &&
> +	test_commit -C src initial &&
> +	test_config_global feature.experimental true &&
> +	(
> +		sane_unset GIT_DEFAULT_HASH &&
> +		git clone --no-local src dst
> +	) &&
> +	echo sha1 >expect &&
> +	git -C dst rev-parse --show-object-format >actual &&
> +	test_cmp expect actual &&
> +	git -C src rev-parse HEAD >expect &&
> +	git -C dst rev-parse HEAD >actual &&
> +	test_cmp expect actual
> +'

Okay, these are the two new tests. We now verify that reinitialization
works as expected and doesn't just change the object format, and we do
the same for cloning a repository. Good.

Overall I'm happy with this version, thanks!

Patrick

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 14:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  6:47 [PATCH] setup: use SHA-256 when experimental features are enabled Toon Claes
2026-12-01  7:59 ` Patrick Steinhardt
2026-12-01  8:04   ` Patrick Steinhardt
2026-12-02  7:02   ` Toon Claes
2026-12-01 23:19 ` brian m. carlson
2026-12-03 16:11 ` [PATCH v2] " Toon Claes
2026-12-04 14:06   ` Patrick Steinhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.