From patchwork Fri Aug 16 08:56:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13765803 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 D152913A416 for ; Fri, 16 Aug 2024 09:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799176; cv=none; b=n/h4JovMPqAiScvBn9BQ7huRVy2N4mqkHhqMHgTiJ/Xlw9TVtnkIrq9zX7A48DcHr5FuejbwNcgThQX+WR0dE+5cMIjDGgjq/c+A+XQ3ezv/ptSpFuTa4AyBfQVxUlqqRHqzVStqqlzzjBZWgfYZriVDh82Hxrj2N7iCVrITaUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799176; c=relaxed/simple; bh=vHbON6DJuratdtZPtnxXFhnY2EJKNntpkUDMlQ4pBWg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sgla1ikPVcAeczKK0JSitJFZ/G5K27sLeAHohjUuSlbWjqGZZ2bPxuhFUGT+LzH4lXmcPegLkHLF6GtbX2++T7HlZ3LJqzcCeHRb+iF9fQDh5YjoJKIuAuvLfnwUzCD8GyiYKxOAdQOtsEFv14Bajzx57zkEa6y2PoZmrCZWaxs= 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=gV6xg9ac; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=rhzj5lBY; arc=none smtp.client-ip=103.168.172.153 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="gV6xg9ac"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="rhzj5lBY" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 90976114AB11; Fri, 16 Aug 2024 04:56:55 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Fri, 16 Aug 2024 04:56:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=1723798615; x=1723885015; bh=hBcrE6obeU l8UAzwXmG1mqpoG637vytBkeS2Sr/rE5M=; b=gV6xg9acngbEQ+Z+9QX4R8WpKE bu7NoZ3hWFeKEBd8XI3GfhCUs9PSVoxdcLgF3q5GuZTZlpEGIRf0oxD3Xg8qPji9 D4ic6BH2SZStdb1gZuRZpwClMdyQhp/b2eVkyskZWkvwU6B+r8NQ8wCnbvvrt3CQ njumAhlfDl80wGDsouoOQlWA+MaxsjpquBZU372AC02y66Jlv/pGeJe95rF1C/ea d5/nh168ysc33NfDMMUEnYvEmz13pPeeDUE3KgtfpHldCzzFBiuPaY4sznXOY/OX khHO/vnGvYOKlQa+S74W0rl0RyeFSVqsrCL8uqp9oH5pT+eBUFmcyyO4kGOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723798615; x=1723885015; bh=hBcrE6obeUl8UAzwXmG1mqpoG637 vytBkeS2Sr/rE5M=; b=rhzj5lBYHwtJhaF9JrgInucJTECyCvEFGkuUCQ6sqQgZ Xw2eGMUXT5ddAyH7YP47aYwSML3niuL0qES/on97zecEWRbf+tQX3yhbBUHUP36x xhgTiEstOzBTHveIsoXm9fYDWhYlUhN77s5nDGbfj7PGH/gZlhxATuqO+ztSEy1c 74ZqFnR83pjla81WnyNJ+7Nci2g3v4tLuDV1fm1BrjQdiwRX0MXJ8vn+JYi6uSoW UAydyduv+KOo3fvqqRZvTSGHYWns6ICa4m6H5P29wYTQW2SyjdSnYm053tULBoAN gyd81YKLf/rNQ9N2nEOJ34K4eZPMg18bWVIQZupnWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtkedgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshgrnhgurghlshestghruhhsthihthhoohhthhhprg hsthgvrdhnvghtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgt phhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhstg hhuhgsvghrthhhsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehg mhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Aug 2024 04:56:54 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 11c66138 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 16 Aug 2024 08:56:31 +0000 (UTC) Date: Fri, 16 Aug 2024 10:56:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth , Justin Tobler , "brian m. carlson" , Junio C Hamano Subject: [PATCH v2 1/5] t0001: exercise initialization with ref formats more thoroughly Message-ID: <0d3844db32237983a1d85ced1a3b1b25fcd1d6eb.1723798388.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: While our object format tests for git-init(1) exercise tests with all known formats in t0001, the tests for the ref format don't. This leads to some missing test coverage for interesting cases, like whether or not a non-default ref storage format causes us to bump the repository format version. We also don't test for the precedence of the `--ref-format=` and the `GIT_DEFAULT_REF_FORMAT=` environment variable. Extend the test suite to cover more scenarios related to the ref format. Signed-off-by: Patrick Steinhardt --- t/t0001-init.sh | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 49e9bf77c6..2093f5c1ee 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -558,15 +558,6 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err ' -test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' ' - test_when_finished "rm -rf refformat" && - GIT_DEFAULT_REF_FORMAT=files git init refformat && - echo 0 >expect && - git -C refformat config core.repositoryformatversion >actual && - test_cmp expect actual && - test_must_fail git -C refformat config extensions.refstorage -' - test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' test_when_finished "rm -rf refformat" && cat >expect <<-EOF && @@ -576,15 +567,46 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' test_cmp expect err ' -test_expect_success 'init with --ref-format=files' ' +backends="files reftable" +for format in $backends +do + test_expect_success DEFAULT_REPO_FORMAT "init with GIT_DEFAULT_REF_FORMAT=$format" ' + test_when_finished "rm -rf refformat" && + GIT_DEFAULT_REF_FORMAT=$format git init refformat && + + if test $format = files + then + test_must_fail git -C refformat config extensions.refstorage && + echo 0 >expect + else + git -C refformat config extensions.refstorage && + echo 1 >expect + fi && + git -C refformat config core.repositoryformatversion >actual && + test_cmp expect actual && + + echo $format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' + + test_expect_success "init with --ref-format=$format" ' + test_when_finished "rm -rf refformat" && + git init --ref-format=$format refformat && + echo $format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' +done + +test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" ' test_when_finished "rm -rf refformat" && - git init --ref-format=files refformat && - echo files >expect && + GIT_DEFAULT_REF_FORMAT=files git init --ref-format=reftable refformat && + echo reftable >expect && git -C refformat rev-parse --show-ref-format >actual && test_cmp expect actual ' -backends="files reftable" for from_format in $backends do test_expect_success "re-init with same format ($from_format)" ' From patchwork Fri Aug 16 08:56:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13765799 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 B740D7581B for ; Fri, 16 Aug 2024 09:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; cv=none; b=Hz8PJRZM11LFaMm0ME+i5PcYhcz2RxiEeLU2d64DdMpByBS2Z5wz1Ki5JK7qvyWypw0DVht2Tw+BJTHknKqZHW4mStCTd8FWCpv28DqBwHH0Yjvq5y9XlEF7R1fWkAac/T4ZcMbB6xvf2TpPOD1w0cQPhs7RZurUyC4GpmltNIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; c=relaxed/simple; bh=iwvBxeyOchcJfVlelwb+BzBURrC9sMspLnBIDaxUUf4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JJhM99V8iETjlOhXQ+GlHmZjbvXr/9qEwqyh/peiPJtgZaaSurnZS7/GLI3waYBD0kYuC2NFWsLckKAS2VLlBRZXLumtUopibWSjb5+XMn9dAKJXGk6k5rWHgRBHs26wmUkdWB8oJAcTLK98BMouQioHCcuIvtt/tqP5FWMRaew= 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=dSnXOeqc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=byWwxfUv; arc=none smtp.client-ip=103.168.172.150 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="dSnXOeqc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="byWwxfUv" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 0C849138FCE5; Fri, 16 Aug 2024 04:56:59 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 16 Aug 2024 04:56:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=1723798619; x=1723885019; bh=OXWalzTFc4 FNVw6teJewSP6UL1rKnyuTQvntJbAWPHY=; b=dSnXOeqc3pC6ZCouTHVJzhPSER Zy5C2gisjyNZ/ktF+y57gcue4hwLsIW2hMs0eKs/ckqFg3P+3goY1U+02rw3+ZXh 5IgB75wvE3JsSqUlmFbXhj3phTfPf56s9zx1IUHLi8pq+9e5TxjZ6BW9p7l4YuFa PiXnVRWFgGSi9EI564uccXoWGYG/arnzQ/Fxm/bGiVX8a2j7HPEk10NwWvqGzDtn bsCHz4A1cHsCD1uYxQ9CBJhzYhUKN9Xnnmun5/Jm6MYXDQMkf16gOCVtPC9QNVc+ ltaWagRYkP4huvJgFb0cl39oHSRUI0lx4oYYh/uzd4CkWHPgQ2UlitOOMlfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723798619; x=1723885019; bh=OXWalzTFc4FNVw6teJewSP6UL1rK nyuTQvntJbAWPHY=; b=byWwxfUvaMBbwNio7ZDz70pTvk+DeNAEdjOPr3gRwndG Vw0uw/CJkmNdTqSxWR4L8kdRL+ZqW/2rcF7p74gOh0VYCKcsYfdbvhhnV1rboC7C 1KkH0W9VMVPAYU4Y+fx6Bnf0j+L/Kz/9snBrrEfgU++mPmhq97U7OP3gQSjtQeqr 9jWZPlFdQaG3OAhg0/0xt8j6y5qKPSagzZ0UnkyK7dvACrtAlMMFuo7maYsUtJRL E2vXih10HxAEut0Rva0noV6nuQmhAAbEio5ZTUZJLktbfAIDbbIM8FXaXANAizAN DGITKZeUwzsa7+aXFJKP886hVuIYgXgkSdCjxWDyeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehsshgthhhu sggvrhhthhesghhmrghilhdrtghomhdprhgtphhtthhopehsrghnuggrlhhssegtrhhush hthihtohhothhhphgrshhtvgdrnhgvthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgv rhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Aug 2024 04:56:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a6cebb4d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 16 Aug 2024 08:56:34 +0000 (UTC) Date: Fri, 16 Aug 2024 10:56:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth , Justin Tobler , "brian m. carlson" , Junio C Hamano Subject: [PATCH v2 2/5] t0001: delete repositories when object format tests finish Message-ID: <6b0cefef6af3a94cd3b650b2ab06de489dbdaf20.1723798388.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The object format tests create one-shot repositories that are only used by the respective test, but never delete them. This makes it hard to pick a proper repository name in subsequent tests, as more and more names are taken already. Delete these repositories via `test_when_finished`. Signed-off-by: Patrick Steinhardt --- t/t0001-init.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 2093f5c1ee..795408e16c 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -500,6 +500,7 @@ test_expect_success 're-init from a linked worktree' ' ' test_expect_success 'init honors GIT_DEFAULT_HASH' ' + test_when_finished "rm -rf sha1 sha256" && GIT_DEFAULT_HASH=sha1 git init sha1 && git -C sha1 rev-parse --show-object-format >actual && echo sha1 >expected && @@ -511,6 +512,7 @@ test_expect_success 'init honors GIT_DEFAULT_HASH' ' ' test_expect_success 'init honors --object-format' ' + test_when_finished "rm -rf explicit-sha1 explicit-sha256" && git init --object-format=sha1 explicit-sha1 && git -C explicit-sha1 rev-parse --show-object-format >actual && echo sha1 >expected && @@ -522,6 +524,7 @@ test_expect_success 'init honors --object-format' ' ' 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 && git -C explicit-v0 config core.repositoryformatversion 0 && test_must_fail git -C explicit-v0 rev-parse --show-object-format From patchwork Fri Aug 16 08:56:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13765802 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 B74D0139579 for ; Fri, 16 Aug 2024 09:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; cv=none; b=CdddvGq74YRBHB4qbHQpYFTkbiy9xRdo8JD2ZPHAIwi6SLJFDyxZS1Ij85ltpMpVhggoUGjMCKa4ZY7ui/duc8okHu6VKyQF+yRNlnfc17FQcfe9nwfx2rFq/FL06BWVZmWElyfza3j6sI1UXm17HXnGJKG7JhI/zFn70w3fAzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; c=relaxed/simple; bh=BERRG9L3o+DkmkqkBYapbhoBSMonMkPYwTsIvB8ZNn4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TxH5Mxk1+znxtT1ss7zZBerIoJV+ieX4cp5/VV1lJJ+R+m33M5BvOxAe61qZMkHGKGW4T6ROo2zY6oLlyZ+uaSs10pbKwKPDW/cmVZpE3Toa2gb5lLxGYmEelqDxWldHqOdzWu2a8p2WS8hU3mjLIvBu9jM3WZgySI1AUP3Y1dw= 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=X+9wMx+g; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qva+K6C+; arc=none smtp.client-ip=103.168.172.150 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="X+9wMx+g"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qva+K6C+" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 88844138FD03; Fri, 16 Aug 2024 04:57:01 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 16 Aug 2024 04:57:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=1723798621; x=1723885021; bh=O/dSDskehd U9PTFhzAP+imJaQ9KSgiFubE51dMB3BZQ=; b=X+9wMx+gNCO7gZsoPcOnjK/mf0 Vgxg0q/8i/KCN//jTDjZJcEAac4HqB/znbQZTWVxgs338tPdI1E6Gjc4wg9nSFFb WbJfoDo+92TzmDzJji0oq6fke0rUN0xrI1j/XwcNcV1ff9YbrL5tdymWlZT8502q mvcxAy1iM33jbCsaNq+XYsPiQPK8mF9fI8IKdWqDpuKPuMBe7eJVOSdeam9jLXgz 0fDZEpgGn0LCsCyQojyssqFoEX524ClMKILVWy6tLatn5IhjC/o/GxcMTU5eC2vH 3hfySpoewTqJzX1+Qsai30lYWoUouSrhPKsxP/O0seGVeEKmgG/CbXzEhuzA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723798621; x=1723885021; bh=O/dSDskehdU9PTFhzAP+imJaQ9KS giFubE51dMB3BZQ=; b=qva+K6C+0WmMhg7ouR7f3ylAAyo4yBYlohfwF6RnREMl kqHy3V2Syon9xFxElo1ncg1JmK9SUyT2S8gX3iLZXDFB10LiErzpMAFOywuZ3ERx 7QRgV4wtCl1Tf8y+UUo3qhLWEq99k+QQO6sE8gk8nHYFW5tBlPYKoD3YR1oC9AZ+ 7doAp5tHkSy0Yo/Kxv7Tlq03VAx8MVB+eB0qs5v1UXmvuhvlvzGTMv7auNVfTJYI 8AqzDUJMHur7tnE8dkFDs2o4ezGrdcy9fMujn7WYWTNQDr9n5rHXo5ER3hsD9GBD /wZamA6hWQKrZJFN5nltBZOX8xFO6CV2x8KcLsAPVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehsrghnuggr lhhssegtrhhushhthihtohhothhhphgrshhtvgdrnhgvthdprhgtphhtthhopehgihhtse hvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhstghhuhgsvghrthhhsehg mhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Aug 2024 04:57:00 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1f7800e5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 16 Aug 2024 08:56:37 +0000 (UTC) Date: Fri, 16 Aug 2024 10:56:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth , Justin Tobler , "brian m. carlson" , Junio C Hamano Subject: [PATCH v2 3/5] setup: merge configuration of repository formats Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The configuration of repository formats is split up across two functions `validate_hash_algorithm()` and `validate_ref_storage_format()`. This is fine as-is, but we are about to extend the logic to also read default values from the config. With the logic split across two functions, we would either have to pass in additional parameters read from the config, or read the config multiple times. Both of these options feel a bit unwieldy. Merge the code into a new function `repository_format_configure()` that is responsible for configuring the whole repository's format. Like this, we can easily read the config in a single place, only. Furthermore, move the calls to `repo_set_ref_storage_format()` and `repo_set_hash_algo()` into this new function as well, such that all the logic to configure the repository format is self-contained here. Signed-off-by: Patrick Steinhardt --- setup.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/setup.c b/setup.c index d458edcc02..5dfcdc99dd 100644 --- a/setup.c +++ b/setup.c @@ -2284,14 +2284,17 @@ static void separate_git_dir(const char *git_dir, const char *git_link) write_file(git_link, "gitdir: %s", git_dir); } -static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash) +static void repository_format_configure(struct repository_format *repo_fmt, + int hash, enum ref_storage_format ref_format) { - const char *env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT); + const char *env; + /* * If we already have an initialized repo, don't allow the user to * specify a different algorithm, as that could cause corruption. * Otherwise, if the user has specified one on the command line, use it. */ + env = getenv(GIT_DEFAULT_HASH_ENVIRONMENT); if (repo_fmt->version >= 0 && hash != GIT_HASH_UNKNOWN && hash != repo_fmt->hash_algo) die(_("attempt to reinitialize repository with different hash")); else if (hash != GIT_HASH_UNKNOWN) @@ -2302,25 +2305,22 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash die(_("unknown hash algorithm '%s'"), env); repo_fmt->hash_algo = env_algo; } -} - -static void validate_ref_storage_format(struct repository_format *repo_fmt, - enum ref_storage_format format) -{ - const char *name = getenv("GIT_DEFAULT_REF_FORMAT"); + repo_set_hash_algo(the_repository, repo_fmt->hash_algo); + env = getenv("GIT_DEFAULT_REF_FORMAT"); if (repo_fmt->version >= 0 && - format != REF_STORAGE_FORMAT_UNKNOWN && - format != repo_fmt->ref_storage_format) { + ref_format != REF_STORAGE_FORMAT_UNKNOWN && + ref_format != repo_fmt->ref_storage_format) { die(_("attempt to reinitialize repository with different reference storage format")); - } else if (format != REF_STORAGE_FORMAT_UNKNOWN) { - repo_fmt->ref_storage_format = format; - } else if (name) { - format = ref_storage_format_by_name(name); - if (format == REF_STORAGE_FORMAT_UNKNOWN) - die(_("unknown ref storage format '%s'"), name); - repo_fmt->ref_storage_format = format; + } else if (ref_format != REF_STORAGE_FORMAT_UNKNOWN) { + repo_fmt->ref_storage_format = ref_format; + } else if (env) { + 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; } + repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format); } int init_db(const char *git_dir, const char *real_git_dir, @@ -2353,22 +2353,15 @@ int init_db(const char *git_dir, const char *real_git_dir, } startup_info->have_repository = 1; - /* Check to see if the repository version is right. + /* + * Check to see if the repository version is right. * Note that a newly created repository does not have * config file, so this will not fail. What we are catching * is an attempt to reinitialize new repository with an old tool. */ check_repository_format(&repo_fmt); - validate_hash_algorithm(&repo_fmt, hash); - validate_ref_storage_format(&repo_fmt, ref_storage_format); - - /* - * Now that we have set up both the hash algorithm and the ref storage - * format we can update the repository's settings accordingly. - */ - repo_set_hash_algo(the_repository, repo_fmt.hash_algo); - repo_set_ref_storage_format(the_repository, repo_fmt.ref_storage_format); + repository_format_configure(&repo_fmt, hash, ref_storage_format); /* * Ensure `core.hidedotfiles` is processed. This must happen after we From patchwork Fri Aug 16 08:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13765804 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 B7491127B57 for ; Fri, 16 Aug 2024 09:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799177; cv=none; b=iV5hMVWQ/fX0Q+Q6xAqGZf2wBIzFZ0/yesVmZ6DUDxReBH/DWgiwSkeMJTMoyOSE0uNpi/KIpEkC26l8d8oqHCtFQakCHKDwZAXl/yfc6p9bSyVlayVdPOnT7d61gzoMJJ0YqUX4SY3/X1yz5IVaxCwij8HQ00pFX6JBxHeYvuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799177; c=relaxed/simple; bh=DcY3cO/+xoHUqbbmKeCHKyLKH+vzXpg9AH0JEB0nNoA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aLeNq2PMBbh5hqwqYpHQ8ZMTJkdEf+jcT25bUMqTdy7ec5XCynD9G7/ajff5PbAjJu8ls01zYVkNxyLOzZFu+vubGoAz8ZhN59lnPQaxizYm6byViVVcz3ADhDQfVHGcbQpd8wBEPdSJxT/ECYPsBBluz4UqUjC0kf1QPi9cSpk= 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=Y9yfzK6n; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KbC+fHKx; arc=none smtp.client-ip=103.168.172.150 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="Y9yfzK6n"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KbC+fHKx" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id EC03D138FCD4; Fri, 16 Aug 2024 04:57:10 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 16 Aug 2024 04:57:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=1723798630; x=1723885030; bh=87Knv1FmB0 TrSoctDO/DybJ6vkkAy8aEIJMTZrp8lNk=; b=Y9yfzK6naatqsx8Zto8Uf0wAsc T4c63eA9+4LpKodGHYPQAavvWqSDkUVNY8nlrsaz5Sn/5Lvajp1xFij1rlJ9+GSj 6XngdO4zmxeqePMaY0DPV7iS6gYoPZaOiygPVDtRSQqzIWus694Ov2m+ieW8D6Pa OQhCgjkJIMazrrIIGLKs+jKjbX2IbgKHfOxPYEf38cIDyjsjs8a3g4TNcKLWSNDp Gp4t0r/TZD7qssA/gOObhWvKeTBwQTMo8nskPolnSUW8at6cR3TKSKiq2Qo1LBBR 7OWJRDEC23g+j26UIv3WzP1jL6nf62ZdUQHUqAhiIGNzVSmkJHGxWiFEHYrQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723798630; x=1723885030; bh=87Knv1FmB0TrSoctDO/DybJ6vkkA y8aEIJMTZrp8lNk=; b=KbC+fHKxb0tND1/AM4V7r9gqAdjnyfFl+GxmXKqzFf3T 6j8Owlbwc/Btct/40me5zHCUUzXTIR9NXbe3Jd469semE5jFqoRgrxqWYIw3OxfK x1KITncVS2z4myDFCWRbneSsq1NOpo3q2BY1MyTLRGJExeIUFBpB4WXZmcKcqrGD k8XfKthBgPeRutP+RWUYSDcmYD4Ptdtj9rJ/1ibBmMRh5XlaDug5tEAREB/Y82kE JwWlqTnnDpRtywpRV9epbYGj0TdyJf/1Fx0ZTBMLvRw9akymCqihIMknxT8wlRsr MABxTWRs/C3QTwUSG1idoGhgjc9huV6ZtPbuvYY6gQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshgrnhgurghlshestghruhhsthihthhoohhthhhprg hsthgvrdhnvghtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdp rhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlth hosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepshhstghhuhgsvghrthhhsehg mhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Aug 2024 04:57:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 826feaf5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 16 Aug 2024 08:56:46 +0000 (UTC) Date: Fri, 16 Aug 2024 10:57:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth , Justin Tobler , "brian m. carlson" , Junio C Hamano Subject: [PATCH v2 4/5] setup: make object format configurable via config Message-ID: <85086620628b1fa136ebf7a1c9e2f64ebdbc7b92.1723798388.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The object format for repositories can either be configured explicitly by passing the `--object-format=` option to git-init(1) or git-clone(1), or globally by setting the `GIT_DEFAULT_HASH` environment variable. While the former makes sense, setting random environment variables is not really a good user experience in case someone decides to only use SHA256 repositories. It is only natural to expect for a user that things like this can also be configured via their config. As such, introduce a new config "init.defaultObjectFormat", similar to "init.defaultBranch", that allows the user to configure the default object format when creating new repos. The precedence order now is the following, where the first one wins: 1. The `--object-format=` switch. 2. The `GIT_DEFAULT_HASH` environment variable. 3. The `init.defaultObjectFormat` config variable. This matches the typical precedence order we use in Git. We typically let the environment override the config such that the latter can easily be overridden on an ephemeral basis, for example by scripts. Signed-off-by: Patrick Steinhardt --- Documentation/config/init.txt | 5 ++++ setup.c | 40 ++++++++++++++++++++++++++++ t/t0001-init.sh | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/Documentation/config/init.txt b/Documentation/config/init.txt index af03acdbcb..d6f8b6e61b 100644 --- a/Documentation/config/init.txt +++ b/Documentation/config/init.txt @@ -8,3 +8,8 @@ endif::[] `init.defaultBranch`:: Allows overriding the default branch name e.g. when initializing a new repository. +`init.defaultObjectFormat`:: + Allows overriding the default object format for new repositories. See + `--object-format=` in linkgit:git-init[1]. Both the command line option + and the `GIT_DEFAULT_HASH` environment variable take precedence over + this config. diff --git a/setup.c b/setup.c index 5dfcdc99dd..770ad1393f 100644 --- a/setup.c +++ b/setup.c @@ -2284,11 +2284,49 @@ static void separate_git_dir(const char *git_dir, const char *git_link) write_file(git_link, "gitdir: %s", git_dir); } +struct default_format_config { + int hash; +}; + +static int read_default_format_config(const char *key, const char *value, + const struct config_context *ctx UNUSED, + void *payload) +{ + struct default_format_config *cfg = payload; + char *str = NULL; + int ret; + + if (!strcmp(key, "init.defaultobjectformat")) { + ret = git_config_string(&str, key, value); + if (ret) + goto out; + cfg->hash = hash_algo_by_name(str); + if (cfg->hash == GIT_HASH_UNKNOWN) + warning(_("unknown hash algorithm '%s'"), str); + goto out; + } + + ret = 0; +out: + free(str); + return ret; +} + static void repository_format_configure(struct repository_format *repo_fmt, int hash, enum ref_storage_format ref_format) { + struct default_format_config cfg = { + .hash = GIT_HASH_UNKNOWN, + }; + struct config_options opts = { + .respect_includes = 1, + .ignore_repo = 1, + .ignore_worktree = 1, + }; const char *env; + config_with_options(read_default_format_config, &cfg, NULL, NULL, &opts); + /* * If we already have an initialized repo, don't allow the user to * specify a different algorithm, as that could cause corruption. @@ -2304,6 +2342,8 @@ static void repository_format_configure(struct repository_format *repo_fmt, if (env_algo == GIT_HASH_UNKNOWN) die(_("unknown hash algorithm '%s'"), env); repo_fmt->hash_algo = env_algo; + } else if (cfg.hash != GIT_HASH_UNKNOWN) { + repo_fmt->hash_algo = cfg.hash; } repo_set_hash_algo(the_repository, repo_fmt->hash_algo); diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 795408e16c..cd34710f32 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -523,6 +523,56 @@ test_expect_success 'init honors --object-format' ' test_cmp expected actual ' +test_expect_success 'init honors init.defaultObjectFormat' ' + test_when_finished "rm -rf sha1 sha256" && + + test_config_global init.defaultObjectFormat sha1 && + ( + sane_unset GIT_DEFAULT_HASH && + git init sha1 && + git -C sha1 rev-parse --show-object-format >actual && + echo sha1 >expected && + test_cmp expected actual + ) && + + test_config_global init.defaultObjectFormat sha256 && + ( + sane_unset GIT_DEFAULT_HASH && + git init sha256 && + git -C sha256 rev-parse --show-object-format >actual && + echo sha256 >expected && + test_cmp expected actual + ) +' + +test_expect_success 'init warns about invalid init.defaultObjectFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultObjectFormat garbage && + + echo "warning: unknown hash algorithm ${SQ}garbage${SQ}" >expect && + git init repo 2>err && + test_cmp expect err && + + git -C repo rev-parse --show-object-format >actual && + echo $GIT_DEFAULT_HASH >expected && + test_cmp expected 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 && + git -C repo rev-parse --show-object-format >actual && + echo sha256 >expected +' + +test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultObjectFormat sha1 && + GIT_DEFAULT_HASH=sha256 git init repo && + git -C repo rev-parse --show-object-format >actual && + echo sha256 >expected +' + 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 && From patchwork Fri Aug 16 08:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13765800 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (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 D14F813A26B for ; Fri, 16 Aug 2024 09:06:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; cv=none; b=qiw3buZ/Zmk0WsLtcPSjB+DTAPLmYDhenJRx/L2WgxjfgBY5hP0n3SoDQnXDC8EDMB+o7H5I8OHioAOfqyEUZ6yRAfQlZOAkwTkskGim+KMp8mUsHBAiSST08ju3M12dgliNlzaQ1DQssXCZ2mBuRL7RLU5S3gHpxnNhehy9Idk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723799175; c=relaxed/simple; bh=4oBDUBX3b50zDdo5wHuL3SddDEDy9BfoqAp7ySWAyto=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kebBHdUU+yW7bYfj9Pf4c2TAbhWohPZeksGeGzPAbHOH8aOmv1p5QoW9qcUlmhEb++beunCC1WorZNccFClaeBQNtlDGaiWRZlRe7J8lgeXrNB+u+e98NCM7Kz7/0h6FUmX3Ge+CvHFYD1rrXk8a2imoOwkHwRu3cedUTAFFkvM= 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=Uggn2ZZ7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=p0wslXw6; arc=none smtp.client-ip=103.168.172.153 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="Uggn2ZZ7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="p0wslXw6" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 4ECB711503C9; Fri, 16 Aug 2024 04:57:15 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Fri, 16 Aug 2024 04:57:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=1723798635; x=1723885035; bh=5ZGO114fXb W3ixSpgeMS+E0spQQejFp5tHq5IKoPzbg=; b=Uggn2ZZ7oeBDaRKjTfzgqwT1rA ClJmizU8dN1jaYkv46PaC0BOAYzITKQFZK0CeTvB8oq60jn5Mip4COhQJHB8oJPq GF7+8XS1RiYTqTgzs3lDrbSfm+2Cau1YV6jkPCBDx5KRcKWEieg8I0a8A7DHRfv3 AbNwGRxZrrA4ZibrbY1+F7KqO6gQpACAXEzxlRc6NTsfopxumKqeCp7JTDRCuZgB FWbu4uxFyygYlCabyyA0LMa6+kkWrqQMnu3Zun7PbYQN9cWn8GXFyXN4JyHrCETh XKv2RmRa/DWqbvaX5vAyl/YPQaATgz2prmN/8N9F1smV3t37EHQc4SR2DfbQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723798635; x=1723885035; bh=5ZGO114fXbW3ixSpgeMS+E0spQQe jFp5tHq5IKoPzbg=; b=p0wslXw62Nfo8e2BsqdKxFMfVygHVNG48QzYtHWMEvnP V9jt8Py1TB7NecIa+sUT3ULzUcu2TMrvF1GfeC+vt5GYTDuOV8PkTRgdemTE4XCi APEyuFmAb2CKmMwMmbq6cgtbi55Qcjcr/C3TCffTd1M75aW74gc9WlroAUBl1OSJ FyKmP79QvUlfqaKxMKf4PlFR0d1AbObQRARADXdMMJOoOInEu/i36gM6qmTFSUHY 1s7fQ1xofvuXSb+/2G9pwdPVDGA6nBYaU1vBEsARgE0vIDpyipvo8cuXITgx7bCZ MF1+/XpihIDrdorItfgD9Y+vpSnKRr7kogRYa77Cwg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtkedgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepshhstghhuhgsvghrthhhsehgmhgrihhlrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehs rghnuggrlhhssegtrhhushhthihtohhothhhphgrshhtvgdrnhgvthdprhgtphhtthhope hgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehg mhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Aug 2024 04:57:14 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4a54b75c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 16 Aug 2024 08:56:51 +0000 (UTC) Date: Fri, 16 Aug 2024 10:57:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth , Justin Tobler , "brian m. carlson" , Junio C Hamano Subject: [PATCH v2 5/5] setup: make ref storage format configurable via config Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Similar to the preceding commit, introduce a new "init.defaultRefFormat" config that allows the user to globally set the ref storage format used by newly created repositories. Signed-off-by: Patrick Steinhardt --- Documentation/config/init.txt | 5 ++++ setup.c | 14 +++++++++++ t/t0001-init.sh | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/Documentation/config/init.txt b/Documentation/config/init.txt index d6f8b6e61b..e45b2a8121 100644 --- a/Documentation/config/init.txt +++ b/Documentation/config/init.txt @@ -13,3 +13,8 @@ endif::[] `--object-format=` in linkgit:git-init[1]. Both the command line option and the `GIT_DEFAULT_HASH` environment variable take precedence over this config. +`init.defaultRefFormat`:: + Allows overriding the default ref storage format for new repositories. + See `--ref-format=` in linkgit:git-init[1]. Both the command line + option and the `GIT_DEFAULT_REF_FORMAT` environment variable take + precedence over this config. diff --git a/setup.c b/setup.c index 770ad1393f..dd2251f655 100644 --- a/setup.c +++ b/setup.c @@ -2286,6 +2286,7 @@ static void separate_git_dir(const char *git_dir, const char *git_link) struct default_format_config { int hash; + enum ref_storage_format ref_format; }; static int read_default_format_config(const char *key, const char *value, @@ -2306,6 +2307,16 @@ static int read_default_format_config(const char *key, const char *value, goto out; } + if (!strcmp(key, "init.defaultrefformat")) { + ret = git_config_string(&str, key, value); + if (ret) + goto out; + cfg->ref_format = ref_storage_format_by_name(str); + if (cfg->ref_format == REF_STORAGE_FORMAT_UNKNOWN) + warning(_("unknown ref storage format '%s'"), str); + goto out; + } + ret = 0; out: free(str); @@ -2317,6 +2328,7 @@ static void repository_format_configure(struct repository_format *repo_fmt, { struct default_format_config cfg = { .hash = GIT_HASH_UNKNOWN, + .ref_format = REF_STORAGE_FORMAT_UNKNOWN, }; struct config_options opts = { .respect_includes = 1, @@ -2359,6 +2371,8 @@ static void repository_format_configure(struct repository_format *repo_fmt, if (ref_format == REF_STORAGE_FORMAT_UNKNOWN) die(_("unknown ref storage format '%s'"), env); repo_fmt->ref_storage_format = ref_format; + } else if (cfg.ref_format != REF_STORAGE_FORMAT_UNKNOWN) { + repo_fmt->ref_storage_format = cfg.ref_format; } repo_set_ref_storage_format(the_repository, repo_fmt->ref_storage_format); } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index cd34710f32..0178aa62a4 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -620,6 +620,19 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' test_cmp expect err ' +test_expect_success 'init warns about invalid init.defaultRefFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultRefFormat garbage && + + echo "warning: unknown ref storage format ${SQ}garbage${SQ}" >expect && + git init repo 2>err && + test_cmp expect err && + + git -C repo rev-parse --show-ref-format >actual && + echo $GIT_DEFAULT_REF_FORMAT >expected && + test_cmp expected actual +' + backends="files reftable" for format in $backends do @@ -650,6 +663,27 @@ do git -C refformat rev-parse --show-ref-format >actual && test_cmp expect actual ' + + test_expect_success "init with init.defaultRefFormat=$format" ' + test_when_finished "rm -rf refformat" && + test_config_global init.defaultRefFormat $format && + ( + sane_unset GIT_DEFAULT_REF_FORMAT && + git init refformat + ) && + + echo $format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' + + test_expect_success "--ref-format=$format overrides GIT_DEFAULT_REF_FORMAT" ' + test_when_finished "rm -rf refformat" && + GIT_DEFAULT_REF_FORMAT=garbage git init --ref-format=$format refformat && + echo $format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' done test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" ' @@ -660,6 +694,16 @@ test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" ' test_cmp expect actual ' +test_expect_success "GIT_DEFAULT_REF_FORMAT= overrides init.defaultRefFormat" ' + test_when_finished "rm -rf refformat" && + test_config_global init.defaultRefFormat files && + + GIT_DEFAULT_REF_FORMAT=reftable git init refformat && + echo reftable >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual +' + for from_format in $backends do test_expect_success "re-init with same format ($from_format)" '