From patchwork Thu Jan 30 16:24:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13954697 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9227322B for ; Thu, 30 Jan 2025 16:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254273; cv=none; b=Npw0kwgum8L9dA4Z1AN8GCciXXPVzxMasW26Scn8KobyoJztahKc7qY063VQBoN3hxvEA50BNI1GS/aPRl0q1GBlHMPLCG1G8jKBvYiDQ9JXpdsbbsobYMOleKCbO59h7Abqvq+1o9NBQBnP8wRTe9equrN+Z8peO9bey4p1Ak4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254273; c=relaxed/simple; bh=buvSfmVe2py6cCTe+k7N1zLt8EUwpk7wxw1pBnk3k20=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZFSgHVruBEmhalyJna9aNaQw8VbDMKPRtkT3P2Ddx2n0BQcLztbeBlYlD4aV7Lc96vh78/JSBqG9Fq00nUyKxLIQncPLKY9gn6Cl2c67uyJiAbUoZrzyXoHpKyr/5TRmwTJmA/AYK5aRFvLXE54QI+MRc332aWHJt7VnAJWwhYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=QBBMh4Jg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SFZq6t34; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="QBBMh4Jg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SFZq6t34" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id C89A71140088 for ; Thu, 30 Jan 2025 11:24:30 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 30 Jan 2025 11:24:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738254270; x=1738340670; bh=6mfrHfmFhWvZdNjFDNsiPM4nxLero6jl5+qofJ3QkqI=; b= QBBMh4Jg9CvN/ciGl8F6qd3z1Fqt8iBKoKsdc/iudpRt6veuDrqqydeVWFhzdZZS 4HbovQV//jLNPBoty4W/NzfFxEXQt1+Zl2ri6kUnpM37gyYdLEz5teXHp1XNErjV kTNa9PmQ9tArR5E4VANrYOl/mCozT2ZBESSGGEl4680otCmenkg1U4PTw4FJGYTm rzd0B5SBXD5YXA4wcUV/lMOpJ19R0CqN84tG7FwF5HG+JvDI68mr1xeczQT4iweO dNF5/GPE8fQPGyrRUtmt2k79ncCi5R13c+eKMoYhSwWEmFzuMskxzbK3qesFrlVe wcdUyrBmcQvczkCJofFxpg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738254270; x= 1738340670; bh=6mfrHfmFhWvZdNjFDNsiPM4nxLero6jl5+qofJ3QkqI=; b=S FZq6t343pzCeD/0KwJGKU+a4e7Wg9J64Eeg95+dmNQf+F9vQ+yRZzmJLHTnNZ8wY bvbEEI1K0jzYL5uoK1G2Y+1wND5ujMg4h8cp4/yUccWEuNirZd6rzIsx6FtEhRF5 iP2Cy9AgkqXIM2AwjXr1CJVTfOzqp9buMjV9Xmffmb/6zBveduVzGwA3Gk9UglAp zbXZ09xJdCVw1JJm/l3rfR083oGLy53shmiPd8u2gM6c8ZLJ6lQ8KmX3TEfF/zHJ /4SOnjQVkHnsQRvep2FJa7b01y3E4RATVOdHsfHX2yz9AZa8BYbdnbxs6djfMn8w kIDHVEh6DeIf2o7RTRnPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeivdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 30 Jan 2025 11:24:30 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 22e9b06a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 30 Jan 2025 16:24:26 +0000 (UTC) From: Patrick Steinhardt Date: Thu, 30 Jan 2025 17:24:17 +0100 Subject: [PATCH 1/3] t0001: remove duplicate test Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250130-b4-pks-reinit-default-ref-format-v1-1-d2769ca01207@pks.im> References: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> In-Reply-To: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> To: git@vger.kernel.org Cc: X-Mailer: b4 0.14.2 The test in question is an exact copy of the testcase preceding it. Remove it. Signed-off-by: Patrick Steinhardt --- t/t0001-init.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 72a0c2e7d4..213d5984b1 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -861,15 +861,6 @@ test_expect_success 're-init with includeIf.onbranch condition' ' test_cmp expect actual ' -test_expect_success 're-init with includeIf.onbranch condition' ' - test_when_finished "rm -rf repo" && - git init repo && - git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo && - echo $GIT_DEFAULT_REF_FORMAT >expect && - git -C repo rev-parse --show-ref-format >actual && - test_cmp expect actual -' - test_expect_success 're-init skips non-matching includeIf.onbranch' ' test_when_finished "rm -rf repo config" && cat >config <<-EOF && From patchwork Thu Jan 30 16:24:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13954699 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DAC11EE021 for ; Thu, 30 Jan 2025 16:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254275; cv=none; b=MUROEtBP30yG41HAaiCHq6puC6VdzVCKQ053FDDeuC67GoKL6VGehwMdkNqk2uRHnFb3mgUrOkwFXDEuWTUg9oPXw8IifLXFi9EDDN3Rmj/uN1scHFfFKwQQaIj9gKs2Uu24OnusyGEE5MRETQXIAC3aCaM3Plf14SV40ctTLYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254275; c=relaxed/simple; bh=7pramfWLmv4Ys56BhtQx6RrUF63xnFQRLeF7rcB0F+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D9pF1UOIO9iEUqWGpCF7rsU/MlBP6m2UcWAPzOoX447nmQ3iWOhwhxXKJ6IV/bCVekecNIWrbi+QFxzbvp+utLR7hkUEskBUiwO+zvcJNR4GvbwAV3e5O+08zPxoGoh3d0XMPynOSncjGp02Q4mCF4az9GE9vn39KQQHzaLyO2E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=NFOrVUlz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kPw1iG3E; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="NFOrVUlz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kPw1iG3E" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 96F401140102 for ; Thu, 30 Jan 2025 11:24:31 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 30 Jan 2025 11:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738254271; x=1738340671; bh=74R58twNDF/tT+P3ltzQ6Vtv5dHabjHLoygdBeWI2pI=; b= NFOrVUlzjm081TyDpVvC35KiUAH0oY3RkXeG23javbhQ+bUZ7WhT9QbKR98GE/NL 7Mz5LofQ2fZM0nY9Ng71n1O1md1y6wsjCNcr8yseRfh9DpsgB12uAwD4R1ntItQE M9Hk3RO7bM2Btxk4ynXUAf6kyVs1ebsa2HFXFGIFDBy4cNhh3vJktD9eJZmyiJmz Q0A+VbNhMPsx5SUITnDOJm1RdBeBX2leTp2Xjx7Y2atEbRE4O/lpVsX8hXjBB6tr U1Aj1FRRUJp2pceJRe1zbKDLV4NZT3JcQOf8CafdxdSeq4KIbI+BgNtDqn5JAghq ++m2rwoIcz31LU1mJBONBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738254271; x= 1738340671; bh=74R58twNDF/tT+P3ltzQ6Vtv5dHabjHLoygdBeWI2pI=; b=k Pw1iG3EkF8BbsrFywpGCvBlVkQXvWQBmojZJ6yZqwPVwLjZVGlkaG7xy5/LtXzma SqgkO6HpTrEOf/joIT/tB3Ds0rTPCtglSpK4xSKdfwMZ4f4CMbu2GZgeMhE3lbVj /jtSDB5Dugfk0rZAXs7LHwUTRkv63ne/q2Sr67ZKjFlq6T3qgiI9hSDPkfr5DFKa eq9Rz3rp/2V+gQevlbZm8PpvNbNQvqRIZslkMh8toH1vp6LkV9VD7hzWq6x/D8W4 DkACu0STk3MavCM1zaNV1gS6x+T18woDnG6JDnanye9p3GRoiXulCtRpyK0ZW6R5 iBGSQ8p/Em3z0iHJ+MfBA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeivdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 30 Jan 2025 11:24:30 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b830ed92 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 30 Jan 2025 16:24:27 +0000 (UTC) From: Patrick Steinhardt Date: Thu, 30 Jan 2025 17:24:18 +0100 Subject: [PATCH 2/3] setup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250130-b4-pks-reinit-default-ref-format-v1-2-d2769ca01207@pks.im> References: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> In-Reply-To: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> To: git@vger.kernel.org Cc: X-Mailer: b4 0.14.2 The GIT_DEFAULT_REF_FORMAT environment variable can be set to influence the default ref format that new repostiories shall be initialized with. While this is the expected behaviour when creating a new repository, it is not when reinitializing a repository: we should retain the ref format currently used by it in that case. This doesn't work correctly right now: $ git init --ref-format=files repo Initialized empty Git repository in /tmp/repo/.git/ $ GIT_DEFAULT_REF_FORMAT=reftable git init repo fatal: could not open '/tmp/repo/.git/refs/heads' for writing: Is a directory Instead of retaining the current ref format, the reinitialization tries to reinitialize the repository with the different format. This action fails when git-init(1) tries to write the ".git/refs/heads" stub, which in the context of the reftable backend is always written as a file so that we can detect clients which inadvertently try to access the repo with the wrong ref format. Seems like the protection mechanism works for this case, as well. Fix the issue by ignoring the environment variable in case the repo has already been initialized with a ref storage format. Signed-off-by: Patrick Steinhardt --- setup.c | 4 +++- t/t0001-init.sh | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.c b/setup.c index 8a488f3e7c..53ffeabc5b 100644 --- a/setup.c +++ b/setup.c @@ -2534,7 +2534,9 @@ static void repository_format_configure(struct repository_format *repo_fmt, ref_format = ref_storage_format_by_name(env); if (ref_format == REF_STORAGE_FORMAT_UNKNOWN) die(_("unknown ref storage format '%s'"), env); - repo_fmt->ref_storage_format = ref_format; + if (repo_fmt->version < 0 || + repo_fmt->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN) + repo_fmt->ref_storage_format = ref_format; } else if (cfg.ref_format != REF_STORAGE_FORMAT_UNKNOWN) { repo_fmt->ref_storage_format = cfg.ref_format; } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 213d5984b1..6dff8b75f1 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -697,6 +697,15 @@ do git -C refformat rev-parse --show-ref-format >actual && test_cmp expect actual ' + + test_expect_success "reinit repository with GIT_DEFAULT_REF_FORMAT=$format does not change format" ' + test_when_finished "rm -rf refformat" && + git init refformat && + git -C refformat rev-parse --show-ref-format >expect && + GIT_DEFAULT_REF_FORMAT=$format git init refformat && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' done test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" ' From patchwork Thu Jan 30 16:24:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13954698 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DA6A1EE01F for ; Thu, 30 Jan 2025 16:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254274; cv=none; b=aWlMQfJLmMM49QPxoNzsWmpT5ZmY1XDeM3yYaE463AMdyCBtl2WKO/wu0sNiRaiR/dFVxSCnrXj8mkxE3iZH6zTQHjlosgZgbRF5HZ8tew5P5r84HuyzVQbfcogj77p3N1dcsAXEhNF8wDn5syeMK0R0jBK83+r2wmMu6sV2s9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738254274; c=relaxed/simple; bh=lIdIOdlBGb/8rrhbC1Ic8RgL3tYHQrycmTkRJ68wH6A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hVH5dxt3z/RxqXQoobRHIRnfT9ZTeLc1xeTEa3bBxvPObYkVt0CWRju3hgCmXxWW49OQTIkT/Qs7WbtSyuXTi5h2roX4GEtiVY1VPeqKJJ9xUTzaywxVfKiYqcs1Md99oWHukX3MLx1BiTuc51iKfr298dSQIaG5gRaNiIhvmBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=gfS6p43a; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KiJ41hVC; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="gfS6p43a"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KiJ41hVC" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id B97781140121 for ; Thu, 30 Jan 2025 11:24:31 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 30 Jan 2025 11:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1738254271; x=1738340671; bh=Gp8UTkRTHtukFkkI8zVAG/UTLc1yuOc/B2k0jK1Y+9k=; b= gfS6p43aek+NNcyOW1+lecbBCopAtWohFjfAO9/PMOIEz0cl2oAYnVALyHERSbqd auQhCiilQZMKwdPTVRqSj2oYDnPEpIyfs0oz+rICsvPq/Je4HZARXbHWC1uP1VuZ XRtIk5X5DY0mB7FdLIX6vui97o51pqr2H4LBj80A1wYhkoeKZdIUnarLoPb6Jza7 LCE1uUiErDjCCYN/gomOSPOcsLFNUIxbuYX6rr5HpxMNgGtL5W6UfLC9cj+DF7l3 m/GiM5o/pqSzSM3VMUxUdyi5LR7XuMryeUgD5Eo/0937sZzsfEYrVSRNpUpUcXyI q9TraOzeP8K9LqlymLhZ3w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738254271; x= 1738340671; bh=Gp8UTkRTHtukFkkI8zVAG/UTLc1yuOc/B2k0jK1Y+9k=; b=K iJ41hVCvsbUIe4wnCIt+fRiCCnWoK14zs6Ib0fldvEQXQV+JbXaub+AL3LJi5zZX cYcKJ6+XJMKrg5VTGbL8UkrOVo9Akjp1XvdXUpj6hClIvOhk3eVAi6XCo/keZc3h Wde9MsY/kChl/5pXKNlZxNlEqpzBK+YqkhTJgaZpukMWV6lamWL6N4lRn0CtDC21 2kQXveQZwwgfGwBAtHgKluWHiMW6MxnZ7YA3KYdyxY+YSN4Agr5Oa9cBi6wCxCPa JOAQsoG60JveyxwOYLfNVbUN5aWZsYOk0HF5tX80WKS+7Ew3sYPd10pQ3zfHr0yK 4lT1ZmF1LoeD+7D4/xzmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeivdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhfffugg gtgffkfhgjvfevofesthejredtredtjeenucfhrhhomheprfgrthhrihgtkhcuufhtvghi nhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepffeuieduje dvkeehuedvkeefffeivdeuleetkeduheejteekgedvudfgtdfgieelnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnh gspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 30 Jan 2025 11:24:30 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e63dbb55 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Thu, 30 Jan 2025 16:24:28 +0000 (UTC) From: Patrick Steinhardt Date: Thu, 30 Jan 2025 17:24:19 +0100 Subject: [PATCH 3/3] setup: fix reinit of repos with incompatible GIT_DEFAULT_HASH Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250130-b4-pks-reinit-default-ref-format-v1-3-d2769ca01207@pks.im> References: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> In-Reply-To: <20250130-b4-pks-reinit-default-ref-format-v1-0-d2769ca01207@pks.im> To: git@vger.kernel.org Cc: X-Mailer: b4 0.14.2 The exact same issue as described in the preceding commit also exists for GIT_DEFAULT_HASH. Thus, reinitializing a repository that e.g. uses SHA1 with `GIT_DEFAULT_HASH=sha256 git init` will cause the object format of that repository to change to SHA256. This is of course bogus as any existing objects and refs will not be converted, thus causing repository corruption: $ git init repo Initialized empty Git repository in /tmp/repo/.git/ $ cd repo/ $ git commit --allow-empty -m message [main (root-commit) 35a7344] message $ GIT_DEFAULT_HASH=sha256 git init Reinitialized existing Git repository in /tmp/repo/.git/ $ git show fatal: your current branch appears to be broken Fix the issue by ignoring the environment variable in case the repo has already been initialized with an object hash. Signed-off-by: Patrick Steinhardt --- setup.c | 4 +++- t/t0001-init.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/setup.c b/setup.c index 53ffeabc5b..7da7aa8984 100644 --- a/setup.c +++ b/setup.c @@ -2517,7 +2517,9 @@ static void repository_format_configure(struct repository_format *repo_fmt, int env_algo = hash_algo_by_name(env); if (env_algo == GIT_HASH_UNKNOWN) die(_("unknown hash algorithm '%s'"), env); - repo_fmt->hash_algo = env_algo; + if (repo_fmt->version < 0 || + repo_fmt->hash_algo == GIT_HASH_UNKNOWN) + repo_fmt->hash_algo = env_algo; } else if (cfg.hash != GIT_HASH_UNKNOWN) { repo_fmt->hash_algo = cfg.hash; } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 6dff8b75f1..c49d9e0d38 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -586,6 +586,18 @@ test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' ' echo sha256 >expected ' +for hash in sha1 sha256 +do + test_expect_success "reinit repository with GIT_DEFAULT_HASH=$hash does not change format" ' + test_when_finished "rm -rf repo" && + git init repo && + git -C repo rev-parse --show-object-format >expect && + GIT_DEFAULT_HASH=$hash git init repo && + git -C repo rev-parse --show-object-format >actual && + test_cmp expect actual + ' +done + test_expect_success 'extensions.objectFormat is not allowed with repo version 0' ' test_when_finished "rm -rf explicit-v0" && git init --object-format=sha256 explicit-v0 &&