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

[PATCH v2 1/3] setup: reject compatObjectFormat == objectFormat

From
Adrian Ratiu <adrian.ratiu@collabora.com>
Date
Nov 19, 2026, 14:18 UTC
Message-ID
<f74a0fd67af600f45bdb7560253c747aab073c65.1794932695.git.adrian.ratiu@collabora.com>
In-Reply-To
<cover.1794932695.git.adrian.ratiu@collabora.com>

When extensions.compatObjectFormat sets the same hash as the repo object format, every command in a build with Rust aborts with:

  BUG: repository.c:204: hash_algo and compat_hash_algo match

This includes "git config", so the bad value can't be removed with Git. It also happens with no extensions.objectFormat at all, when compatObjectFormat is set to the default object format.

Check for this in verify_repository_format(), next to the other repo format checks, and return an error instead.

The check runs before any of the Rust-only code. Builds without Rust, which so far died because compatObjectFormat requires Rust, now get the same error, so the test needs no RUST prereq.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 setup.c                 |  7 +++++++
 t/t1302-repo-version.sh | 14 ++++++++++++++
 2 files changed, 21 insertions(+)
diff --git a/setup.c b/setup.c
index 186815c780..a97280cafe 100644
--- a/setup.c
+++ b/setup.c
@@ -918,6 +918,13 @@ int verify_repository_format(const struct repository_format *format,
 		return -1;
 	}
 
+	if (format->compat_hash_algo == format->hash_algo) {
+		strbuf_addf(err, _("'%s' is '%s', the same as the object format"),
+			    "extensions.compatObjectFormat",
+			    hash_algos[format->hash_algo].name);
+		return -1;
+	}
+
 	return 0;
 }
 
diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh
index 69723b88ff..718dafc95c 100755
--- a/t/t1302-repo-version.sh
+++ b/t/t1302-repo-version.sh
@@ -98,6 +98,20 @@ abort 0 noop-v1
 allow 1 noop-v1
 EOF
 
+for hash in sha1 sha256
+do
+	test_expect_success "compatObjectFormat equal to objectFormat $hash" "
+		test_when_finished 'rm -rf same' &&
+		git init --object-format=$hash same &&
+		git -C same config set core.repositoryformatversion 1 &&
+		git -C same config set extensions.compatObjectFormat $hash &&
+		test_must_fail git -C same rev-parse --git-dir 2>err &&
+		test_grep \"'extensions.compatObjectFormat' is '$hash', the same as the object format\" err &&
+		git config unset --file=same/.git/config extensions.compatObjectFormat &&
+		git -C same rev-parse --git-dir
+	"
+done
+
 test_expect_success 'precious-objects allowed' '
 	git config core.repositoryFormatVersion 1 &&
 	git config extensions.preciousObjects 1 &&
-- 
2.56.1
Previous: Adrian RatiuNext: Adrian Ratiu
Message 12 of 14 in “compatObjectFormat: fix a BUG(), wrong id and unknown headers”
  1. 0/3 compatObjectFormat: fix a BUG(), wrong id and unknown headersAdrian Ratiu, Nov 12, 2026
  2. 1/3 setup: reject compatObjectFormat == objectFormatAdrian Ratiu, Nov 12, 2026
  3. Patrick SteinhardtNov 16, 2026
  4. Adrian RatiuNov 17, 2026
  5. 2/3 rev-parse: die when --output-object-format cannot map an objectAdrian Ratiu, Nov 12, 2026
  6. Patrick SteinhardtNov 16, 2026
  7. Adrian RatiuNov 17, 2026
  8. 3/3 object-file-convert: copy unknown commit headers unchangedAdrian Ratiu, Nov 12, 2026
  9. Patrick SteinhardtNov 16, 2026
  10. Adrian RatiuNov 17, 2026
  11. 0/3 compatObjectFormat: fix a BUG(), wrong ID and unknown headersAdrian Ratiu, Nov 19, 2026
  12. 1/3 setup: reject compatObjectFormat == objectFormatAdrian Ratiu, Nov 19, 2026
  13. 2/3 rev-parse: die when --output-object-format cannot map an objectAdrian Ratiu, Nov 19, 2026
  14. 3/3 object-file-convert: copy unknown commit headers unchangedAdrian Ratiu, Nov 19, 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.