git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] setup: use SHA-256 when experimental features are enabled

From
Toon Claes <toon@iotcl.com>
Date
Dec 1, 2026, 06:47 UTC
Message-ID
<20261201-toon-init-experimental-sha256-v1-1-eecd8454be9e@iotcl.com>

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
Next: Patrick Steinhardt
Message 1 of 5 in “setup: use SHA-256 when experimental features are enabled”
  1. setup: use SHA-256 when experimental features are enabledToon Claes, Dec 1, 2026
  2. Patrick SteinhardtDec 1, 2026
  3. Patrick SteinhardtDec 1, 2026
  4. Toon ClaesDec 2, 2026
  5. brian m. carlsonDec 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.