From patchwork Tue Apr 30 12:26:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648906 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (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 A2CD813F43D for ; Tue, 30 Apr 2024 12:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714479990; cv=none; b=MUuC0UCD0f07weKm932R8EuFr9J9chGc5s5z9tyurVeT2AVx9MoLY6QiaHWTJF7q8reQApx76evyd6vLB+6hPAKXVrp6OeNljWcxgY/v9cqaZms+ApyngRVtRcls0MZ/EHvX5sxtORoppjBXgfct88aqMxhn+de0DaL/U+FR8U4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714479990; c=relaxed/simple; bh=CWSKQIf2v7UZybUTHUAT2+iVr94BemLrQ4Shqr7iFHQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mz/U40Q5pNj6ykc4VtUIUtTmbrwcnxSPExL/ga2OK+e12ZBc/E/Gecp/atebDHD7cel13+Vi95wmVO3tzd3xZL28/5vwHJL326pc7wZGEeeQr9ra2nO3U93LunzUeYI7rMRI1rAOiUyBDKRkDq17Q5L8/aD7FcWec3UubEe1G58= 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=rWBHrC0a; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z5jf5xPV; arc=none smtp.client-ip=64.147.123.146 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="rWBHrC0a"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z5jf5xPV" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id 6DA581C00115; Tue, 30 Apr 2024 08:26:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 30 Apr 2024 08:26:27 -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=1714479987; x=1714566387; bh=SPKyjNyw6X d1lKhd53SB3ejBicA2wId3znggYuENP5c=; b=rWBHrC0aFTYZzPXciGiN3xcygE N46u94454q9OCHkd8mM283fwYbSbmsWHkCptLqsXvJYdmFyhW9j/NgaRTAzZ7RcN 5BtzjiY1XedcFiGPoIJrupz+oCghH6xG0nWk5YGTRoPb0rIUXHrC+0rVNE1/aB0K dJ4eYhzmFSZ+LVCbD+NssCcB2VIkPcNHR5zRJZFA0/2gNAOXNQwDEtFQzWZcpwcn GT8wOUYZqk8/wCA0I6eqiaPoMgROdett6mPCAyfMD3ihcMTMoQzaj63UEmkme4oh wWOsoYGH5kla3eTy0jzo6wUTc99iasHhp0EmVML0dF/+BL+7UvNDLnJ+5ZqQ== 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=1714479987; x=1714566387; bh=SPKyjNyw6Xd1lKhd53SB3ejBicA2 wId3znggYuENP5c=; b=Z5jf5xPV4MKTYWGOAV2qgkrc9MrYOE9mmksk+7V9/eD6 G/LKyV7PN18vmWuMpmr3qLQC5Ha1UJBGRnMC3hBCFr+aWzwsh0nXHAsQWYshMwaj qHHR7lIwy5zUq1QmvoHqj+IL/TXZf+aNaQ5rd5AeQhNwsaCxUhaRljAbxdqaUeRO cz7bz26Lx1hGRj4xb//fC0PzFnG9UOJL2QDQWQc06YE+Thxy3dC5OhuciaglVsqJ rgFNr+Ljgyo1CcZBUbnjyxj35k0CKAxXUZQ7yWUSCpN34eiaLRvrZVf/sa7r3CiY tj7AaqfyOqxryI8ZLe3jVN+CqKg5/KRprE4sRNU8XA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:25 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 88ead617 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:04 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 01/10] Documentation/glossary: redefine pseudorefs as special refs Message-ID: <2489bb558543d66592fb0f3eb4d4696ba8e31fea.1714479928.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: 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 nowadads, 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 hihlights 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. Signed-off-by: Patrick Steinhardt --- Documentation/glossary-content.txt | 42 +++++++++--------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index d71b199955..f5c0f49150 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -496,21 +496,19 @@ exclude;; that start with `refs/bisect/`, but might later include other 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. +[[def_pseudoref]]pseudoref 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 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 Tue Apr 30 12:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648907 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (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 034E213D277 for ; Tue, 30 Apr 2024 12:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714479995; cv=none; b=UotikhaOOt7FV6bIkzBstzZctnAnW2EANcpL70mj3UdpB0mNaL896SqImaTTK5ClhnPaHJ42t5DeNEWQuw9V5gsT16FjFPbPeVsWhLKXWOx6Fx+N7eeDhuYo1vqmSK074EezIrgponh21ciItkTUEpMnZKsNX2+42+ijTiv+UEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714479995; c=relaxed/simple; bh=tq3mLeNrhVCWcuLC525FGp/kFUNkyrlBuHaYFTt3VCk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G384V5G+uepTH/vaotzf5l1x+WXyqlENU76E20hSU7Dt5MVonjW0rPt0uxn5xbTMBjnqj/urNQZZ/o5EZFKP+JIFwzpLwuMGv0WbDhojgTpmU9LZoWC7hm7HW6XvGE1mshe9+4lfNsRv+a08RYs95iaxjfuzOnp20q2gPYio8ck= 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=Q735llZr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O1HR9ZvE; arc=none smtp.client-ip=64.147.123.146 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="Q735llZr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O1HR9ZvE" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id F04C11C00115; Tue, 30 Apr 2024 08:26:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 30 Apr 2024 08:26:33 -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=1714479992; x=1714566392; bh=XLdzags/+s iFmpsiVhwTlS2WZBb53gphYvLEbhJcx7c=; b=Q735llZrECiNxmfRNE27riiZml laZNJ15n7BYPELM55qLCzEEMkTl8seoS56x5nU7T9CrQ4mw4WHktPUID56GybC47 aZ6mZVhtkwnGFKX8Zv6+dp3v4DZZXMGsnS2BEvK6wrv30L/2YPAsqQcWL+y4IuDG TWGPwLC//l4aROBATtDckZzCa/O4w5UY1Loge1cX3rSHa2ExQ1aYIGmWA6Pstmz2 42TS9S5WYfKnpk1/NKxz0revKvIa1GEBxZo7hS28GeXyZkPwn/p/JjbbgJQLnF62 Iq+OBEJ7d8YcwuzSqzCaZxlWA2Xk/MRTUF5+kGhQThnY8sE4KL8lvgMRX31Q== 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=1714479992; x=1714566392; bh=XLdzags/+siFmpsiVhwTlS2WZBb5 3gphYvLEbhJcx7c=; b=O1HR9ZvEVQsGQUjW2IZ4yVdz+WFka2pF6LMLipfYKRVe /IfdkReLDUXRSMsXEsQ83LF8jk9gB0soyUw0yEgQl09qJcAGH/RneH7WaA44rhas JPh5tcBrzYESzQN2tG9HJCbTs5x4ZHkCaWgSy4yl/0+8JC83JBvpdu0yCY+Csohm 18qTa9FZ+E7WDgue5WK7R4SLtCurbcU9XoMVdFEme1rri+uxyth1KcLXxChCu/LD 0gR1ua6Jg+Hnf7hm2+JGcrsc9p9f4lkrlcjmuNaiG8B4YZgBgiTbNyaz1Ufn866C /yWrTU05UazhbITzeL4LFLF04+nc00pHC1HLnBpYSQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:31 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c6644a2d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:08 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 02/10] Documentation/glossary: clarify limitations of pseudorefs Message-ID: <1f2f8cf3f2cfba65787551ce6571376275ef3a8d.1714479928.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 no ref, 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 f5c0f49150..13e1aa63ab 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -498,8 +498,8 @@ exclude;; [[def_pseudoref]]pseudoref 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. + 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 Tue Apr 30 12:26:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648908 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (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 942E1140E2B for ; Tue, 30 Apr 2024 12:26:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480000; cv=none; b=ivWluBQIXQ/wJg4ET1LnAPMWATi5KyMQdhLWyJU1gDXasuY9qiYoPV5Ndf10ZT/ibuClOtuawKY2e6Dafyb2Z1H1vUojVlNfhMbVEwEGzlsHur4win8scCTDFt6pLHD0zIn2Zd2BTnxEiJRf4wKfEDpYh252zW4Nbzg43MWv5iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480000; c=relaxed/simple; bh=6v3yUM1b95Isyc3kG6N+MTUA6aTWj6VDhE/Wuf1OU/Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GnrThdI0sbMAVRynsGNkL9B8IlNl4CsV6ofipBJO2OLF10As85Sop4bvU7qWb80ysKCGmBUnxneNW/hw0O2BUz/C7QKaUyIGbvIc/K8FDKXnn9E/sWiTcXpEF4OsbJ3fdHEk0VmDq7t3mNMQt5ixpbCE9Nc1qEVj0eUBgEY16p0= 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=X8+tvfdO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EqPAp3U2; arc=none smtp.client-ip=64.147.123.146 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="X8+tvfdO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EqPAp3U2" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 956021C000EF; Tue, 30 Apr 2024 08:26:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 30 Apr 2024 08:26:38 -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=1714479997; x=1714566397; bh=aVEPaepXdb 0P4qWB2nzG0hEc58QbkQpgMuIDP2IZ58g=; b=X8+tvfdOw08PEqC3uOJkgSMKPX LkPrQ7FvVCDULIu88Ccsko4zdGPmaEgdRr3Gud37qMitqrgcb3nuWvremnUf+T0p qtv3nLlyGgmKhx5nYQ4EZHOSposmibNfx0xZBd38XXRq26bEJZfWbFiY9LvUD5x4 2zVptaZE/s0KcDdNsi6sTQJlQfhOaYj3dF4PThMSpca82WKtVBE70Q/rfKz5WC3X 0k/cgBD+xkWehNnMCST5A0tbPOVxOKN8uSCOwkc57wDS/y7rfnjxFTYjw+7kp3VP dPcWoi+M96s9bkHMajTTggcYLNn+vCQ2GOCFsRoioPVh54ZQducjBPY8FFjA== 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=1714479997; x=1714566397; bh=aVEPaepXdb0P4qWB2nzG0hEc58Qb kQpgMuIDP2IZ58g=; b=EqPAp3U2j1m5XNVSTyBaV7qRi7OTR2lh3bMONep2Uhzg +N0ml0axWfPUbewfcz9/Gfe1aP4TjQlZZFJj8pTOwHbtZScRqYWs7HAKxobDiDb2 IS9j7JAqajFnfRSRgr3ZqOS37LQIjfKyFBik01OGGmO5MbBMArxKYSg9Z+VVF0vc 1UgND5+7KPh7qDFyy2TNS7A1wEDQQFEgioIaGmMGzR3Tihn170wvzrk850rKSicB RA/nZTHniMw3kkGQibeqeFR92anuLEUvZAEPcvjgFjNk8/rjMInp232qAXOo91mE INgOYC9TKGeODOhQPpQWtDSIU8bbmz1a35Co6FM/SQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:35 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id caa4ac69 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:13 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 03/10] Documentation/glossary: define root refs as refs Message-ID: <9659d7da3f38e706af22b4cef0a3e77f780493fd.1714479928.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 | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index 13e1aa63ab..683b727349 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -550,20 +550,39 @@ 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. In that case, their name must conform to the following +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 Tue Apr 30 12:26: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: 13648909 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 22517140384 for ; Tue, 30 Apr 2024 12:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480004; cv=none; b=K9sx4gs4u37JNDTPpeVhdS/fb+a8ptSZIXu5rmDS+W24V97785TmuG0y5OQ9evA/e2c1OqPdlU7Bh0SzVUw0MMq99HYE4gKU/h6c5NbWTuNg2zX50fY6ZXxH4+7iHDKfAmj8eDbtYo+7o07mwYQLLDDTvC++QYcVmnrkKUgj8uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480004; c=relaxed/simple; bh=c7my6STImmCz3Z6OrhTRzog29N8MWHfwtpYKn6yQ+1U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kinrSw2igiZAoIEnIfY3ssGiIWz37JNRTORIgiuOGVfola6KABbcEJh527G4CthJfDkFh7zRTzYZJBZG66wCylzaLJ4VVIlw6NUB6hyBy+y/N62zM/OeDXEhjkuitnkIHQpwBpT8PD1PDdDBdgzYl241J/nNY0KZIIRNltRyH9E= 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=cNe0Jvra; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ccUyfkbT; arc=none smtp.client-ip=64.147.123.156 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="cNe0Jvra"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ccUyfkbT" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 2C7C61800155; Tue, 30 Apr 2024 08:26:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 30 Apr 2024 08:26:42 -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=1714480001; x=1714566401; bh=AlDZiXDqf0 SLqKnRRmAFET28o311Na2gbPl/xepIjw8=; b=cNe0Jvraph9SaeUsIjJe/d/YrM QqC2fUdIbn4qEe4leeWTKF/GQNxgzTwd+MPd2V5iiIhRc/ZR+JDRgug3RbCwQMpk TuMvaOx/MQ6hJBJQN/u8jmxKe4XCv2nlOhadZ1kla/rW5y6EcVsP9oy0NT+p7aKS UGcnAj9wczwWuvenFkf/LsOokJe9IpOALeDRDgMXJs8zQfw/mHBSFvimToICFN64 wd+PTrdMqCkucdVsVsDELOEEoY7ZRpnEMVy8uO6olthvP4p8JJV/VevlJaOFv+6a hJ5Erkmp8DWcbd9ed3tpj4MlgrhPE5XheN/S1bDhu1orQbeHXz0s0ZlHSsbg== 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=1714480001; x=1714566401; bh=AlDZiXDqf0SLqKnRRmAFET28o311 Na2gbPl/xepIjw8=; b=ccUyfkbT58wwR4DWV0goX9g2Z368NE6HxpeRb7olGRK6 4nAJSuJU3kVa3x7KQwDZw8lj6ITyvejc7n619HNdOi4MHZyg8dH85yEkDIQidOBx TE5OXwKSaef86tn5h/C1q4DgawlqECN0jf1eiqMN2So7KBpbbj6EHfApuevPfWbp uHM/dRXZFOTRQbgEnJWBisJfUQs0io8ZHv100cJ/ENEmHTor1inbzVSjNv7ftFPo JQhKjGe5hZqoRsDMF8AhJn4yWOGn0CWSGZk+yxjr+tXL7CvgEEXSJ9YuRD4OHcAg nr5P6ii21VNVtQI33G2bymUpsxIlVRZzVeUiQdgfGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f7e8de9c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:18 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 04/10] refs: rename `is_pseudoref()` to `is_root_ref()` Message-ID: <3d7ea704177c84e5afeceea5848f5606f11e99f4.1714479928.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 Tue Apr 30 12:26: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: 13648910 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (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 AD1E5140384 for ; Tue, 30 Apr 2024 12:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480009; cv=none; b=uBJ2VZdEKZ/ZQ0GjzQ1ahSY3HAxcoju6JkegtUMvVWshO2/XzGpbEEhQimUFnBlcio9sjru6q7VDcMSUHZ1ZuqLIf5bzj+Ms9ytV/38DtZZ/fvLdbzqykTYdb/XOlqOhL6/BATqlqr2Yq/5rzLWrFMpaWFJKJuz35TGzUogqLHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480009; c=relaxed/simple; bh=OnLLvQoi1mbyFOERIdR55C1Y4+eoFUSK3bvu1vqUbFA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=arE9YNwWhgK//7aDrgKkzBNp/TY7n1EvBpqgmUXAxzXl8qZGAygBI6v/sQ5Ebe81SmBbcv4ckGz4AF5HaI3BIZjDlKYYX899tbOZl6UB9bIQKDupF7Uy0PndCyUn5rKlso9Rq+n7Yd+xR4btZNjo/toDYIpfY6fyLdX9rdVxtAc= 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=jXWxFfUO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VDUtqQfe; arc=none smtp.client-ip=64.147.123.146 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="jXWxFfUO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VDUtqQfe" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id BD56C1C000F7; Tue, 30 Apr 2024 08:26:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 30 Apr 2024 08:26:47 -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=1714480006; x=1714566406; bh=QcbhTT35lw uPBSxa6yg88Gtc8PW2UaVx/ICH7SoOQ4U=; b=jXWxFfUOoHz/CC0br3+Eg9to2L D9uj6RifmwzsHLmVq0nidP6zZF3UCvpe5u/Dwsv2+TNgJwuPmhK98mhpi1jdXAoP TBI6PXKf5V3VHSwvHHHtNSUGVRqLAo4dtfYFtZPwPY1vYJjLbVZ/YCP6tTTLOLZF NV/L3WR3Q/mFgrXEZfUbp7mrPvEt2xwayoeWPC7E4wiIuKcvwxTVLHcHu7bUNZjk RhxrlAo0QpBZRUS6rR4b0RiW7JnXb5YZODHeSV3PTabUhXnGTI0RVkUjHTEXpMDB 8RSAbTU/smWLsgWDL5m9JEgRInwITmsv2ryYqLkbOx7OwXxIN1fTU1Cq6f7Q== 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=1714480006; x=1714566406; bh=QcbhTT35lwuPBSxa6yg88Gtc8PW2 UaVx/ICH7SoOQ4U=; b=VDUtqQfeG63MzI3dahwnbdf+7Xr0rpxizsGzCo+oxUUI lTX7I7dmI3jAh2vqdCkqk4LO9SKaCU1hL+hgNt1He/A9TrtlhEo/v1wKsVipr3cr AwYRSDobJgblEyuzRH/yfvbN5QbJzv6bgolCG2VDaHdgcQSk2g2azUsSWLt/wgYw 1AjXj/3n8MXujvgmIQ51Wqe2I2jW/yMMJ5DtzwFAosC2BrpxeF36ntO3GQsQX/dx 7tMmmpn6p7BFD+7XaQ7O9oFf02fTFKnLyDUdRwop38alnD5uu9gPGuasuz922eA9 2sBcLCzyCqckdwNQEW58lfaPHwH/EHF6u4eRGAZ0Hw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:44 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5d85e475 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:23 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 05/10] refs: refname `is_special_ref()` to `is_pseudo_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: 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 intentionall 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 Tue Apr 30 12:26:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648911 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 7C180140384 for ; Tue, 30 Apr 2024 12:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480013; cv=none; b=AL/ofjxDmMuy7zakyjLQMiVhIvfrMD3e0kBCEuH7Mewa+qPN8U7xZFTBX5sPW21SovdSWEjqmM9L4Pl5iDlzV5th7ZnlJzcivd7vqwVcChiVWpnc1Sr62Y+6svNPZea/3EOK4mrSYprPQukV1vZt1emtYNnNTGLCKThqH/CnbwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480013; c=relaxed/simple; bh=DRCpjFx+ZmjyfIL4M+xhmyTgsk7mRa5LIKQ/xtkFBBU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U6OqZ/MrhQo+bvzfZA3jxX7dJ76bJpiFqiBIfDKV/dqKSgpbVf5g4KWkWTJun2TafYS8FFfNP+oWYCvVHk062lNs91S8V8TJLqFu24gSrhpi72Nyrlj6+bycUZk9fW6KdDtwJlcCNfAwpEjIgufEC4gXZV5gpQEWeX++2e9l+NM= 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=YdAWfup6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Zs9Sf+2Z; arc=none smtp.client-ip=64.147.123.156 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="YdAWfup6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Zs9Sf+2Z" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 4B75C1800155; Tue, 30 Apr 2024 08:26:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 30 Apr 2024 08:26:52 -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=1714480010; x=1714566410; bh=u8QLNqzxeH Ce465zBp4kSPUEIZ7TXWAC/d5eoExA0lI=; b=YdAWfup6pMA/6YLl9rdKdFjZy2 2JgFYCL+FMpP+m+QBETTy3dZRecjdNM9/yjN63O674VeniecjNYgxpnRv027WWc6 iDbm/bBj150ivneq0BD2eQ4AiBT2UpzndtEB0XgmUt5tCukQ5nm0QAnC43fbw62/ ERUdqQeCcyU4mMM8H2zG7o/W0a3CEvmtHyOHgDhcx/mhaPLrnRa7muqNK3c3UnwK UCjzhBGyCKIG6ReP2pmeXoSno7GVK2tCAbBpnTdFl53/TpMGcpXVtxKR0LDiifqM NjYxwpaLPTRVpk5nXAiGKe8P6c/+K0Suhb0rqeBLMcQQaYu477He7U1sG+nw== 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=1714480010; x=1714566410; bh=u8QLNqzxeHCe465zBp4kSPUEIZ7T XWAC/d5eoExA0lI=; b=Zs9Sf+2ZObcAm2SJkkq3rvbOrInkSHDW2a2RJRDvKH+O pM5yTX/UpcgYYsc31nqCpqxTrfU4NSKGK1Y+6LtxGfhs8b9I+X3OTVTrZ6NeccNj GD5TQBzLQyHbvDhMBWPBRiUdkOPN6m5Ks60QWVLqUN/T6QqvYKVNXwdoYqQNZvlS 5Qp9A8e1pzcqZ/TNNDTScRg+L0GQfLW1e/tPpDGilGQdATbjlH8t2eYMFIjP1x9U wf4jc8a5gxfdlIkyOfvP3+7cIJu4kULZQ7vlfsXYdA+9k6hrs+2JTg2G+6hGoWj9 K/NcktexXfALL6oBYW3TunCWnPRi+dQnCqtWEhDPVg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:49 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 15839947 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:27 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 06/10] refs: classify HEAD as a root ref Message-ID: <44f72a7baf22c833549bdfbbf3c960b4104dcb1b.1714479928.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: 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 Tue Apr 30 12:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648912 Received: from wfout3-smtp.messagingengine.com (wfout3-smtp.messagingengine.com [64.147.123.146]) (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 32A0B14037E for ; Tue, 30 Apr 2024 12:26:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.146 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480018; cv=none; b=qik9gVqeQoh1Oken4ENUGqnU1GrH+/aeiKBisZa01GI2H9zEAJfmCnh0sU3RHXLg8d2EIHiemUv1q4yk/kCE2p+sAiWk5eSj3eRRMpI0g88LME6s6j4IVwx4l83qm/v15IBo7bmd9T2rJjOrUO54fRPhxaKCUuyiGZ9VtjkFosU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480018; c=relaxed/simple; bh=RTUdWAgX8wMZunTj7yaB0xjF2ZQrt/EBTNY0ZdpGEAU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rPmqUuL/BdWhQDYJaC2hVVE3dtEttDW3CntjwyqgzHoNALWZDBDM1w4SGB5YeX9TUR9EcVjzH01GztOElKQRhBhV8q7GXj7iq9OLx6PmahFss0sMI2DjZXLobVOshAENv/tfm3Faz1OaCkn02kRCkjc8n6odVu+6Cl/+KCaclgQ= 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=No8rxVku; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TNl1XR+c; arc=none smtp.client-ip=64.147.123.146 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="No8rxVku"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TNl1XR+c" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 22F2F1C000EF; Tue, 30 Apr 2024 08:26:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 30 Apr 2024 08:26:56 -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=1714480015; x=1714566415; bh=QY47j0rS+3 a2TzzSkTXgGW/a4ow0u6ZQKvc0kQibxpQ=; b=No8rxVkuhB2atj2abX5jgfrSSh zgepRC5J5gnmqCQYgFMhjAEL8JECy/YwXEDjVpyA9l7b+ZeXJn1dngc0X0draDD5 jXHX0nYoPaq3t+vcMXBQLhmb2WIxuvfviUCxoPc3B0raoHca35IxOKr8Cc91dgM4 HFRed2VcXdsMksgpfnLBFKZp+Gk3ozCr2FZU/1y5axF7Df/LYzm8t9LK91XxXKzE NAcx6+H/ps9F257f19WtWM8QGFOpe4Bq0QyztccOUvBLG8cwJbwSxaxe7kKyp6i9 Wf3iG3zQx2KxaHz5koAeH5nL4KiKBEKbiJcSiSKdyBJmrawZkDsXlGk9A7gw== 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=1714480015; x=1714566415; bh=QY47j0rS+3a2TzzSkTXgGW/a4ow0 u6ZQKvc0kQibxpQ=; b=TNl1XR+cBJMxyh20G7iRhnYuWR2y5jf/8j/iMUkBVWu8 Qr/WxFM9HTtYv7dQSwkvUuDRxBhgoxNHKFqvRGt+mORo0wBX6kcsyJd3PtqmGuxz Jf12utF9trxStKGP8nk9YED7mWp0s951i4C3jSj5XkpvOm2P/fEXfNtTEJVCp99/ GTMssguQgF1mAnSyf+Uepxow0GKoX15D3JVgPK1Ldl9a27bHmI+iYBD+aOLgI+ds I1BL5hIP8ZUhPut2HbSjlo6LMBc0a3sr+Xz33+nIadIlPdupXuGVw2BnnpdMeo+X bghUTKVxqbTIeQP8icx4wxNCAuYrvymorqZLOiHz9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 09210981 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:32 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 07/10] refs: root refs can be symbolic 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: 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 intialized `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 Tue Apr 30 12:26:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648913 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 9879013FD8D for ; Tue, 30 Apr 2024 12:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480023; cv=none; b=SNX39n9DOAWvzlIEiD7K1sNp7ETv7lzHfZe42qzyJ7ah3A6rJSSd1IxH4XbDfaQrNHV6C5dHGYr67NQwssibeMf26D0p+T39rVA/NgpAU8SBalBX92V5643TmE3f7PlxLzUy/eBPxU8VU/Y9nmr/VtfZracqqZuDJUWYSl48+vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480023; c=relaxed/simple; bh=HeQuzra9/wyVxp3JvU3uSHxemgTkLJDhGIU4o6dMp+8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SNceHeoCsZXLNNzwGDmMnMktGb4WNDX/PTfNPTPi5TPSSYBZhzAtOKNbxv9yb2ldPp1zQITjnwcGwlw500i/6AJaUIcwMWmMc1+PZUP7bLEAv3VOc6wsVvr+eIkJCVJ4c8SH5wkx/ZIwrGqgfLZHbMI7eGI1FY61LRCGGqbE44w= 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=iOvEQC6w; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=S8lcRdYV; arc=none smtp.client-ip=64.147.123.156 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="iOvEQC6w"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="S8lcRdYV" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id A671E1800177; Tue, 30 Apr 2024 08:27:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 30 Apr 2024 08:27:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1714480020; x=1714566420; bh=iFKZJRYlJd 0SC1C7mgl7V3fgC+TkIwn8/0y7yz6JYmY=; b=iOvEQC6wsGR0iFnhkvJZ27g/G1 REuxKMj0DmxtEo5bfBqaRWKslsPS3W+anQtiRVSv2XkhIA7qTmQZhDLxLpTKlibc lynFI+iqV5HcyFVt20fJdW0fvSYdGCp7tcjeFfxTNYI3LBbErJ0kN/A2VMWllP8k 8Mxb/xbuiM2hQlmmHaxqStN47Ek7gDVlN+RGMorruQDB1Ys+70uUg5nMuWLlF5a9 +T7+mnTei3bR679DGunRq8ytDTWv/4rr3kISVi6N7ubpjfOAKbUy0UnqxMsOLikh gIgmytfqFAK+6EqWgr+FT9RGovrFspRh7DAXy5Ci/NZXlDJV17zYPSb2aTTg== 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=1714480020; x=1714566420; bh=iFKZJRYlJd0SC1C7mgl7V3fgC+Tk Iwn8/0y7yz6JYmY=; b=S8lcRdYVkcCQDzo+a9MQEkQcQwQEMxxA2T4qmD7FKWBz nBzl4r0udNjQTNo9km5WZIUQMOgyoisfoeFitBZf/76CP3ag9GrbGROZJRAtSl1N Tph958hX9T+i/7GZ+NdDC4fhwafegFZlW28Qq+1hCeC6tABSPZ9zhC26ahm8F6fU c4N9GQBT3bjdyWy8ObDswXDAmD42Xg3A4zrcf1Y6eSIEqPCqLRHVezHNTTI/Kt9n V7PI9Hdq6kKFc8Cl1VAof/c9fUNTXXLwbiWyes4SjKMHthQsLek05Pn5HMaqgCM9 DGRXxaqYPB/MmILCMWzlYgGh9nz/T44wPRUS0LRJRA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:26:58 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 39f90c34 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:37 +0000 (UTC) Date: Tue, 30 Apr 2024 14:26:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 08/10] refs: pseudorefs are no 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 `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 Tue Apr 30 12:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13648914 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 5A7091411C5 for ; Tue, 30 Apr 2024 12:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480027; cv=none; b=GvJNDsxBUWfUw191c6O6lG7wM9ogtrD4OYs3qovedG2uJYwCV2U26/CIYKf+Vs4YpgOur/OKxCTEuITIHN372WEW/tK/0EPUp6ou9TOJR6TUPt68Y6vV1tgwRwpceIYPDAR6ji8cUBMey6P8BCZ6pRbOExYsPpl6gekbLJDM0wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480027; c=relaxed/simple; bh=DT8qCTPfZvRNZTE9aHi76WYqiSlqXLyklCW4edCiuFM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DULEBGS7gWSsRc67YDd/k4rqdV1TffYzuWjTMC2OPuX7L4Te0o5EcmKrtwTyacZGTeKhEQYZL0K6QmvbEhg9Y61eqjfeg00AiqM+AmpegfGApNSnaCBD0QVXKItk8e+XfLshXn6Z3JtpCn63s1a+QK0NDtlxxmKD2YU2xRKMnaE= 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=c9pNOnQ1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TOwaV0tk; arc=none smtp.client-ip=64.147.123.156 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="c9pNOnQ1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TOwaV0tk" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id 41D2D180015A; Tue, 30 Apr 2024 08:27:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 30 Apr 2024 08:27: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=1714480024; x=1714566424; bh=Y8+M9trjBH Kx3SdheJxWgOJJ/Nu72h08hGi3lA9EHj4=; b=c9pNOnQ1Cwj+pKHd8buG15U4TH WlgFENpegp1kTTLo6H+Ne38YGRQgO10Z7nc8FKvGQuYoLuXo8QyoC1K9r2gIwZAD G7jLqH8CGbLngLBmi91Tiw0sTgg2SUskDUmvElZe+zI3mCRkN1cckk17T1vECGKx h7N0RZMNo00AHp7YwBsOszXqCx6vZORcjD8Pv0456XR7STIqMD3lh6jAFdgGuxOV W6EghAZ3v436JBqbDBVjCgItOMPlkjnXpadGVD1a0/hZGqY4um3Xnx/ti9fEimif Y8q6LH9Q1tU1EDv9CQPh/eQnpz3M549j+poVFMdBc5b95v5ndxCCIlCstIwQ== 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=1714480024; x=1714566424; bh=Y8+M9trjBHKx3SdheJxWgOJJ/Nu7 2h08hGi3lA9EHj4=; b=TOwaV0tk1gwBv+MA/0hSE1XHj6sAsm15cnXME7tCkgcE dPqMVJx6w/+/41PlZTA/pa6ZzqnvxO0wEveEWGxXukgVj1lsXXLPI1O16IDZUWtM BCV6irln0cy//yF+gfU96BgJAwskdcg5VrIlYosmiAa+3QSBuT+FfLKxqg6M6jA6 2TYLnDRdCEXAgHg5sSefz9VHFMJrIJzuRK1ewplWyPiIIW2sMRvdFbDe2iLGkxvF CLeWYAlxpFqbC3tLPsVg/UrAwfWrDPMlle2SBA4rDwo8lhv2yQnrgBQTmw1oyhqx ekaOcki0iO8vtlIZwJzi0a2ccVHLS4jC2jn/XdXUQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:27:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4b6e9ba6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:41 +0000 (UTC) Date: Tue, 30 Apr 2024 14:27:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 09/10] ref-filter: properly distinuish pseudo and root refs Message-ID: <95d7547b2e8c5305e76888f7dc0a41d2b9e2f558.1714479928.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 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 Tue Apr 30 12:27: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: 13648915 Received: from wfhigh5-smtp.messagingengine.com (wfhigh5-smtp.messagingengine.com [64.147.123.156]) (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 C49A6140384 for ; Tue, 30 Apr 2024 12:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480032; cv=none; b=udIhQVgXNIGIT2r73Vi3kwXKgUDAQtkfuAbT6ICRMc3oFA9+7jq4D29j4Vphgmp5v7+HZysuEV64RKXU20/KpPHSXAPjQcgyK+QfRBSIXVoR+RdviOZ0+Nh8mlssH9DHUUAj/Y7NxHjW6rHLSPpSVj3Ml1abEWuZ5UjQ68c1c78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714480032; c=relaxed/simple; bh=NwHKU2lxrDx3FEiQUU5hZEs4MenBZ8Il3CZ7hNocAXc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=thGO/cWepy1dmtunyaZrqoAnuFtUfsHRU7f+OzUoo7YMTZY9Vm5QnnuURRGzxecPp8Mbnr6TOkAwWVZ6MQRFf+XNWfKNan3ycOJUIMqEM9Oi1x1p/v9lzTZ/CySIYJoutmpo4XIu6kVg+MTx+Tp0XdEj1QIxAe5qos1QGHlIi1M= 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=JZzvwSwY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U/6ikUkY; arc=none smtp.client-ip=64.147.123.156 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="JZzvwSwY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U/6ikUkY" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id CB2901800160; Tue, 30 Apr 2024 08:27:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 30 Apr 2024 08:27:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1714480029; x=1714566429; bh=j9ylLgb2r3 zp9HmjFjVR+UJZR57q03Ow6XuP32hlnhc=; b=JZzvwSwYP2KnafC/dl0cNcPQ8Q K3P4/4gLdtJb3RvKjHUGURKUD697be+oQHleA6dQnHXSeohM77+XOeinFS7xNofY Dy6mbUW4g6EqiJteDskkQgnfxdi9Kaf57gYwrGEwgGVXjee1tPcKN0rcrgi1zyyG LIkfv2YBqbPne9hytEfY0iCoqZwgVugK1i1ZqZwANxVP1m8UWoWkFIu5nqKkdRaw 3fk/ATKq5w8vaLhdzkkHgbeHyqr7fosUYY2MRsJZRXWaX3VERf/S0cdKZsFQj2Tq La9AjV0bSLQjlAxGtbr3RSk3c4DLAfS4CycWqU5E8uB4ZCE4oVmykUbr4RrA== 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=1714480029; x=1714566429; bh=j9ylLgb2r3zp9HmjFjVR+UJZR57q 03Ow6XuP32hlnhc=; b=U/6ikUkYLtHSX5zXQnhRw/LhFNQ/orV6jxP45toMDBcZ kfs0kGvYEFyDK+iz8txobXMa1bYn4Q//Fjyj+9rztKgY6dkL5XsL8mib2RRY5RxS kl3KqnMGBihWaudVH9cA55XTPHkYAcOfsqEybCTOG3DYd39YOgQBch2Im78vfaA6 dLTB3uAeJFkvmyNFn+gO1fVYjB2UZExsvBwsyMQbHnXrZqnMWLs7ChIxo9mObeAP +cTZcWvLurZEiT56gmlULwycJbp4jMHwVo0Tl4QOOV5qYCYnXlzPsl4iYHyJimnI ULtQZXOZRczzo/50s0bMmkB/iGiY0QGAuHi+vxB86Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddufedgheduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Apr 2024 08:27:07 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0d604d39 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 30 Apr 2024 12:26:46 +0000 (UTC) Date: Tue, 30 Apr 2024 14:27:06 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler Subject: [PATCH v2 10/10] refs: refuse to write pseudorefs 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: 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)"