From patchwork Thu Aug 15 07:59: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: 13764484 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 94CDA199248 for ; Thu, 15 Aug 2024 08:00:05 +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=1723708807; cv=none; b=pJ9ZLj81AJ/cFkDJX2zp4UutN3gagessR6GBu72cNUr6Uez5KYiBiITk74nFZcoV7T9znU4UgmjbQkAv4Qb3X6/cW6sym03PTjM9g7kVg2leRV+KANcElGnSv/akqmVJTjJagESQz2rVzcPMYjVVCcBNLeL0QVD6Cw9QpQpHzq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723708807; c=relaxed/simple; bh=vHbON6DJuratdtZPtnxXFhnY2EJKNntpkUDMlQ4pBWg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OGN+dNWSp0t8HK8eWn70zeAMwlPGPqVYxrzamy9gfJlACucURjay0AJYFlBHk/Vmqb0Ue4kHgGOxx0otR4WAcnIfwIWOXyFiDQAWUiDFbsGx2T153N9XhAw+Rba8SK0kV2D15kVhjrQabAjOsH3tjQU1EIJ7xHXwk1LF1iPVqL8= 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=ifxgdTXL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NZoGJsfq; 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="ifxgdTXL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NZoGJsfq" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A9C621151D1C; Thu, 15 Aug 2024 04:00:04 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 15 Aug 2024 04:00:04 -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=1723708804; x=1723795204; bh=hBcrE6obeU l8UAzwXmG1mqpoG637vytBkeS2Sr/rE5M=; b=ifxgdTXLx12636kJL0FIczWNbJ 57AV8JlIEp8B02SoUjbdeuoqvlFF7i2QRBS3IZdruzvdv/B2an0OzBO5OdaFNMnJ KGhNaID7MWo2kRWf3gEnPOX7px4fVIyaxMbL0HczjwyGqs8I0qz3JXCBVSrLOrtA iTMhFzzTh4DMwofPbbyM+dFNdmsQup+zeEH2F1dLaMzDb/bubiPlc0X8Snb8QfBw 5pR6qZFX1Ne9LhORaNFvmXA+msi2m50aLxQ2gqgS9DLuL083vjHupTEzz/HS/9LH TXATipuulyhDrNt3hvEtHQcHbEOJxRAyLniOYJzG6WlgEyfaBJqjBzDKvKqA== 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=1723708804; x=1723795204; bh=hBcrE6obeUl8UAzwXmG1mqpoG637 vytBkeS2Sr/rE5M=; b=NZoGJsfqIMYdHITfpy27NlVEDUqFzmdgLCyz3OHly1AN ASSzk6EP4vTZMXYzED0R+FfQDaJEiqzW33i0WD00AhkaEH33nnHBDzKEP+rGn0E+ tOJwYvJkiBDrS8PyQcoIWjLAj5QhKLjl7s8KiQXmTXLnvd3/C/hEJWNifsFqQKEe tFAJ1gbvTpCR9i4xNnj/IjlHQRjVyK08ZKKQJVzJmUEFif7+9nWW8iWPK8+HaV2g soZ/Wlnwt2yxRXTb5PmBELbkiwEZdvnkmesG9kHpXiQYdTrt6sY5SZFxzYbrw1Wp 7aHOXbYSlMPtQURB91Rsol44KieIZaZPAhaHXvaA4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddthedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsshgthhhusggvrhhthhesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Aug 2024 04:00:03 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 153acb75 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 15 Aug 2024 07:59:38 +0000 (UTC) Date: Thu, 15 Aug 2024 09:59:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth Subject: [PATCH 1/5] t0001: exercise initialization with ref formats more thoroughly Message-ID: <0d3844db32237983a1d85ced1a3b1b25fcd1d6eb.1723708417.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 Thu Aug 15 08:00:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13764485 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 B383F18CBF6 for ; Thu, 15 Aug 2024 08:00:06 +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=1723708808; cv=none; b=n+0dGCDYsPVHKAiES6jsrEUq5PnBUhjLVmVh0QdaOXAMSNo2J5N+P63fuX/fY0+D94U8oFDCxTw59OY1BYhQVZ7It0ItANW94oS2+K47++Kx0cZ+WbCUUN8VRb5VAyLmpMLPPQI4fhNzu0l+meX9VaGLQjBzfT5IuGKXW+jQC+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723708808; 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=DC/25JUoB+SQ5ZT33lIF6653l4GPj7KR2MEPKTSceDM1bHcUDo+f+K1tcSoTugakQEpGflwEt+R3KAUgk90iTSdNGufYMuWletDxWKhE8ISMxZAG0Z46rgmuEAOdC4pnynirEvYa8Tiz3bOXTvpd9eA7c52/WY4rOhCQAt10YYU= 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=eLb0yZjm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IPDsYrlK; 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="eLb0yZjm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IPDsYrlK" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id AB1A3139001F; Thu, 15 Aug 2024 04:00:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 15 Aug 2024 04:00:05 -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=1723708805; x=1723795205; bh=OXWalzTFc4 FNVw6teJewSP6UL1rKnyuTQvntJbAWPHY=; b=eLb0yZjmQO+R0QN5A1IWp0oBl1 UHUx/oaSd2WREaND3NM9cKFqt3BZjPgoUQZJNb93LIfhsH4dYqcEJzWObtSE+GF1 1sP7mVL0eLOATu901/PQWpdJ5dst5UM9R1n3g3WXnI8W8QpPG9NKSErZXfzdsyW4 CzAXqvUCI9FDZII8g5ekgnyfp/kwYyfuITe2/VzF0wDSDcN43XO4N2B+9SCibl+t iNoRXwSXbmCjf6lciww7/NhGAiXfbIoJ6DiOrnijHmDfWb+zugFkjJH+GG0926XQ tv9822KjLRxNWdfACvAC1VN12rwwfjEHYHYxiXnBxBQG5bHXceSuclodJEUg== 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=1723708805; x=1723795205; bh=OXWalzTFc4FNVw6teJewSP6UL1rK nyuTQvntJbAWPHY=; b=IPDsYrlKiwDcZHlAm+Af82BYf4gCH3rn2+jth7Sp7aeT qCR/UkV9FDFBxUJK1PNr/Y+cmBneMZ5NWxeWXVoeuGS4G0l1qZ9Uaau7FRm4WL8w leEWJO6ezXu1R/OkIaZDvR39ybhwAvlIIzYSg4XvK5sty+GYtUm8tUYAkT+RD1tt KQF9QDmEg/aDGJltcCJ4Lgc8xlvmDeVXSi7dg9r4cuZxwK2JQGvfUFwcx/xgiMpA 2tF4wP2/kmin89RedGSFfFUDqKD0+GNkfUbiJi6/jDHYysoSS865OYjGZPWk4a9N L76nm0BTPcGlzIaeacvUj768+/QZ4OOvarE+EYMRAw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddthedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepshhstghhuhgsvghrthhhsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Aug 2024 04:00:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b793aa09 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 15 Aug 2024 07:59:41 +0000 (UTC) Date: Thu, 15 Aug 2024 10:00:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth Subject: [PATCH 2/5] t0001: delete repositories when object format tests finish Message-ID: <6b0cefef6af3a94cd3b650b2ab06de489dbdaf20.1723708417.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 Thu Aug 15 08:00: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: 13764486 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 B7121198E78 for ; Thu, 15 Aug 2024 08:00:06 +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=1723708808; cv=none; b=JJEbfuKtY5FHi9l1rMk2KxqR7CO1FKrLDcsk4A5Us5xlm64BPO1nsMb5j55CmHFVKOJLC4n69j2aAOlBhXdUSlWPddNlOlSoY4iM7+ebcHv4v1m1yfyhm5uGYXwVNK9NskpGzn0cCX2FPGMDZJgVXhtAm/7M4w31REGWiTizqKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723708808; c=relaxed/simple; bh=HeduqKlyUIKFPDoQ8QA3Jph3jSzrJp6YcurxKNYy2OI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iwxJW5vZFKS528MHKBXhoY3sjdEZVMN2G5mcPSviSjCXJx1LwuzgUFV994iYS/IcQOhGr/FgsakwLt/BnbzAhWJoPqA7DUEFjaW3GqqEjJpSrAVMegZcJHkb6NlboNCJqUkMalEFpFJ0W8e8SOx2qAbzRG59uwKICMaUH5dcbiI= 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=RPDQakXd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MOV+qnTr; 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="RPDQakXd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MOV+qnTr" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BE9531151D14; Thu, 15 Aug 2024 04:00:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 15 Aug 2024 04:00:05 -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=1723708805; x=1723795205; bh=3wbx7NAwlx Czy0OTfl0tDedytPb7CUdUJ6W28XxBQgo=; b=RPDQakXdE7nISPeNfjAXnfshBu Qcg5QLVPjGwETyL487IW4BoCdpjHGULR3I9Co4hCjd6l3yGGS8F+sOENPKZJfyZU QLSqIagKxMNFlZF9EQ13hPR4QzdM4A0INEGBxf9cxQfVv6DNfsL/f3qS0HJBEIqr PPuosFYOzhMUmde5r9l8S5vuZqZ3hUclv+SdVRbaKH/CY37bpDa6Y7Gu7ygAUBuV w4HGwuJWIyWaqDQAQpoiY77DDRlGj6nf8f6wR6egIlZuerztEUm4j+SXHCRHlDp6 9yKNL5vD777wuZZjXc0cAfEDFFqqWstG8M3Z+EJvMqk4i+bx4jacCYe25NmA== 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=1723708805; x=1723795205; bh=3wbx7NAwlxCzy0OTfl0tDedytPb7 CUdUJ6W28XxBQgo=; b=MOV+qnTrSzScwMw4nvflt8+SjbXh0/7exz/1fSl2vLhI aDbaQoMqHNpzy/sykOAFKAh1pUuwrnlY5UokA/rl/wMA+6Yn9/drqSiEs3VxUYaj 6DD1jOEjHA9DLKDVlcVNpR/Q+Z0C2y+eKnfsnhiMmszxY5tIRGpE+XEqHnXqVGsN 2m9TwYiVMKYUmHqY35yMhEesnrt933VoRHkCfygjv7vooJO6PFy2FTR/+kXPcwbK HA1qTtPVgF+0aVg4M52l7tCmuaGlX4qKtI1K+HQP4bQvpIBndOabmLDtx1g9ZGoM kLpaMdoeiRn6cArYeZG/DFMCQU7oClyFtjE97bORdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddthedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepshhstghhuhgsvghrthhhsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Aug 2024 04:00:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6cf40be6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 15 Aug 2024 07:59:44 +0000 (UTC) Date: Thu, 15 Aug 2024 10:00:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth Subject: [PATCH 3/5] setup: merge configuration of repository formats Message-ID: <16f52b75d8972343776adb269da305e7406ff385.1723708417.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 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 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. 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 Thu Aug 15 08:00:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13764488 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 5CDCB19DFA9 for ; Thu, 15 Aug 2024 08:00:17 +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=1723708819; cv=none; b=d79SbzKCj55aParnpX2FiLI5JWXWGxbGUdBAKQN+CHGFBcs9ylSzVmXMlC6rv3Vc4lcNVDS3Bep+02vGNkPVmFk8zVFqrh0g6EuQNteUQUiuoCF2CAnVwwgdBbGlzvh5uScf82vlkveLhj2jIdxRnIQtrtedPdJJi4/67ADye6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723708819; c=relaxed/simple; bh=GV8TZwlpPamBnFRlnAMmJWUgbkPHpKXWWYhNmnr/NdY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XZ/rHTvCd8JDkJK4FWSox+m+CgIk1vSb/wwn6SOxz2Q873jlryj9b9tbZGZdM+NPp7puQAHAlOSDwLHyrVKUyPxqXHyyQ9veZKqAYEykL+i6S2fPbml7VYC0u81HPP71GTpDBGQlQ5iqL02cGs0Bc8xSOD3SgR1+sQ1xkilxC5s= 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=POilrCTr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AFk/ogTY; 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="POilrCTr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AFk/ogTY" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 502061151D1C; Thu, 15 Aug 2024 04:00:09 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 15 Aug 2024 04:00:09 -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=1723708809; x=1723795209; bh=QAHkKwx6uF DNyDabAsWzV+m3owbZBOH55F9xLP1j8Ig=; b=POilrCTr0zHhotbLBi5lUwBfl0 q1pk904SYA9Odf31ZdFZ4mqsNNRsWsd1PUXofZwldhhBVSOgmDUNw//i7v1cjuq1 A1CdmJIf21ifJOsoEwZRNlUtD1HG5g9NTSRY3WIGUvuy0IfZwl2Ck1JXiTwFYnUB 2h9FOGA4TRW/RUxdl/PqDrmRJqTV6nMYPv4pc4EkJsP5s1oIjVwDCW/pYOzLF4/F Z13tvLg2kXbup9X5OP5UhE8y2gGCaVqHAjsRvF9rV7nIRC7oAb6jskPooz4hubUf Juq2ZkwQhf6Ej30nFLEkgBLS0auK5s7Jn4ELG78IxHxYYX/k94BqI9AQxqzg== 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=1723708809; x=1723795209; bh=QAHkKwx6uFDNyDabAsWzV+m3owbZ BOH55F9xLP1j8Ig=; b=AFk/ogTYsA6bBk2e13oQJ87uqPyNO4ORQwc43ramSNQ6 u3ttXRmuCyN13qgbabV7BWYs0cy1ENZEJAn6H5DixxLLFccP+Z5+Xu56Ac9glZsW CLS1Fv9dyvaz9Uqs78ZBMYPJzWsFezmWtq7H7qn8CLQW4plBKSKSNy+ZzildwFAS kzSXreQbb1JsWu9scZRF5w9trATPTYew9HLnGugmgOj885suq2jpkv1gY15xtJbm YQro4znz41jzkcU1EBLkGufxK0dC+toz/WL43zUY3K4ymiGJIqTbvsfIhGL31RHw A2/6xWhdr6Xog1n90GPSRjl2Xi2lJ1jwVXoyr1spcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddthedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepshhstghhuhgsvghrthhhsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Aug 2024 04:00:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a88e3ee6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 15 Aug 2024 07:59:47 +0000 (UTC) Date: Thu, 15 Aug 2024 10:00:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth Subject: [PATCH 4/5] setup: make object 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: 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. 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 Thu Aug 15 08:00:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13764487 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 641EB19DFAB for ; Thu, 15 Aug 2024 08:00:17 +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=1723708819; cv=none; b=sKd/mN/5FUzwe9GncrIkbUSQ1sBEzy9sSKiF+44pRz3lfTp9nfPQsTtf7TiwzMZjPhmTkv2dEons9wQzTY+ZWVMEE2MYQMKBeq2Hattgcug2Mai2z0Y8U0NxzWM7U87hasyaOZAH2iiVPlWSKaBH3DzH9cNMcaIObhIANY98NnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723708819; c=relaxed/simple; bh=WHPEJkJn92AOSfXG46TnrB7VYRAEhz9IE4EbSX56Ty0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TG9JSMFo56KJOPWQDyO5WeSy2wK+dcllm7wYxVu8OIM46DFAmQZlgY37qri5bh033+aROleKDfOsUVlLOqAiqgEAvQeAUIH/4pafGCAXqOcU19WNLtSISxTtxvV/YOzDdR6KjofU/mTsaQ+UvOn9Xr/wyiwpSEsMG7AsOFXcN6U= 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=ZtWvv4fr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=axhj6gem; 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="ZtWvv4fr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="axhj6gem" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 52267138FFAE; Thu, 15 Aug 2024 04:00:14 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 15 Aug 2024 04:00:14 -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=1723708814; x=1723795214; bh=yq3F/B/N8p 46GAsTJCi6Olt/7R02w2IgCgohVaGAgso=; b=ZtWvv4frXBXIUHU5qEX3ngYXIK TFNQFci1a1OjpOsVb7AEgNs9u4MX9raRVIml1R2TKUYas50GTF2bRbqyiVcf8R34 osq7PDzK8lw+aR4BgtWJOrnyBl33tupZbQBPQ4kAwUHUL0ged8u07+EGV9zXQMzd rTh4lt7YIyK6CFxWV38I6k+NQg2DCcnJbjaNpWTSovoekeSO8wYyyeifHQL4XcTC 7nmZhTyvQPlpS5tMezdxal7WltdRzNcKKLdVd+ALDVtrAI6LjxYUAJTabkOeB6KU JKy6PM/PMxdnf0/pj5vQOvwOUJ3L2llljoAFjfSRCktPjV+oz62Kqnfmo/Ug== 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=1723708814; x=1723795214; bh=yq3F/B/N8p46GAsTJCi6Olt/7R02 w2IgCgohVaGAgso=; b=axhj6gemKwiYbmC8UgcuyLVvfabfF3ZydlrbSP3m+Nrm xfK397rYAdUn2uK4vQOyVlBKqUOOl8Ksxs/llJ0C8+MTvBAjUfi8MnCvqHCKZm0F OrZKN3MT7uvxximRLccyAe0WadWKlllWIXHDisw4KCtshi+dcw9eatZ82EZfmOVS 6aX4gKA+RmbtwoPm9+iP/D9Dt7Jo6JNVHoTrtPOosl48kS19A7Rjh+HAXS/hQzI7 /bQYk0LXb3N/Ee/GFQT+PET9tl2IhjzSuzXB5m+iZLzFf6Uk8uLGW43MRWNLva1H wU2qq3bpyqRO1n/5LPH90p4bTdG0IFEIFcUmor2EIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddthedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedvpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehsshgthhhusggvrhhthhesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Aug 2024 04:00:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8e4b751c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 15 Aug 2024 07:59:52 +0000 (UTC) Date: Thu, 15 Aug 2024 10:00:09 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Sebastian Schuberth Subject: [PATCH 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 as 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..9be97bcac8 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 object 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)" '