From patchwork Thu May 2 08:17:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651379 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 278DD2D04E for ; Thu, 2 May 2024 08:17:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637840; cv=none; b=nfIrqHzgw5NN0mda32rWv6ejytj2QQQhra4K4pml/ywut6oi7UKyRQ0srArUrRf3HGpJmdo4Ukc+Yg6r3I1Pnz9qLIW2yLK6KTgVc1TK8sJf2Rvn8IZcMHwygt7ODSaLnQFgo/fJ1dmKaMsHA7S6qm1sM1pRlCN+UdFW3iJtjjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637840; c=relaxed/simple; bh=96T3EiAUzPaISRFb3sl+nIzwuBQnTOxOJqZbpuSQMZg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q6T232o2EoGqAA+XG0DGb2rIU6W87XtcDA0yp8zEhmACeyrBTm2IYDHYiIxN2ReBHsd6Z8LW7HIAOe70/+VCNcpfJQeQDG1InaQg+h+432gKs0KjEIzO9K8ZMZNSHO4KPtRDGYzKSpq3nopsenGXDh9lG3i7QFyuVTN7zN+GYIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=is8cNbIp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UQPoWpT4; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="is8cNbIp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UQPoWpT4" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 468261380F7B; Thu, 2 May 2024 04:17:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 02 May 2024 04:17:18 -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=1714637838; x=1714724238; bh=Ot4gOESHFm HddF422iyQma4mBE+I+qGIL3TgEIJqAh8=; b=is8cNbIp6ECZG5Ex4tLLEDum5J 8Ec70+4cWHAEX+hDbvnl6llVFTRlBM7OTixcpgQ6gA1sPkfBdqUpE4TdkFZs5j2K 0ObEZ7ed/JDJhF8vmAJMHNhckLZTryFdq95UK8d3BHelXmy5TYRZEPqPwsvlT89N d/FkPpHYIjwubBK651TfxmSwvJjwySxAPs4FHxonzfZs9TvY8m7Feibn3ufW/7En kyvreOazHOhh7/JvMDdDXfLzSBl9JOQTa96JtHeC3XAXtjqwgd/hkY57ULvHKY2Q V+vv0ab1jJ1MbzUVuywr5VPnktGEJ6xC+p78q3ObIB/j63CItCUt2UufsM/A== 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=1714637838; x=1714724238; bh=Ot4gOESHFmHddF422iyQma4mBE+I +qGIL3TgEIJqAh8=; b=UQPoWpT4nVJ3Ddyd2ru7+vSDltJgFdqAyF40YlJ+O4lI Cbip/eDTQYSBt1fq2AEw7pUJMm8jJUjVOzOaP21CHj0ciV/+YDtkzDH3BB5JXpFd jyT9+XkIOdmXQaRxqqDlt4lvd2vZJTGXUAP/rAsS/pz7FVf93W8nIAuZx1EqDklh G6zGB0rXZGEzshNyIqsNLB3c1M2SnH5pOT5WNityHmqTHaMFbsWHtu/yYlFFrKqu KVBzZbg5Hhbmxn6CdfsUMuKJ6j7RMKR+bZRfWpEh/qVPLwDDLQBomXjTkGSuyWpt ku6c/L1roiNCTC6jAvTgeIU7bQUoMseUiSTMdOvRfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:16 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c2ee2f54 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:16:50 +0000 (UTC) Date: Thu, 2 May 2024 10:17:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 01/10] Documentation/glossary: redefine pseudorefs as special refs 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: Nowadays, Git knows about three different kinds of refs. As defined in gitglossary(7): - Regular refs that start with "refs/", like "refs/heads/main". - Pseudorefs, which live in the root directory. These must have all-caps names and must be a file that start with an object hash. Consequently, symbolic refs are not pseudorefs because they do not start with an object hash. - Special refs, of which we only have "FETCH_HEAD" and "MERGE_HEAD". This state is extremely confusing, and I would claim that most folks don't fully understand what is what here. The current definitions also have several problems: - Where does "HEAD" fit in? It's not a pseudoref because it can be a symbolic ref. It's not a regular ref because it does not start with "refs/". And it's not a special ref, either. - There is a strong overlap between pseudorefs and special refs. The pseudoref section for example mentions "MERGE_HEAD", even though it is a special ref. Is it thus both a pseudoref and a special ref? - Why do we even need to distinguish refs that live in the root from other refs when they behave just like a regular ref anyway? In other words, the current state is quite a mess and leads to wild inconsistencies without much of a good reason. The original reason why pseudorefs were introduced is that there are some refs that sometimes behave like a ref, even though they aren't a ref. And we really only have two of these nowadays, namely "MERGE_HEAD" and "FETCH_HEAD". Those files are never written via the ref backends, but are instead written by git-fetch(1), git-pull(1) and git-merge(1). They contain additional metadata that highlights where a ref has been fetched from or the list of commits that have been merged. This original intent in fact matches the definition of special refs that we have recently introduced in 8df4c5d205 (Documentation: add "special refs" to the glossary, 2024-01-19). Due to the introduction of the new reftable backend we were forced to distinguish those refs more clearly such that we don't ever try to read or write them via the reftable backend. In the same series, we also addressed all the other cases where we used to write those special refs via the filesystem directly, thus circumventing the ref backend, to instead write them via the backends. Consequently, there are no other refs left anymore which are special. Let's address this mess and return the pseudoref terminology back to its original intent: a ref that sometimes behave like a ref, but which isn't really a ref because it gets written to the filesystem directly. Or in other words, let's redefine pseudorefs to match the current definition of special refs. As special refs and pseudorefs are now the same per definition, we can drop the "special refs" term again. It's not exposed to our users and thus they wouldn't ever encounter that term anyway. Refs that live in the root of the ref hierarchy but which are not pseudorefs will be further defined in a subsequent commit. Signed-off-by: Patrick Steinhardt --- Documentation/glossary-content.txt | 40 +++++++++--------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index d71b199955..ca04768e3b 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -497,20 +497,18 @@ exclude;; unusual refs. [[def_pseudoref]]pseudoref:: - Pseudorefs are a class of files under `$GIT_DIR` which behave - like refs for the purposes of rev-parse, but which are treated - specially by git. Pseudorefs both have names that are all-caps, - and always start with a line consisting of a - <> followed by whitespace. So, HEAD is not a - pseudoref, because it is sometimes a symbolic ref. They might - optionally contain some additional data. `MERGE_HEAD` and - `CHERRY_PICK_HEAD` are examples. Unlike - <>, these files cannot - be symbolic refs, and never have reflogs. They also cannot be - updated through the normal ref update machinery. Instead, - they are updated by directly writing to the files. However, - they can be read as if they were refs, so `git rev-parse - MERGE_HEAD` will work. + A ref that has different semantics than normal refs. These refs can be + accessed via normal Git commands but may not behave the same as a + normal ref in some cases. ++ +The following pseudorefs are known to Git: + + - "`FETCH_HEAD`" is written by linkgit:git-fetch[1] or linkgit:git-pull[1]. It + may refer to multiple object IDs. Each object ID is annotated with metadata + indicating where it was fetched from and its fetch status. + + - "`MERGE_HEAD`" is written by linkgit:git-merge[1] when resolving merge + conflicts. It contains all commit IDs which are being merged. [[def_pull]]pull:: Pulling a <> means to <> it and @@ -638,20 +636,6 @@ The most notable example is `HEAD`. An <> used to temporarily store the contents of a <> working directory and the index for future reuse. -[[def_special_ref]]special ref:: - A ref that has different semantics than normal refs. These refs can be - accessed via normal Git commands but may not behave the same as a - normal ref in some cases. -+ -The following special refs are known to Git: - - - "`FETCH_HEAD`" is written by linkgit:git-fetch[1] or linkgit:git-pull[1]. It - may refer to multiple object IDs. Each object ID is annotated with metadata - indicating where it was fetched from and its fetch status. - - - "`MERGE_HEAD`" is written by linkgit:git-merge[1] when resolving merge - conflicts. It contains all commit IDs which are being merged. - [[def_submodule]]submodule:: A <> that holds the history of a separate project inside another repository (the latter of From patchwork Thu May 2 08:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651380 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 D4A4D2D04E for ; Thu, 2 May 2024 08:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637844; cv=none; b=iEq3DDy5Ph7vhsI6JsdoNRVYB6Nkj2mr8hY2G8RzLni96RuzP9wreRoFCcu2OJJ4Ugzb6IZHpLG0sHvvxwvO7HrrVpgDozC0Z4L/QaEFuPDXyf9hxfTQuKsJj2I+TEX77yIdnJLdKs39eXpOsaJKyry0L3bTkmWmBM3MhfdiOTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637844; c=relaxed/simple; bh=kaPR3KzjQxklruE4IAb4rvGmn9h4iozBx/uOprBhSTk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rDjBN4iK9n1tIKBmKBhiVmZs1H47WXwLaiFkD0d7K+WE7tmprIBEDUcAYUxA9qZ3JWV+Ls94Wct1pxgkTtRqXs1piWg5iHgaXUyIl+PsMs5KVJCYA7I8SBUA+k27BPA/XnvL2YL2DXGy/6ALqbGKB4QonU/6LZIYlm0mWEf7P9c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=QW5ikPhq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SdQ1bJa9; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="QW5ikPhq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SdQ1bJa9" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0AA0D1140112; Thu, 2 May 2024 04:17:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 02 May 2024 04:17:22 -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=1714637842; x=1714724242; bh=J24HJ/+P2+ Pnz+Wvv23RmRL2ggKgoPOG9pDR5AyEXJ4=; b=QW5ikPhqdVTt2EuWMpj3UHfaEZ nEDAHF0bH+BBXg5CSXquZDVPvIdamTYUmfhWBnYBWGdhc26UT1fWTFwYh0mByKUg VjsisFnEGEpM/TQ0TVoFeLiaG5a0DptetYJ0xc4rcDDapOieQYre4yR8PD8s7aD3 CjNMZyRLSdsNURlGGJUVBMQf+ndtGk1edL5AoND3vl4KGpyXyYnnBkQB8WMfFdPm oe3ZBMKf/zUk5aBkVStTrqochXItJ6PQkICXP4aBTP49YCEaZB0t8h+wyBPOQcC9 Z956ZhOJV3W2D3ZlkVy/9iHKlekpVF8NjEY09QAiwOP6Fv8FuyjJ8Y3vdJpQ== 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=1714637842; x=1714724242; bh=J24HJ/+P2+Pnz+Wvv23RmRL2ggKg oPOG9pDR5AyEXJ4=; b=SdQ1bJa99t9+OTzNZrqN2ThIR57nKK1STEuxaQie9sjw bGmxziX4UyEgouBOcs9N7Kxivut0Fvc9c+bQU5CSDYiSjTJAY4r5Hip7twlJXD/X kgyVQCng+XEfhuMk30aNoKGJkIg9M12PLmmZKXQIGes8csyQ1Q8DKRt1DO/iCTjS fdtCMOLQkMt2FFpCyK1eB93jsOkXc9snLz+FZ8/0wdEmdN4TdtW6PmrBgemrKUgH gfeVYKl6qfemSrIb/F9h8c06AifLp80Uea+E/S1FYpkKQB0Le3wsN52H4w3VMpG4 qu46Uc8CnsO2ga8RZ/DPfGgalVEeyLvYcml4KwZ1Kw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:20 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 65aeba0d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:16:55 +0000 (UTC) Date: Thu, 2 May 2024 10:17:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 02/10] Documentation/glossary: clarify limitations of pseudorefs Message-ID: <66ac0461328409fd880ab1dce92dae5c012ceea8.1714637671.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: Clarify limitations that pseudorefs have: - They can be read via git-rev-parse(1) and similar tools. - They are not surfaced when iterating through refs, like when using git-for-each-ref(1). They are not refs, so iterating through refs should not surface them. - They cannot be written via git-update-ref(1) and related commands. Signed-off-by: Patrick Steinhardt --- Documentation/glossary-content.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index ca04768e3b..b464b926d5 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -498,8 +498,8 @@ exclude;; [[def_pseudoref]]pseudoref:: A ref that has different semantics than normal refs. These refs can be - accessed via normal Git commands but may not behave the same as a - normal ref in some cases. + read via normal Git commands, but cannot be written to by commands like + linkgit:git-update-ref[1]. + The following pseudorefs are known to Git: From patchwork Thu May 2 08:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651381 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 8983F3219F for ; Thu, 2 May 2024 08:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637849; cv=none; b=VsKtmQ+46Y17KqmyXnsniLeRZZlzZgPfOKPyR/OvF1qjirz11mT9tV1DrWe1SZj6LqdGo7majd91T3/rUwdRvMjrBMMHTnE2sR4UglsHGRJpkkUQUu+tyINMXXB9XZn2JWcJ3zW70vvoKLuhpTNu7Wju5edR2hVTFbyFa/eN1Zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637849; c=relaxed/simple; bh=RonLS48SSZtjpGEkLBiYee+bvKSEIKkNF7dYon1g4Vg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=t/rL0gEvy77fGnw3vWIbbo6GCcqVeZ2Lc4FMKJPuIIwh5pwb1Kx8DtBIYBiu7AbwmNq2zZtvBP+iv/hZ6bkkBvZexcpJ51/gvet2fdREkWtI0xaQoJC7fo0FFkN2gG2Ul4NAr5fHGaTo+WKBUSEA+Uxnies8ICAiKCOKlKBLAxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=voggLHWm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RGHLtQTf; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="voggLHWm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RGHLtQTf" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 93D1613805A3; Thu, 2 May 2024 04:17:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 02 May 2024 04:17:26 -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=1714637846; x=1714724246; bh=0119PLtSYI aLAg1hqdVX8y+M++1Mg7bgMYNr0PwD6wU=; b=voggLHWmJyTMa90eD31RuQRvlj p2wBaH4FmwKvsfDb3ODZ0g+l/uKi6D06HxOmeQr2W0f6XPSmBI41nPjgrtQdKQhS rj9hrz1fRkAaKrtcuTHOtXLfO6xp1/bl8yz4DgUy4UuRpdbNPFzyAD+iYsi9ClrW 5kdXzj48R619wy9SpwqPy0WvkFqP6zQ7QKnt1TzvqTiJKHDqlQGxINn9w255C4Tr 5dvqYiH/3P4YIXFaxpIhQZRY5LXRLnZWml1jrGiUOpK6zeAgqp8p4Z8IDV09KVaS QsQWfGumDVBTzYmOZelX4vujpfbUmQppL6waIXQihxMvksMyctLNDYgUWxvg== 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=1714637846; x=1714724246; bh=0119PLtSYIaLAg1hqdVX8y+M++1M g7bgMYNr0PwD6wU=; b=RGHLtQTfG5iP45D4/ZuouZ311NaQfyOvFV5iGzxukWoP 3e0qnVwitnqGt6KahMr7SpyODT9udvAov4YCkMTeyEXX5x6GSAYq82Px8F0iP7WO b+FqrQ8ThyUL/fy5QzFmcXZCJGG6RLcjVl5shly4nOYkUUF5PjPYsg+l5YMWUl+q xYf5PolZaRFasWYOiGb2/FK+45FooXzZWutJoJCKSuiO6jqpkurjjvx9ewc8u5bt tCfPIkOOUttJzc7kxI9NRQnIJrzIMEUsEkTSfTW2H9mUVnUTAuv/q9dCUhtdZo7s LLMRSwZj0QlIkrqGAXOLbjINYBMj9wOy+AFxbJHlNQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:25 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id da26fcbe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:16:59 +0000 (UTC) Date: Thu, 2 May 2024 10:17:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 03/10] Documentation/glossary: define root refs as refs Message-ID: <243d616101350c03b1b536f9e26d05ca749d08d5.1714637671.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: Except for the pseudorefs MERGE_HEAD and FETCH_HEAD, all refs that live in the root of the ref hierarchy behave the exact same as normal refs. They can be symbolic refs or direct refs and can be read, iterated over and written via normal tooling. All of these refs are stored in the ref backends, which further demonstrates that they are just normal refs. Extend the definition of "ref" to also cover such root refs. The only additional restriction for root refs is that they must conform to a specific naming schema. Signed-off-by: Patrick Steinhardt --- Documentation/glossary-content.txt | 32 +++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index b464b926d5..d6cf907a19 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -550,20 +550,38 @@ The following pseudorefs are known to Git: to the result. [[def_ref]]ref:: - A name that begins with `refs/` (e.g. `refs/heads/master`) - that points to an <> or another - ref (the latter is called a <>). + A name that that points to an <> or + another ref (the latter is called a <>). For convenience, a ref can sometimes be abbreviated when used as an argument to a Git command; see linkgit:gitrevisions[7] for details. Refs are stored in the <>. + The ref namespace is hierarchical. -Different subhierarchies are used for different purposes (e.g. the -`refs/heads/` hierarchy is used to represent local branches). +Ref names must either start with `refs/` or be located in the root of +the hierarchy. For the latter, their name must follow these rules: + -There are a few special-purpose refs that do not begin with `refs/`. -The most notable example is `HEAD`. + - The name consists of only upper-case characters or underscores. + + - The name ends with "`_HEAD`" or is equal to "`HEAD`". ++ +There are some irregular refs in the root of the hierarchy that do not +match these rules. The following list is exhaustive and shall not be +extended in the future: ++ + - AUTO_MERGE + + - BISECT_EXPECTED_REV + + - NOTES_MERGE_PARTIAL + + - NOTES_MERGE_REF + + - MERGE_AUTOSTASH ++ +Different subhierarchies are used for different purposes. For example, +the `refs/heads/` hierarchy is used to represent local branches whereas +the `refs/tags/` hierarchy is used to represent local tags.. [[def_reflog]]reflog:: A reflog shows the local "history" of a ref. In other words, From patchwork Thu May 2 08:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651382 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 0D7202E3E9 for ; Thu, 2 May 2024 08:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637853; cv=none; b=kSZQ3+MsI+48FRlc2FXQzkDnfLOLeoQx7sg9Ue9MbWpkYrMb80L9FDihYmghpVIyjdNG3XcAcgaPm9kn0yhxf3c1UmezDRWfwTZ4MAEziWjqYrAL6Q8dhFrfrvpzKHa+1AWuGlOxi9S6seApay/LFFtmMvK3yU4xNA+kU2BZsS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637853; c=relaxed/simple; bh=mgxoTfQm3uwga8G7FEzpicj8iUmpCfLlVgLaXHSJ6Lk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ifo2d1o13DyEAQ9sYppZvsP034QNB5hLKzYbWbXHmi4KUV4OLgzu3yM4/d5+r4Nz7VFd82hxGr+wYomERuwnQjqODxy1Yn3/q2ZwTqSyHCgeVR+8PgKROGRbf8hMaMrX9da6uQ8c0VThsWU/3p5NVnVtiIJD2CE9CCZDkTpYeZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=onXOY2SN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QNGNeFtH; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="onXOY2SN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QNGNeFtH" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 2C06513805A3; Thu, 2 May 2024 04:17:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 02 May 2024 04:17:31 -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=1714637851; x=1714724251; bh=+X2gC9Z3xy pKpkOEw05EIW/b/AJZ5G2ZSOb1uWdHJPs=; b=onXOY2SNfw7gvit7PR4IW/E57z MvjvkckTwZht1DdsO91lFlisCxW344pFj5b66sb0LmiUL41u70XA+8tUBeTV2u1W VIXXIrUyOfyjZkUXJheQcRmJV3QjzaCGrqloq0HKiQSasI9aO07IhYxIrIy/YpVV SR8359zb1tMlEv1IeMt4Uc90BbwtbXwdus0LEmEjFawRvensk0hhRGhk28pYhDVw +wkm3J8YhRfCACDH0EwvC1fKDWn3rrEK+uKqp5D5qwWhTGuOxqbRjvHeV8QYcpdR a9TTsPWl4iSor3ox0gASTFWanls32+bq1Lak9ZOQzrh3vEflkMhuLCF+29bA== 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=1714637851; x=1714724251; bh=+X2gC9Z3xypKpkOEw05EIW/b/AJZ 5G2ZSOb1uWdHJPs=; b=QNGNeFtHVVChNQYJS1I3D4yU5yXbQOBOLw7tw4ph/jHA UxF6F/0hUqw2fkFgl389aKexj/V16Cg2f1hODnYfUMg1iKl4Xoigi3E/KgtxAhXB 4xDFejkbEAXKObJytk3B16UQInjXRpDzqOFelF/htqajy4LdS1L5IbrdF7WGlRF+ 0G9Ey4rhHcz5pMpZHeLnR/ksRdabiTZZrmFDcO6ft27BXxTqSKMu1VpTr0xBltDW 1kuNw/wu02pQJrjYDmWKxYfhdtuNJhXrwxSZ2d+rHkuZ90KG999P8P+FrpdrPx2l 8oHMAaqGYO7vy1utbWK51uE/rxl9rh+FCkUIeokDRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:29 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 11c55b75 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:04 +0000 (UTC) Date: Thu, 2 May 2024 10:17:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 04/10] refs: rename `is_pseudoref()` to `is_root_ref()` Message-ID: <0a116f9d11413e0f16d60d963d5b41b8fc6b7420.1714637671.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: Rename `is_pseudoref()` to `is_root_ref()` to adapt to the newly defined terminology in our gitglossary(7). Signed-off-by: Patrick Steinhardt --- ref-filter.c | 2 +- refs.c | 14 +++++++------- refs.h | 28 +++++++++++++++++++++++++++- refs/files-backend.c | 2 +- refs/reftable-backend.c | 2 +- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 59ad6f54dd..361beb6619 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2756,7 +2756,7 @@ static int ref_kind_from_refname(const char *refname) return ref_kind[i].kind; } - if (is_pseudoref(get_main_ref_store(the_repository), refname)) + if (is_root_ref(get_main_ref_store(the_repository), refname)) return FILTER_REFS_PSEUDOREFS; return FILTER_REFS_OTHERS; diff --git a/refs.c b/refs.c index 55d2e0b2cb..0a4acde3ca 100644 --- a/refs.c +++ b/refs.c @@ -844,7 +844,7 @@ int is_per_worktree_ref(const char *refname) starts_with(refname, "refs/rewritten/"); } -static int is_pseudoref_syntax(const char *refname) +static int is_root_ref_syntax(const char *refname) { const char *c; @@ -860,9 +860,9 @@ static int is_pseudoref_syntax(const char *refname) return 1; } -int is_pseudoref(struct ref_store *refs, const char *refname) +int is_root_ref(struct ref_store *refs, const char *refname) { - static const char *const irregular_pseudorefs[] = { + static const char *const irregular_root_refs[] = { "AUTO_MERGE", "BISECT_EXPECTED_REV", "NOTES_MERGE_PARTIAL", @@ -872,7 +872,7 @@ int is_pseudoref(struct ref_store *refs, const char *refname) struct object_id oid; size_t i; - if (!is_pseudoref_syntax(refname)) + if (!is_root_ref_syntax(refname)) return 0; if (ends_with(refname, "_HEAD")) { @@ -882,8 +882,8 @@ int is_pseudoref(struct ref_store *refs, const char *refname) return !is_null_oid(&oid); } - for (i = 0; i < ARRAY_SIZE(irregular_pseudorefs); i++) - if (!strcmp(refname, irregular_pseudorefs[i])) { + for (i = 0; i < ARRAY_SIZE(irregular_root_refs); i++) + if (!strcmp(refname, irregular_root_refs[i])) { refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, &oid, NULL); @@ -902,7 +902,7 @@ int is_headref(struct ref_store *refs, const char *refname) } static int is_current_worktree_ref(const char *ref) { - return is_pseudoref_syntax(ref) || is_per_worktree_ref(ref); + return is_root_ref_syntax(ref) || is_per_worktree_ref(ref); } enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref, diff --git a/refs.h b/refs.h index d278775e08..d0374c3275 100644 --- a/refs.h +++ b/refs.h @@ -1051,7 +1051,33 @@ extern struct ref_namespace_info ref_namespace[NAMESPACE__COUNT]; */ void update_ref_namespace(enum ref_namespace namespace, char *ref); -int is_pseudoref(struct ref_store *refs, const char *refname); +/* + * Check whether the reference is an existing root reference. + * + * A root ref is a reference that lives in the root of the reference hierarchy. + * These references must conform to special syntax: + * + * - Their name must be all-uppercase or underscores ("_"). + * + * - Their name must end with "_HEAD". + * + * - Their name may not contain a slash. + * + * There is a special set of irregular root refs that exist due to historic + * reasons, only. This list shall not be expanded in the future: + * + * - AUTO_MERGE + * + * - BISECT_EXPECTED_REV + * + * - NOTES_MERGE_PARTIAL + * + * - NOTES_MERGE_REF + * + * - MERGE_AUTOSTASH + */ +int is_root_ref(struct ref_store *refs, const char *refname); + int is_headref(struct ref_store *refs, const char *refname); #endif /* REFS_H */ diff --git a/refs/files-backend.c b/refs/files-backend.c index a098d14ea0..0fcb601444 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -351,7 +351,7 @@ static void add_pseudoref_and_head_entries(struct ref_store *ref_store, strbuf_addstr(&refname, de->d_name); dtype = get_dtype(de, &path, 1); - if (dtype == DT_REG && (is_pseudoref(ref_store, de->d_name) || + if (dtype == DT_REG && (is_root_ref(ref_store, de->d_name) || is_headref(ref_store, de->d_name))) loose_fill_ref_dir_regular_file(refs, refname.buf, dir); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 1cda48c504..5a5e64fe69 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -356,7 +356,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator) */ if (!starts_with(iter->ref.refname, "refs/") && !(iter->flags & DO_FOR_EACH_INCLUDE_ROOT_REFS && - (is_pseudoref(&iter->refs->base, iter->ref.refname) || + (is_root_ref(&iter->refs->base, iter->ref.refname) || is_headref(&iter->refs->base, iter->ref.refname)))) { continue; } From patchwork Thu May 2 08:17:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651383 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 A88A02E3E9 for ; Thu, 2 May 2024 08:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637858; cv=none; b=Lyis5tpbSL2MRBCAAWgtErzIP5XlUe+ZmE2CTZQSk0ZR8yPFc8vSUUJlrG1PRf2CbwIZQekc1x0HyHfn06vQlbNYuJHi9hYqk04269/f2cYW66NG0AV2eBfQWL9b/77im92DeFxfX9nomFlrNn5zpalm2Z1qibVk+bNjvOgKlCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637858; c=relaxed/simple; bh=l/TkPV5aZKja7LGwU4b3Mdc7EGWEG4tVqG80o4y3MbQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fBWSUyan+Oy/2/iK7QI5QoYCI02yFq+ntKftEKgkTuw/sGjjTImqs2HBu1NS6a6JfQB4Mgf6vkNp846Adw12qtq7n0a5LcYnaKouuTfas+w03Xi6srAarQdN5pRs2Ff+cJpFLUj/L370e/czMkfTMmBh7ARvULhAyG2057vgU3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=WBD3oIUT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fIgiAcro; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="WBD3oIUT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fIgiAcro" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B8D051140112; Thu, 2 May 2024 04:17:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 02 May 2024 04:17:35 -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=1714637855; x=1714724255; bh=cev4B/NJ23 DjTS5ifC3cZMkwuMmEkHFCAUrqCQ6XhOs=; b=WBD3oIUT0tBP4LZwUKDFurehDH rjvcMKSfrN6sHdZUPbafnMlAi/3oOKcXfHGhZlGZRreU4sfnZ8kT5BMafkmsFhoV xcr7FlP+UgffVJicOMXNUTkdw0brwnK1PW0EU+IbGEhSLrvLmZj5So8I84y+QNQ7 4nvcYxX6H6593s1HfqVlwn90Cg7GatWcXYhYMw2u9YlWVi8z0slx+RQwgq/mhKg9 jYRVnk92v6Tg+TY+jnyy7FRYsy4hfMbJ/KphkLa6UIM3CBuBIhfUSAZaEcF6noKl zniOAVm6j6m4K9JIDtjldGjVq51IftqMyZeTIZpDTQZXm1i8OvUxsGIKfNQw== 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=1714637855; x=1714724255; bh=cev4B/NJ23DjTS5ifC3cZMkwuMmE kHFCAUrqCQ6XhOs=; b=fIgiAcroaTbFZPpLA36sBI7aIqqYWNzvFO1bZY2fGsfy nhcKHvRfM9ns6KlvJ4VK7Cu7MJhzZmsdoUxvLRwb4VLxIOSWq10ZE4+RI/hVlhWp Iovher5qJkCrCteKpXbr0kZNxLr8JcyVDixf4Xsh1WukA00F0+pZevGYlx1awx2c o1B50oWgeNFF9bI0yTKf9JfJmp9UHEIIIEDZHS3ukKEyTmt8NQE9WH4U5vmc/kcG eq6pHZ5i4HhNsdiOna77PvhtmdZV9RohyAfV83yaVAmHe4g12wRd1rkX3zZjdscY vwyxTFIZWrncESY+0aSu6hQnPFfIVgGZVLwppPhVag== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:34 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 85c6cb00 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:08 +0000 (UTC) Date: Thu, 2 May 2024 10:17:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 05/10] refs: refname `is_special_ref()` to `is_pseudo_ref()` Message-ID: <484a0856bc947c3b0b05bf1ad3a9379ba4feeff3.1714637671.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: Rename `is_special_ref()` to `is_pseudo_ref()` to adapt to the newly defined terminology in our gitglossary(7). Note that in the preceding commit we have just renamed `is_pseudoref()` to `is_root_ref()`, where there may be confusion for in-flight patch series that add new calls to `is_pseudoref()`. In order to intentionally break such patch series we have thus picked `is_pseudo_ref()` instead of `is_pseudoref()` as the new name. Signed-off-by: Patrick Steinhardt --- refs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/refs.c b/refs.c index 0a4acde3ca..6266f77474 100644 --- a/refs.c +++ b/refs.c @@ -1876,13 +1876,13 @@ static int refs_read_special_head(struct ref_store *ref_store, return result; } -static int is_special_ref(const char *refname) +static int is_pseudo_ref(const char *refname) { /* - * Special references are refs that have different semantics compared - * to "normal" refs. These refs can thus not be stored in the ref - * backend, but must always be accessed via the filesystem. The - * following refs are special: + * Pseudorefs are refs that have different semantics compared to + * "normal" refs. These refs can thus not be stored in the ref backend, + * but must always be accessed via the filesystem. The following refs + * are pseudorefs: * * - FETCH_HEAD may contain multiple object IDs, and each one of them * carries additional metadata like where it came from. @@ -1891,17 +1891,17 @@ static int is_special_ref(const char *refname) * heads. * * Reading, writing or deleting references must consistently go either - * through the filesystem (special refs) or through the reference + * through the filesystem (pseudorefs) or through the reference * backend (normal ones). */ - static const char * const special_refs[] = { + static const char * const pseudo_refs[] = { "FETCH_HEAD", "MERGE_HEAD", }; size_t i; - for (i = 0; i < ARRAY_SIZE(special_refs); i++) - if (!strcmp(refname, special_refs[i])) + for (i = 0; i < ARRAY_SIZE(pseudo_refs); i++) + if (!strcmp(refname, pseudo_refs[i])) return 1; return 0; @@ -1912,7 +1912,7 @@ int refs_read_raw_ref(struct ref_store *ref_store, const char *refname, unsigned int *type, int *failure_errno) { assert(failure_errno); - if (is_special_ref(refname)) + if (is_pseudo_ref(refname)) return refs_read_special_head(ref_store, refname, oid, referent, type, failure_errno); From patchwork Thu May 2 08:17:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651384 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 2957517984 for ; Thu, 2 May 2024 08:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637863; cv=none; b=N79cNWy5TutF2sBaSCs7kz0gY9aLEEbCuPKzl0lFvxfhhW1dpyGrVkjoTIHYNokhgwo/BITfROHN/BKIGBhqOQ6QRxZQNk0wm+ouaIGlwIsZDPQ5//XHGQAuBmi+Ki+wUMdE4RfWrMahjOI/ZOmz+2jLKPPyYcQT25X0efKhkSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637863; c=relaxed/simple; bh=p6I93s65eUTSA9lEi1hWEwCemUu/VeoLAcHgnUWegCo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZJBdHwo+EsTyviz3Jwq+WaCxY9IFyq4mFQSOCzH1zKaFGVc8u/CY8iBRtoI6AjJpJB3nInHqRw6PKpEh8SPHgllj+bkAPwAJmlnfFhIYUoU4QatL5bgK9lkndCWteGKMJVIgt5H9i02s7WGCiysjairkGSIpTdNtDTbNQGSMlFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=V8nZvjJw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PiM3y9yx; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="V8nZvjJw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PiM3y9yx" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 62218114011E; Thu, 2 May 2024 04:17:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 02 May 2024 04:17:41 -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=1714637861; x=1714724261; bh=bBOqlcLJty soYVrJa+NhEqgYyOkOa9QMiapxPVAJRxo=; b=V8nZvjJwi1n5YEh/2tOSScQX17 jrtWHYS5JzjQIBpzY4UI4e73WsmKmBGx4xuCeQBOPDg9mNKF7IjkCijCpEpmegJd 7EUfkuTRz5GBQIzbXkJ5y3QGoZdrli71S9PQ1Bm5ZjfRrpke0aAZQ+wt44I6Ug6U VeJKedRnAsXEFGOHCEqYcStlEvo2ipIMeheh2fYq9B+ud9KxIlCvywTXDhsUM/xg 1gm0KDL0Pzu6iHY8iJLjoJ9EGKoT4np5fSuScd66rnKEn//5//pH2q4Sr9DaCzr9 uD/elBSoiiTGYfz7KiOcKmt/s8sIXqt6+OQLL6xMMJirs1IFiSEOY4hxnrfg== 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=1714637861; x=1714724261; bh=bBOqlcLJtysoYVrJa+NhEqgYyOkO a9QMiapxPVAJRxo=; b=PiM3y9yxyXBLgB5m2E4wpIKr6QeRaQRXHRQ50ZzEueH8 Q1bQFkDp+sS243AxpcbsDb28CPfXix1q5TLZ/Ik06D/xcfbOEvnUoNBkmUyxN44X W1MyoHAaf0LKEwaG3aF74CqNGTeyQweyt0PItIabIc8S6augyk9y2T1v3rydHsn+ 5DolkmESVVUyrHI0vpnRh6t0JTQdz95Magm6VUJsZ6qILftei3hBiItaDPNWGT7E o/32SrGLa1/GXuImdqMBIOCU3q7PWKJJRaGoiDd92x9ZWtXugaVLRSrMjk0l3z9A ZwZez1/uArevpKWxaL7a9meN26TvO1+7tYnnvmJKdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:39 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 10c29cc6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:14 +0000 (UTC) Date: Thu, 2 May 2024 10:17:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 06/10] refs: classify HEAD as a root ref 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: Root refs are those refs that live in the root of the ref hierarchy. Our old and venerable "HEAD" reference falls into this category, but we don't yet classify it as such in `is_root_ref()`. Adapt the function to also treat "HEAD" as a root ref. This change is safe to do for all current callers: - `ref_kind_from_refname()` already handles "HEAD" explicitly before calling `is_root_ref()`. - The "files" and "reftable" backends explicitly called both `is_root_ref()` and `is_headref()`. This change should thus essentially be a no-op. Signed-off-by: Patrick Steinhardt --- refs.c | 2 ++ refs.h | 6 +++++- refs/files-backend.c | 3 +-- refs/reftable-backend.c | 3 +-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/refs.c b/refs.c index 6266f77474..5b89e83ad7 100644 --- a/refs.c +++ b/refs.c @@ -874,6 +874,8 @@ int is_root_ref(struct ref_store *refs, const char *refname) if (!is_root_ref_syntax(refname)) return 0; + if (is_headref(refs, refname)) + return 1; if (ends_with(refname, "_HEAD")) { refs_resolve_ref_unsafe(refs, refname, diff --git a/refs.h b/refs.h index d0374c3275..4ac454b0c3 100644 --- a/refs.h +++ b/refs.h @@ -1059,7 +1059,8 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref); * * - Their name must be all-uppercase or underscores ("_"). * - * - Their name must end with "_HEAD". + * - Their name must end with "_HEAD". As a special rule, "HEAD" is a root + * ref, as well. * * - Their name may not contain a slash. * @@ -1078,6 +1079,9 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref); */ int is_root_ref(struct ref_store *refs, const char *refname); +/* + * Check whether the reference is "HEAD" and whether it exists. + */ int is_headref(struct ref_store *refs, const char *refname); #endif /* REFS_H */ diff --git a/refs/files-backend.c b/refs/files-backend.c index 0fcb601444..ea927c516d 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -351,8 +351,7 @@ static void add_pseudoref_and_head_entries(struct ref_store *ref_store, strbuf_addstr(&refname, de->d_name); dtype = get_dtype(de, &path, 1); - if (dtype == DT_REG && (is_root_ref(ref_store, de->d_name) || - is_headref(ref_store, de->d_name))) + if (dtype == DT_REG && is_root_ref(ref_store, de->d_name)) loose_fill_ref_dir_regular_file(refs, refname.buf, dir); strbuf_setlen(&refname, dirnamelen); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 5a5e64fe69..41555fcf64 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -356,8 +356,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator) */ if (!starts_with(iter->ref.refname, "refs/") && !(iter->flags & DO_FOR_EACH_INCLUDE_ROOT_REFS && - (is_root_ref(&iter->refs->base, iter->ref.refname) || - is_headref(&iter->refs->base, iter->ref.refname)))) { + is_root_ref(&iter->refs->base, iter->ref.refname))) { continue; } From patchwork Thu May 2 08:17:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651385 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 AA6E336B0D for ; Thu, 2 May 2024 08:17:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637868; cv=none; b=aB6PtoG7pegUYvr+dUiYd6tI83Py1IIg6Xx3t36/nP0eypdvcfUIHjl09CKnAoRllIWPYJHVuM7b8csn3bT//Ys54F140B2uXD8SbOdMKlZlDDfdPAqGS+kMnVYXk6H3jfdaCIoaGb9d6GI3jWBIXn2d01SPQNkGZbofzG20bY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637868; c=relaxed/simple; bh=ZgXg1CpgHxDCZtX0yhEKqFu6jsPVqMBWTsqho0ewmfE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RJpxS6ogdWXj6GGw9SF0Sm9yAPv5JI8zDdMZuk7oW/uYxOqrBBT1r9801JN+hRTSVAEPJq9GEEoPSmhpCRAuJLCKwt3bWV2bKh6MgFdBLKBunjcOPYrztUSVRh8hjK2pm1fJA4qIkrJceAnDvWwN1lEVVwDMrl0NaCsgBOCq1aI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=WEsJHjLN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U/dXPDwB; arc=none smtp.client-ip=103.168.172.152 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="WEsJHjLN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U/dXPDwB" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0348E1140112; Thu, 2 May 2024 04:17:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 02 May 2024 04:17:46 -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=1714637866; x=1714724266; bh=nBpjVZ8uYT w+41G0z4MBjdNaXf+WL/x+K0mN+Zg7x2U=; b=WEsJHjLNP10nKAgd6JtjPGd2RG aiMGvS0nHZBGGiim2cES/fZgyTFQEDS84UAr9vgT1oFYLaO52ZmZyCqxsuL2fr5V Rpfzsv0aYqtK1A7LIyzxlGQSrUfq8ZRd4+kDqk88YNor72F6pA1FH40Xi2tcy4Om Wblv9Vtll1+NhRnXhNppVd7F3qJw3go4M+CtWAPSSH1Dw4uU4ewSrcZLhf5nNFa4 U0Jp/szpOt7w4UHUXQQYps3hXb3WEfADoGOYUTrp6s4hvEDp5RSESbFpGdWgKufM k0phuexTmWPVEDrTE0vA0op1IrQeJpi1V3g0937VSlCP58XgBlxdBNfW1KRA== 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=1714637866; x=1714724266; bh=nBpjVZ8uYTw+41G0z4MBjdNaXf+W L/x+K0mN+Zg7x2U=; b=U/dXPDwBxScuInJdQRDWXOFZ3Zg1BY/R7NHoROhmipjz /jDpEWlovEqkGcfg3f1ECFfbsNreqEnMVVPIW1ROLoODAqI/bDApD0HjXsyZm4Ax YwDMVrp332N3yX+QMvvjLmuX6w0YDhCo0sQfWvnYHVrX/YwYpo3O70zlv2b2+/UP //ZvLVkZRs96avALMoBxVGXio3ouuUeOK7Nex60mxBCmrov82CrWPqj3mTDD1AqE QCDuZZqpuC02I1/PtPcExaM8lgsUxvksw0JPlbYCGiMRW223t4KbgKIFQPKgal0O OZ23wz+xQlVrz/SFhmGBHh+0ULPhpAmg1l0JkdoTmQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:44 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f52e4df4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:18 +0000 (UTC) Date: Thu, 2 May 2024 10:17:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 07/10] refs: root refs can be symbolic refs Message-ID: <92a71222e1067ca4ce9ecaaa555d78d0cce0d9d0.1714637671.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: Before this patch series, root refs except for "HEAD" and our special refs were classified as pseudorefs. Furthermore, our terminology clarified that pseudorefs must not be symbolic refs. This restriction is enforced in `is_root_ref()`, which explicitly checks that a supposed root ref resolves to an object ID without recursing. This has been extremely confusing right from the start because (in old terminology) a ref name may sometimes be a pseudoref and sometimes not depending on whether it is a symbolic or regular ref. This behaviour does not seem reasonable at all and I very much doubt that it results in anything sane. Furthermore, the behaviour is different to `is_headref()`, which only checks for the ref to exist. While that is in line with our glossary, this inconsistency only adds to the confusion. Last but not least, the current behaviour can actually lead to a segfault when calling `is_root_ref()` with a reference that either does not exist or that is a symbolic ref because we never initialized `oid`. Let's loosen the restrictions in accordance to the new definition of root refs, which are simply plain refs that may as well be a symbolic ref. Consequently, we can just check for the ref to exist instead of requiring it to be a regular ref. Add a test that verifies that this does not change user-visible behaviour. Namely, we still don't want to show broken refs to the user by default in git-for-each-ref(1). What this does allow though is for internal callers to surface dangling root refs when they pass in the `DO_FOR_EACH_INCLUDE_BROKEN` flag. Signed-off-by: Patrick Steinhardt --- refs.c | 50 ++++++++++++++++++++++++---------- t/t6302-for-each-ref-filter.sh | 17 ++++++++++++ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/refs.c b/refs.c index 5b89e83ad7..ca9844bc3e 100644 --- a/refs.c +++ b/refs.c @@ -869,7 +869,10 @@ int is_root_ref(struct ref_store *refs, const char *refname) "NOTES_MERGE_REF", "MERGE_AUTOSTASH", }; - struct object_id oid; + struct strbuf referent = STRBUF_INIT; + struct object_id oid = { 0 }; + int failure_errno, ret = 0; + unsigned int flags; size_t i; if (!is_root_ref_syntax(refname)) @@ -877,30 +880,49 @@ int is_root_ref(struct ref_store *refs, const char *refname) if (is_headref(refs, refname)) return 1; + /* + * Note that we cannot use `refs_ref_exists()` here because that also + * checks whether its target ref exists in case refname is a symbolic + * ref. + */ if (ends_with(refname, "_HEAD")) { - refs_resolve_ref_unsafe(refs, refname, - RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - &oid, NULL); - return !is_null_oid(&oid); + ret = !refs_read_raw_ref(refs, refname, &oid, &referent, + &flags, &failure_errno); + goto done; } - for (i = 0; i < ARRAY_SIZE(irregular_root_refs); i++) + for (i = 0; i < ARRAY_SIZE(irregular_root_refs); i++) { if (!strcmp(refname, irregular_root_refs[i])) { - refs_resolve_ref_unsafe(refs, refname, - RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - &oid, NULL); - return !is_null_oid(&oid); + ret = !refs_read_raw_ref(refs, refname, &oid, &referent, + &flags, &failure_errno); + goto done; } + } - return 0; +done: + strbuf_release(&referent); + return ret; } int is_headref(struct ref_store *refs, const char *refname) { - if (!strcmp(refname, "HEAD")) - return refs_ref_exists(refs, refname); + struct strbuf referent = STRBUF_INIT; + struct object_id oid = { 0 }; + int failure_errno, ret = 0; + unsigned int flags; - return 0; + /* + * Note that we cannot use `refs_ref_exists()` here because that also + * checks whether its target ref exists in case refname is a symbolic + * ref. + */ + if (!strcmp(refname, "HEAD")) { + ret = !refs_read_raw_ref(refs, refname, &oid, &referent, + &flags, &failure_errno); + } + + strbuf_release(&referent); + return ret; } static int is_current_worktree_ref(const char *ref) { diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh index 948f1bb5f4..92ed8957c8 100755 --- a/t/t6302-for-each-ref-filter.sh +++ b/t/t6302-for-each-ref-filter.sh @@ -62,6 +62,23 @@ test_expect_success '--include-root-refs with other patterns' ' test_cmp expect actual ' +test_expect_success '--include-root-refs omits dangling symrefs' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit initial && + git symbolic-ref DANGLING_HEAD refs/heads/missing && + cat >expect <<-EOF && + HEAD + $(git symbolic-ref HEAD) + refs/tags/initial + EOF + git for-each-ref --format="%(refname)" --include-root-refs >actual && + test_cmp expect actual + ) +' + test_expect_success 'filtering with --points-at' ' cat >expect <<-\EOF && refs/heads/main From patchwork Thu May 2 08:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651386 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 776823A1DD for ; Thu, 2 May 2024 08:17:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637873; cv=none; b=uaTcABHQXEyPUXrm7dv9fJlLQsa+8KHW4b/P1NIx9tLoaFlHhxtJDaLJ0rNsuaBQ2wwawYbg4rht4IgTIssJKLY8cKKSTbWcR1/QzZP66hqEU0apRtugrSMUmxVQWqKzAtBJmnPo/XATkjURhsybtCiNj7gb23uCUjs9a6sdY5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637873; c=relaxed/simple; bh=S4O6Yay9cNqdXSoK7mfNo3oVlYGySVoSdlVaDEh8Blo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h8PXWjoW0uzOmfbx8d6nWCKmNeBDH7HY8uYF6x/5UGQm+ynhsCWvbXP4s0qRr0yueFv2MWFYHdS4+vIf4mR9sFf2sbdYPWViNMEHTv+QSk8sL/wfq3WCdXcznOHVk39bk6Wu4PJrdm1UUuH0dXZtTcIwJ45uaoYyD7rLWBYQMU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=Nxi/RT5G; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hYIG/5kO; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="Nxi/RT5G"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hYIG/5kO" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 9725B138106C; Thu, 2 May 2024 04:17:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 02 May 2024 04:17:50 -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=1714637870; x=1714724270; bh=YkYuKXRsbS XBO64kv5vbwSwe5izugFNKJfPphax26tM=; b=Nxi/RT5GnFSDJRIdfKWpswcJKB iqlocsr+WgR/OFP/yxa5k/xt/HMZJDlg3qjVkInid79/aPurCZAoamP+ZsMxIcVH Tvfi8C6kd3kFksfhDoi1SioIAI2N/MBWK+a1aE188KJiALKFPVA9bWA+hukkJmJ8 P9xgP21RPsvswWQcyMB9tNdAmicxASKMII/V917IFtZHVOPq6ZeHbQ6jrR/Hntw9 fzvE5P1AkrYZ4FLzVH26O7hRfvEvlV7SJpUvAVaSgOaz/GtFWwy6GmnL9IPAdp8B uCn+gwkinO3G+pWrPzyEiXDyg+sUj7pK/Pt7KwcqmON3KBkQ4fJHVR/pmkLw== 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=1714637870; x=1714724270; bh=YkYuKXRsbSXBO64kv5vbwSwe5izu gFNKJfPphax26tM=; b=hYIG/5kOv6RtazqWQRZP4Z0KCRImsXlWc4YwdVrg8y7a COKVPjGSGmKBHEiQGgsU0j2bEU1cen7U0G+dVfRNrbuxBEF+jpRAfx/0fVG9cEQ2 0qMVeEiN6hyNuS4+y5ZTMEgp2ZPaAPbbV4QZgTB1q6o4a9ZIywVwQ4+Uc64s7N37 m/KrQx/0Kn3NIoO9woV+s7bQFlSYM5jo/bAveoIsfFldL/X3Z7Mu19Wc9pmyxQCc 6ikH44fhikOlN0mUd57zdvgHz7HDBdKTO+W0iZotGbjqEs49GPT+u+n3IQJNCAUu 1e4T3wdo67NfUfZdhCzVS88cS2l6fBH2boL6TSemWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:49 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f77b849a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:23 +0000 (UTC) Date: Thu, 2 May 2024 10:17:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 08/10] refs: pseudorefs are no refs Message-ID: <8bd52e536329bb3ad1e5dfc34b42de0902511275.1714637671.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 `is_root_ref()` function will happily clarify a pseudoref as a root ref, even though pseudorefs are no refs. Next to being wrong, it also leads to inconsistent behaviour across ref backends: while the "files" backend accidentally knows to parse those pseudorefs and thus yields them to the caller, the "reftable" backend won't ever see the pseudoref at all because they are never stored in the "reftable" backend. Fix this issue by filtering out pseudorefs in `is_root_ref()`. Signed-off-by: Patrick Steinhardt --- refs.c | 65 +++++++++++++++++----------------- t/t6302-for-each-ref-filter.sh | 17 +++++++++ 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/refs.c b/refs.c index ca9844bc3e..dec9dbdc2d 100644 --- a/refs.c +++ b/refs.c @@ -844,6 +844,37 @@ int is_per_worktree_ref(const char *refname) starts_with(refname, "refs/rewritten/"); } +static int is_pseudo_ref(const char *refname) +{ + /* + * Pseudorefs are refs that have different semantics compared to + * "normal" refs. These refs can thus not be stored in the ref backend, + * but must always be accessed via the filesystem. The following refs + * are pseudorefs: + * + * - FETCH_HEAD may contain multiple object IDs, and each one of them + * carries additional metadata like where it came from. + * + * - MERGE_HEAD may contain multiple object IDs when merging multiple + * heads. + * + * Reading, writing or deleting references must consistently go either + * through the filesystem (pseudorefs) or through the reference + * backend (normal ones). + */ + static const char * const pseudo_refs[] = { + "FETCH_HEAD", + "MERGE_HEAD", + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(pseudo_refs); i++) + if (!strcmp(refname, pseudo_refs[i])) + return 1; + + return 0; +} + static int is_root_ref_syntax(const char *refname) { const char *c; @@ -875,7 +906,8 @@ int is_root_ref(struct ref_store *refs, const char *refname) unsigned int flags; size_t i; - if (!is_root_ref_syntax(refname)) + if (!is_root_ref_syntax(refname) || + is_pseudo_ref(refname)) return 0; if (is_headref(refs, refname)) return 1; @@ -1900,37 +1932,6 @@ static int refs_read_special_head(struct ref_store *ref_store, return result; } -static int is_pseudo_ref(const char *refname) -{ - /* - * Pseudorefs are refs that have different semantics compared to - * "normal" refs. These refs can thus not be stored in the ref backend, - * but must always be accessed via the filesystem. The following refs - * are pseudorefs: - * - * - FETCH_HEAD may contain multiple object IDs, and each one of them - * carries additional metadata like where it came from. - * - * - MERGE_HEAD may contain multiple object IDs when merging multiple - * heads. - * - * Reading, writing or deleting references must consistently go either - * through the filesystem (pseudorefs) or through the reference - * backend (normal ones). - */ - static const char * const pseudo_refs[] = { - "FETCH_HEAD", - "MERGE_HEAD", - }; - size_t i; - - for (i = 0; i < ARRAY_SIZE(pseudo_refs); i++) - if (!strcmp(refname, pseudo_refs[i])) - return 1; - - return 0; -} - int refs_read_raw_ref(struct ref_store *ref_store, const char *refname, struct object_id *oid, struct strbuf *referent, unsigned int *type, int *failure_errno) diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh index 92ed8957c8..163c378cfd 100755 --- a/t/t6302-for-each-ref-filter.sh +++ b/t/t6302-for-each-ref-filter.sh @@ -52,6 +52,23 @@ test_expect_success '--include-root-refs pattern prints pseudorefs' ' test_cmp expect actual ' +test_expect_success '--include-root-refs pattern does not print special refs' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + test_commit initial && + git rev-parse HEAD >.git/MERGE_HEAD && + git for-each-ref --format="%(refname)" --include-root-refs >actual && + cat >expect <<-EOF && + HEAD + $(git symbolic-ref HEAD) + refs/tags/initial + EOF + test_cmp expect actual + ) +' + test_expect_success '--include-root-refs with other patterns' ' cat >expect <<-\EOF && HEAD From patchwork Thu May 2 08:17:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13651387 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 F12D22E3E9 for ; Thu, 2 May 2024 08:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637877; cv=none; b=Go24Gnx9MFbrpdgIWH0SFFc867cX5z9Zmam8xTfJqfI3Mspab80aIBQwKmbDQwR9qd10eMAm/YP5QLLL+rh6vxQvkzG5SiGFKB07TYPq+TYc+uTEzj/jf6l1WobF/rzImo5hBpsSAxIGatKUg07xaoa7FKQl4uC2GyGTG50BoqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637877; c=relaxed/simple; bh=ZklXTU0glvzDK5etBExuHEr0oZ1Od1Ti3Ls6oB8aaRo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=npfXmj2VTxsXRyoZe4gHr2PJHx6Wr03MerE1vuz1O5DozprxoCpRDJSdTg18O0XH9o+j+iMMrE7xxJggNNgliMMnr3yCtWRrzHTu8ay96hxSAir90nWROGl4GuVrfwaUdduvBaCBR02aEhi9k5FOn9UnKwk2n39UL2h4XOwMPw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=gCnASpJL; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ym0+xefP; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="gCnASpJL"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ym0+xefP" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 3BAF61380F8B; Thu, 2 May 2024 04:17:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 02 May 2024 04:17: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=1714637875; x=1714724275; bh=iU/a/E/Jl2 +caygpcVRY45r8NSADAyTVEnpC6lOGncc=; b=gCnASpJL9LR9Pf+CIkgwCLhFg0 toxKKb85ujvAxX41sWp/vFYqNpnGp+Iw+lBg9eumyQ7GeVXBKfv0vJkrG6JbDyBo e8Dk9DIYR8v2LQJsQ2K9u3ZYO7Kc6W+Q/Uy08Wj8iTHp7Jv+3mvxV3criMkJnUYg 8lIM7jsG/ZuBnMw9Z33wrqG4h3WWGbytQn77yQa0ZQCjsHCuLyII6hLf3rzSDNIv 2p0oA9s4dOGQWdkIWyduWtIIiAoKS68Uo/QgbXVE+ixgwa5I1Ib+IJ+gD/+r6pSn 4Dx4mb8mhaBhaLpwnq85uat5U3uHuLrpx8MUwWJo/1FFnPnyUKKYpa3yGzug== 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=1714637875; x=1714724275; bh=iU/a/E/Jl2+caygpcVRY45r8NSAD AyTVEnpC6lOGncc=; b=Ym0+xefPAJP3m9TudBmFbIeqe1guN6Dt5pwA+2ltfgzQ p1XjSBO0O9Q9VPjNpC1RdsSVkQFDjKp7maGZ/bm2B+//uTsCp6BQRfpAkRBlHorU 7A9/Ob7BhatdBPj7ZVJz/7QA7oP2IULKaqFSE8/iL3A6n3xa6Tt2qg+S9Kpq/i0V as5+6L7vgFSHNaEFW+3yqO2ydqcr7kiOkxpg3Jg+nr6SoPJ2Q840z9GOZtIyucfG go+yNCHfiLQ1e5gDvgFBz3yhNVipOyCkRfTT2tXNWu0XmAxn76Z+a8/vJr5ywPQU Yb8hWB/AZRwV1Z3jCu+1QOoI32yEwRnrTowrHZPegw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:53 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id ddfae1a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:28 +0000 (UTC) Date: Thu, 2 May 2024 10:17:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 09/10] ref-filter: properly distinuish pseudo and root refs 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 ref-filter interfaces currently define root refs as either a detached HEAD or a pseudo ref. Pseudo refs aren't root refs though, so let's properly distinguish those ref types. Signed-off-by: Patrick Steinhardt --- builtin/for-each-ref.c | 2 +- ref-filter.c | 16 +++++++++------- ref-filter.h | 4 ++-- refs.c | 18 +----------------- refs.h | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 919282e12a..5517a4a1c0 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -98,7 +98,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) } if (include_root_refs) - flags |= FILTER_REFS_ROOT_REFS; + flags |= FILTER_REFS_ROOT_REFS | FILTER_REFS_DETACHED_HEAD; filter.match_as_path = 1; filter_and_format_refs(&filter, flags, sorting, &format); diff --git a/ref-filter.c b/ref-filter.c index 361beb6619..d72113edfe 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2628,7 +2628,7 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter, each_ref_fn cb, void *cb_data) { - if (filter->kind == FILTER_REFS_KIND_MASK) { + if (filter->kind & FILTER_REFS_ROOT_REFS) { /* In this case, we want to print all refs including root refs. */ return refs_for_each_include_root_refs(get_main_ref_store(the_repository), cb, cb_data); @@ -2756,8 +2756,10 @@ static int ref_kind_from_refname(const char *refname) return ref_kind[i].kind; } - if (is_root_ref(get_main_ref_store(the_repository), refname)) + if (is_pseudo_ref(refname)) return FILTER_REFS_PSEUDOREFS; + if (is_root_ref(get_main_ref_store(the_repository), refname)) + return FILTER_REFS_ROOT_REFS; return FILTER_REFS_OTHERS; } @@ -2794,11 +2796,11 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct /* * Generally HEAD refs are printed with special description denoting a rebase, * detached state and so forth. This is useful when only printing the HEAD ref - * But when it is being printed along with other pseudorefs, it makes sense to - * keep the formatting consistent. So we mask the type to act like a pseudoref. + * But when it is being printed along with other root refs, it makes sense to + * keep the formatting consistent. So we mask the type to act like a root ref. */ - if (filter->kind == FILTER_REFS_KIND_MASK && kind == FILTER_REFS_DETACHED_HEAD) - kind = FILTER_REFS_PSEUDOREFS; + if (filter->kind & FILTER_REFS_ROOT_REFS && kind == FILTER_REFS_DETACHED_HEAD) + kind = FILTER_REFS_ROOT_REFS; else if (!(kind & filter->kind)) return NULL; @@ -3072,7 +3074,7 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref * When printing all ref types, HEAD is already included, * so we don't want to print HEAD again. */ - if (!ret && (filter->kind != FILTER_REFS_KIND_MASK) && + if (!ret && !(filter->kind & FILTER_REFS_ROOT_REFS) && (filter->kind & FILTER_REFS_DETACHED_HEAD)) head_ref(fn, cb_data); } diff --git a/ref-filter.h b/ref-filter.h index 0ca28d2bba..27ae1aa0d1 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -23,9 +23,9 @@ FILTER_REFS_REMOTES | FILTER_REFS_OTHERS) #define FILTER_REFS_DETACHED_HEAD 0x0020 #define FILTER_REFS_PSEUDOREFS 0x0040 -#define FILTER_REFS_ROOT_REFS (FILTER_REFS_DETACHED_HEAD | FILTER_REFS_PSEUDOREFS) +#define FILTER_REFS_ROOT_REFS 0x0080 #define FILTER_REFS_KIND_MASK (FILTER_REFS_REGULAR | FILTER_REFS_DETACHED_HEAD | \ - FILTER_REFS_PSEUDOREFS) + FILTER_REFS_PSEUDOREFS | FILTER_REFS_ROOT_REFS) struct atom_value; struct ref_sorting; diff --git a/refs.c b/refs.c index dec9dbdc2d..50d679b7e7 100644 --- a/refs.c +++ b/refs.c @@ -844,24 +844,8 @@ int is_per_worktree_ref(const char *refname) starts_with(refname, "refs/rewritten/"); } -static int is_pseudo_ref(const char *refname) +int is_pseudo_ref(const char *refname) { - /* - * Pseudorefs are refs that have different semantics compared to - * "normal" refs. These refs can thus not be stored in the ref backend, - * but must always be accessed via the filesystem. The following refs - * are pseudorefs: - * - * - FETCH_HEAD may contain multiple object IDs, and each one of them - * carries additional metadata like where it came from. - * - * - MERGE_HEAD may contain multiple object IDs when merging multiple - * heads. - * - * Reading, writing or deleting references must consistently go either - * through the filesystem (pseudorefs) or through the reference - * backend (normal ones). - */ static const char * const pseudo_refs[] = { "FETCH_HEAD", "MERGE_HEAD", diff --git a/refs.h b/refs.h index 4ac454b0c3..8255989e7e 100644 --- a/refs.h +++ b/refs.h @@ -1084,4 +1084,22 @@ int is_root_ref(struct ref_store *refs, const char *refname); */ int is_headref(struct ref_store *refs, const char *refname); +/* + * Pseudorefs are refs that have different semantics compared to + * "normal" refs. These refs can thus not be stored in the ref backend, + * but must always be accessed via the filesystem. The following refs + * are pseudorefs: + * + * - FETCH_HEAD may contain multiple object IDs, and each one of them + * carries additional metadata like where it came from. + * + * - MERGE_HEAD may contain multiple object IDs when merging multiple + * heads. + * + * Reading, writing or deleting references must consistently go either + * through the filesystem (pseudorefs) or through the reference + * backend (normal ones). + */ +int is_pseudo_ref(const char *refname); + #endif /* REFS_H */ From patchwork Thu May 2 08:17: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: 13651388 Received: from fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 B895536134 for ; Thu, 2 May 2024 08:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.148 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637882; cv=none; b=attCoood1PSy6ikXCxuyWDiMFgv7CngM7jtHcJvBaTmb6lFksIhFg5HILhebonhq4rDoY0cIkY4gqRzJejc0mw1uWaNyQtXIlyg9n1MJQb6MyjHLhWccJcKuxXLmpaDVQIygei0Lp/JdFIr8ZjsRh0atond7cDAmRqtVHNzX0z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714637882; c=relaxed/simple; bh=OpyRhZy8z8+HE4yPto3zXnjczv4ZRnD5pfMdUeXpFJE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gO7RqH3ZxUcUR9hwxx6JpOiHNTteyFrOH1BZU/l9UEPZdXlAERJ/tvGhsisPKbRBggNN9NjN99T1ldYd8m3R9QcAGKpFhQlzalOOeXEnSw3D3PPGW57i2wdV7si0bEoUUeWzYy7Qqz4s98ZWee0hTUOtUr7YbPlpLx7AluN+sJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=aGZtthe8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XPGMt3J6; arc=none smtp.client-ip=103.168.172.148 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="aGZtthe8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XPGMt3J6" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id CB2041380F8B; Thu, 2 May 2024 04:17:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 02 May 2024 04:17: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=1714637879; x=1714724279; bh=nhxc17gc2d kvk2vzCIu5bkyJ4TnJlnLGRMfHEKsAodg=; b=aGZtthe8BxjrqhQoS+jA7mKoTo vzbTPU3aQHI3vNIw0a4reS6ozQzWVcT86j1NMI8xoGaKwbktXgCqdkGbZj1yuAkF /YxbwkJLa3Yv//mGfQtQkZOkbz39AEC7E4QXaM0hiZeCTgZvmFlVqV6okImm5EWL BFrHyZfpBiwLozMAMgJucip6Ld3Eq49czbDKObFpIDFgoTd71SfKcfQVRyjnqJch pR9bVio1XYtzkeARXkfCWPG5rFZM+VlE28w7ylWq9XTNgeuvmxEviVF98Ng2gJEo sO5bTFTBy7SaFBHCd7F0Ld7iux6sZIDR5E9BgrvSK5xKg/RKV8exq7dT321g== 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=1714637879; x=1714724279; bh=nhxc17gc2dkvk2vzCIu5bkyJ4TnJ lnLGRMfHEKsAodg=; b=XPGMt3J6jF2FvC38m+NA4Dyo6NTw45orP+8mx6Ljv2V8 GZzofFf1jFCa8T3nfTgPksz16HNFwuWijVNYH6zeafBuo88h3Z5Hzj6OeV2QsN1h 2zXTjsOOKHmdynLnRNDmoT0Igd2DB+kaYeQoDcc47v4RNz5OXM5I+TG7afmM2a/c CGHrHfBQqoM1IDeny1mKjqQzR232kw9siwMa7vD9KT3i+bitMzmMRIdLPkOGkGs7 e4CY1h2xf83DQExUDb9PSYLw6IBKjhjHj4gSn02RcQGDh1J4pRDXP3KoloB7nN80 OWoRJl/zm1sD0sUkF5lmqj2XkeQOrdExLag4VsQ8Zg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddukedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 2 May 2024 04:17:58 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id eb8866d2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 May 2024 08:17:32 +0000 (UTC) Date: Thu, 2 May 2024 10:17:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk Subject: [PATCH v3 10/10] refs: refuse to write pseudorefs Message-ID: <6956fccced4d082c7fc304fb154147838ec43205.1714637671.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: Pseudorefs are not stored in the ref database as by definition, they carry additional metadata that essentially makes them not a ref. As such, writing pseudorefs via the ref backend does not make any sense whatsoever as the ref backend wouldn't know how exactly to store the data. Restrict writing pseudorefs via the ref backend. Signed-off-by: Patrick Steinhardt --- refs.c | 7 +++++++ t/t5510-fetch.sh | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/refs.c b/refs.c index 50d679b7e7..7c3c7465a4 100644 --- a/refs.c +++ b/refs.c @@ -1307,6 +1307,13 @@ int ref_transaction_update(struct ref_transaction *transaction, return -1; } + if (!(flags & REF_SKIP_REFNAME_VERIFICATION) && + is_pseudo_ref(refname)) { + strbuf_addf(err, _("refusing to update pseudoref '%s'"), + refname); + return -1; + } + if (flags & ~REF_TRANSACTION_UPDATE_ALLOWED_FLAGS) BUG("illegal flags 0x%x passed to ref_transaction_update()", flags); diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 33d34d5ae9..4eb569f4df 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -518,7 +518,7 @@ test_expect_success 'fetch with a non-applying branch..merge' ' test_expect_success 'fetch from GIT URL with a non-applying branch..merge [1]' ' one_head=$(cd one && git rev-parse HEAD) && this_head=$(git rev-parse HEAD) && - git update-ref -d FETCH_HEAD && + rm .git/FETCH_HEAD && git fetch one && test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && test $this_head = "$(git rev-parse --verify HEAD)" @@ -530,7 +530,7 @@ test_expect_success 'fetch from GIT URL with a non-applying branch..merge one_ref=$(cd one && git symbolic-ref HEAD) && git config branch.main.remote blub && git config branch.main.merge "$one_ref" && - git update-ref -d FETCH_HEAD && + rm .git/FETCH_HEAD && git fetch one && test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && test $this_head = "$(git rev-parse --verify HEAD)" @@ -540,7 +540,7 @@ test_expect_success 'fetch from GIT URL with a non-applying branch..merge # the merge spec does not match the branch the remote HEAD points to test_expect_success 'fetch from GIT URL with a non-applying branch..merge [3]' ' git config branch.main.merge "${one_ref}_not" && - git update-ref -d FETCH_HEAD && + rm .git/FETCH_HEAD && git fetch one && test $one_head = "$(git rev-parse --verify FETCH_HEAD)" && test $this_head = "$(git rev-parse --verify HEAD)"