From patchwork Wed May 15 06:50: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: 13664708 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 8C6CE405CC for ; Wed, 15 May 2024 06:50:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755834; cv=none; b=H9UuxkI3lQxw5jhacH/KxvbQV04lzrj1fD52fymbxRwKsH914OSCc2B60OJ8/66lb3FIx84hHQvxxDovxhv9KQUWfja7shXpe0NJs7ej8oBW87pIYPRlnQNorHpthTmxIIot368CTQQR11BM/uJIB4ilSAIVbJrwUyFGPXYkANs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755834; c=relaxed/simple; bh=PDH3KUHSdkG0Zf+8pH+I/sabZDTqT9teo8GzRqyWk6U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JaGbFnS4LcuZx8jEVQB1KrfzAY1Z8xNkL0nknFKK4PL1T6B73hxzJmPoog5TMuyw2qT1xnXgLL+d5Tm71u6e+9jeesAYhqFIc8TcsL0MrflohS8llmmhMvKuQf+0HQJ5QbFyvwENeL5zYHvLOK6F+/y9YZGklCpJogk6C8hLBgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=GPn6EWA1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=TxArxiQF; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="GPn6EWA1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="TxArxiQF" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id A5644138118A; Wed, 15 May 2024 02:50:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:50: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=1715755831; x=1715842231; bh=SYDfW7qJZL YpZL6GFM8/uKPLfzyoD/KlgMDByNgEN6c=; b=GPn6EWA1MY86bPs0lYaCvY6IYL f4c7o8liwoS92DuQr9xvBPZWS8PfGdlq7X/g6Qkt7g/s34zzAHaFFyg92qawtCEX wld5m4S9LO2cu3qnWuQvYP+U9xRgT5cs0PNiEuNK0jxwUQbLvIQ1A+Hk9CVChzdO QwEod1uTGszi1CzQSnf340yumayIoKNfFeJABmZ5nSUwPAomky+71e3nItmc4/Lf 6R8hQM7eZXflokrof/Zw96tHX6xVoK1/S1nhIBetK9QKHmju8iBfQ9DpxkAY8I/y tC84+0el91kAwO5wTtKnTD0BabfxrlQYTdJ1xeDgc5HduWkDvvHeVird4fyw== 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=1715755831; x=1715842231; bh=SYDfW7qJZLYpZL6GFM8/uKPLfzyo D/KlgMDByNgEN6c=; b=TxArxiQFDcLZzoN/M8SgwaOvm/y7FyTPOKh3W3IEl3p2 yFpZlg9FixKwOJvJ8INB+NU3J+upUuedjcYPs4cadTEG+F7LSIBWdybJ345xHSTx uhCleLvlS9p9krXYAoDTZvmXuaFyi6Fq1n9FGvGxttlgJQKcMxxBK8gyucFmzHfw t0ysVoe1oY1S24/kWvVEBkNUk8Uaxj0q3jqBhhe/UCPQJh5eJqWq93TJxOy8e8QR uIg5HmHMo1wA59mKcCSgdDjQLar/Fe7GDzByqGuaWqn4XC1N803IL0SfgVT9zIvi AJ5AmfeTH5H1YN2oVp5muQ6WeYrcREGq8CzazcWzEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:30 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 3dc9372e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:08 +0000 (UTC) Date: Wed, 15 May 2024 08:50:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 01/10] Documentation/glossary: redefine pseudorefs as special refs Message-ID: <1f2445b95b32e70696e07a6e9445b63ce45a85c0.1715755591.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 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..e686c83026 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 Wed May 15 06:50: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: 13664709 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 379ED43AB2 for ; Wed, 15 May 2024 06:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755839; cv=none; b=QKNcWRPYkNL4xA//Ej5KTcM/5p9Cn5AILNrhNmT6UdHJGJeSzoDIu7LIGIyZwLVD/YK2PIikccQzIV6NzH9LbnPkwRNhuggpicWyUF/C31Yk7ra3oKHE5tEpc3meBwnKChKnIbt4uz98foE0cBH+cu2Raebw3easf2UjjMDYJeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755839; c=relaxed/simple; bh=g61NCzUgQ5wxo1NBKBysVOM6Krak7gqzjacm3v7lIvc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S0Kn3Krmr/OGjGuVnY7aAdANUffa/RixRm9fP0qAOTzNoBJ+H1Kl0MkhAR7jh/HYkce1rwArsOmDI52DriZ64snJy8qsTLty3LUNPEGHSnAvbAiWRtoXeA36NeJt3HnqouXGbFOg9H8jrmfd2Ep+l9yRTbBNloeQ+gtxCHTcJLM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=S4Mw47Ib; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=au4tP9QA; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="S4Mw47Ib"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="au4tP9QA" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 5C63F1381184; Wed, 15 May 2024 02:50:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 15 May 2024 02:50:37 -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=1715755837; x=1715842237; bh=KbNzE4ifKO 0ckRyFhup0opHv7FY7WeR5GMQz9qmlIjw=; b=S4Mw47IbvxxteBTKDs2zGdMcQk QNcyTeFrZMWIl3q3wwnVroZKHYSjnUZ+o0qgGKXb78QP5Ng2VeFubHpfc+LJVPyr RlBAM9oLhDyNZCfuLN1XWjUDZQoLtUQPT1Af2Wto7KP+NLW3fFRxZB0nKKQbwp6p b0Ti4yZqnY9IrAdGuBE2nYH+qNEYuYBNBDqOLOkx2s3oUWxI+0MoMOPvurDvIU80 hwunsOEX3GmMcuZW4M0DW+3eZuNPa694FSFaAgDrGi5t+kz21lo2lm4qX7C+7POn D4LyLiTkk3yGhXZRBrwT3EowMP304QGh5sHL7oQkwUk6WJ6/QAHPWh/ZdgHw== 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=1715755837; x=1715842237; bh=KbNzE4ifKO0ckRyFhup0opHv7FY7 WeR5GMQz9qmlIjw=; b=au4tP9QAD4DrO289YGhHuTdY6xH6FHWfjzjsBpGSopts VpH4dbaYElCfE4hMB4hvhBdV/CfciPAnoitzrI0EzNWx/YvzH6x3kiX3ABwf+78h Bfz3g/11T67IHhv1sFg0Yu0SNxWJIBymB6IWg+M5WPG38ISAoAzXP9KMRUMfCNrd LoKRzo7jBqRk8ZHp+vAworu3p28nj8gtU5QrBbPVdHYFBDTkGgOuKDzl25deH9Qw AtLTcTkV9vS+zdE3478b3l5cYpgMKJexfBHussiS2J/RPC+je3hir8n0asExNuCu r8p6N6oKp1R61cP9YHVQTy0mkPeU2FB3Ufvkh5F8eA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:35 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 9e7a1ea7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:12 +0000 (UTC) Date: Wed, 15 May 2024 08:50:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 02/10] Documentation/glossary: clarify limitations of 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: 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 e686c83026..d8c04b37be 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 Wed May 15 06:50: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: 13664710 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124FB47F6A for ; Wed, 15 May 2024 06:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755844; cv=none; b=rBEBG9krGwCJLczitZcuLBfr2IRJAInhBvcAAXY5Jn51M+6GoxXrtj5FjJcEnBydPKv2T2G2mIyBid+qjMwsl04m7BCUPH+DbR2CN3EdZTVhOTJbxLiO6B7shziyGC4ZFEKuW/DlxA1zJn9qk6nPvkUO63ayuYuJRoPqzzkRjKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755844; c=relaxed/simple; bh=f+1JJbtCJomcgheMcjFIQbsWFrzM0ZykFaHtoZv81Dc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X25wMGwb0Yn/mU4AT1tFPvnQ2rLDKejVFqAbXS7S7e31Y62JswxZGXHtTrrIoRzciJ73RUbknJAkMba6BjSyPDxx+Fbkz0YEUj2VgdFaPxrHQG2lHJTeW3m1AfM2YJNYFKp2HUM1FThqJR8relcj67+MwnEQvRn8b6GMRhxdGO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=LfofOvjM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cDyrVmgn; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="LfofOvjM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cDyrVmgn" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 256B31140189; Wed, 15 May 2024 02:50:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:50: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=1715755842; x=1715842242; bh=5HlBw6C3Ti Sc8sse/hoLej1tefGAG2Mr8Qo39n3+KvI=; b=LfofOvjMdhlGzzqNte+2PCSpZL UkrpHAYQnuPzk2AzkiyyJaJkZVtPAs1oUZZqkpjFHhSkHu/2jHvzV+/725BvMrtH 8m+hm7xU75X+a8juuS+/Lk2XsOmouCMUQR7gCJpkqEZkZJRMtaYWUbMA6XAF4Ao4 TxREDRf24o3OZmmayowL17VJJddlTQIqkSpVTxKkUCCAHJG1B3D2/fNzZ++/iz6t 6VLcIB2VqVny4hhKOqqvRqHJzd4zKOaX9H6gEnUtKjul2+QqZV6cusRbT8tvbVj+ SXTZBNLJedsJSdWPHJc/P0/negrRDDtfanCHG+l/6VXQeYdII0BBcKQaL+EQ== 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=1715755842; x=1715842242; bh=5HlBw6C3TiSc8sse/hoLej1tefGA G2Mr8Qo39n3+KvI=; b=cDyrVmgnp/PoOUfMQ6ZZWbRBnr2U+njAu5z5Z+4sxd+5 NOXy2jYb/hbkoc+UrNdWwmdqaVNSRwPEFLSKnLATncNd/+Kh402BGYUahCXs+oXt nTTP6y2doMvSfCistSSse9vv9JkQGmKAkbXJqeqT1p86V1eMN1PbAveMHFEi9kQw s2PtHpnK5lA9ifgrsTx/2vcDGwzlcnb4zPCXBa2hni+OnbIkn7b9Wl2+07Kq5jGv su8uLu4UWOZ5r8aKYm9ZwNFR/NpB92ynWYywjXy9Btd3hrIssJNiw2fdcS1zlGvt mLYp3VgInemC8tnwn78VJYuZJmsQG2eQMaCDgeP3nQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:40 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0f6bdb63 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:17 +0000 (UTC) Date: Wed, 15 May 2024 08:50:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 03/10] Documentation/glossary: define root refs as refs Message-ID: <0d185e6479394025c31d2869c144a667df3f4301.1715755591.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 d8c04b37be..c434387186 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 Wed May 15 06:50: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: 13664711 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 CD75D4CB23 for ; Wed, 15 May 2024 06:50:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755849; cv=none; b=jca8aa7NaPgTXebrtejrxWsGsUvVEbOnUqQfBR8G73wJG6+QNaEzX6HFN/mlMxlw6V2H3yM7CHstCa9xnzblWiiWRaiZq7oY102DaJwpADyROxnSYlm9ap4DYZkmskrvuB/HKs2AQGxL/WNpoR6hWc7JvPrCgkx3aFfKEay5bfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755849; c=relaxed/simple; bh=uAEIzNM+CJKn1CM8iZpeOsebNeZdn1IsA7uWuHkJ5as=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mInPVo71u7iiRmXrorOCQ4VqCTNyylKVjT9+ZNZ+md+6BNgQWf7F/TZGo3n5mve/LyeQZ72U2I7ZS3gqeaFgWfIV0WvPKOCuHC8wq6FVJqYf1DUdnHhRxhu7keZdacQwOF23lgh7mA/sVTi2tO/Nf/fu0+BFsBPA2zyeOuJiqqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=QlZ5scC/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cebuGEJg; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="QlZ5scC/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cebuGEJg" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id D9AAF1381431; Wed, 15 May 2024 02:50:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 15 May 2024 02:50: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=1715755846; x=1715842246; bh=96fuiI+SL1 VOIdnM3OGx20M0WxP7zwxc+S1iSP/hcoY=; b=QlZ5scC/UyJ27gfoohvM6BbC0F TNIN/sprgFiKyosmqfyyMRN7NUNMqyGa3lKqGzEpH6kCNbNGRXvN16FtiL5V6JwY KAwuyrIc14o3tmMDfZnujupKf9g+ND5uGsVfjl0rWdgZfQclIG8B+GTSuulplIuw Sy+s800fuKR0fWnqoyUR+W50OO0jtrPawyRARt6EUfUuR9vNBt93wW/A3WiegcoZ SpFfbPmAIXCAm+Zlybsbw1R73/5oGjYODFaT+8j2hfm6DrYwD1LD03MGMhFCG0JH lN4RC+2TOFYW7Lr0NugWRhkJZPK5pVZ4oIPuIaDb18k5ed1R5ivTlUyLbqwA== 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=1715755846; x=1715842246; bh=96fuiI+SL1VOIdnM3OGx20M0WxP7 zwxc+S1iSP/hcoY=; b=cebuGEJgBDkajcGzvCE51knGi8ipYzQoltc6+NYSsvnr SwvNXEoZ/ie4LK2sVUjF5ReEZBdSGgvAk0Xm6ux9CHVRPsJAZ9e49Py49z0wji7H A4zj7Pxh4F39aTa8Ut6uJwqAvsYpG+oq3bWLrBZGKI7XCiOqA8jGFxgkDALvXOvR /+Q0oVUAFLLlfSETzrd0m+gl1rsu/c1edg8Wb5KM7OlmpPHJ5ouw15mkxqKR4LZc FXYSrTUEqmBvgK1ZPSLXGBNSaQUd74nOvhpSjh88n64MdX/rUz7TxG9f09Eog8xx 5r/mYnmzWW51meos+UQflCJBxn5qykYKmzdAWVBPQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:45 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2ec23542 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:22 +0000 (UTC) Date: Wed, 15 May 2024 08:50:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 04/10] refs: rename `is_pseudoref()` to `is_root_ref()` Message-ID: <33b221b248edbf18ee36a867e96a13d01e713846.1715755591.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 | 18 +++++++----------- refs.h | 28 +++++++++++++++++++++++++++- refs/files-backend.c | 2 +- refs/reftable-backend.c | 2 +- 5 files changed, 37 insertions(+), 15 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..434c4da7ce 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; @@ -853,16 +853,12 @@ static int is_pseudoref_syntax(const char *refname) return 0; } - /* - * HEAD is not a pseudoref, but it certainly uses the - * pseudoref syntax. - */ 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 +868,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 +878,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 +898,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 010ef811b6..36ab3357a7 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -354,7 +354,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 Wed May 15 06:50: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: 13664712 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66C8C40875 for ; Wed, 15 May 2024 06:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755853; cv=none; b=Ci3W+c8GBoEveZPmHR23fScPrV4pt7s7Em06CSZsN/NGoXpHNiOHeWDKqQEO1Gepdtzu7C2EBSjlhfijaoE52Rgl9CGBurxyVe/2R8+3ghwJtHYTWxbHWoNTy1igFe/QkHQD/LVrl3ycJsjTDs54pN8mm6UHP2Nj1i8QxsiU8bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755853; c=relaxed/simple; bh=MF+/Gs8dabaw3lRBATuTHr12+GG+5SntcG+wqdzodJk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i5ZKWuBvp5e5VP6DMmVQAX4X/23sozKL0/rvj7j3Mbzjuq63FHLtkAUH9SajcAPXTE7fCsnPDhPoOxT4MAkIaFd9dlNQVjKaEjLiJa5waF5LzOKh0KI7J7AUpjwoSeJAigxhmnO45gQEtvaYIO9yiVtFP+O6EFGwTuPLVx2WkCY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=B0UPH0/W; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KCkFrzqC; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="B0UPH0/W"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KCkFrzqC" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7EED7114019A; Wed, 15 May 2024 02:50:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 15 May 2024 02:50:51 -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=1715755851; x=1715842251; bh=ty5B4beUFx tfwVNbbaxeFzih4EmjoctjrBN/4acglR0=; b=B0UPH0/WrVlavi/opUcrvSX/Ty eOKg5bZxTwKhOmNnR0QlRV1uXaUbCebJ+yWG+LZ4tgUKcMjLCaMMRF2SrBe8pKhr GyV3w4RhcyklpN/phr4K8AaOAyM/ADo7hB06eU05VcQ1RGSgBdfT8mXAvPDBYwJX q6kTo5Ymdt4F3PQ97o6SE2s7zT4LSXG2Tzccyg7TS43cUR2YSbVvO5Qo7IgSV4HX OpGUYlBQWAWgQt6j7b2XcMMBxl1GETLme+xDkDcWNUtyW0trGZ8gRgbs40CcCv/A TJVx67K9w5DCdV7LWmJE5zkEJqCcW0Pa64Ko3mIHAtkXG6gIJ9G2IHEVqoGA== 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=1715755851; x=1715842251; bh=ty5B4beUFxtfwVNbbaxeFzih4Emj octjrBN/4acglR0=; b=KCkFrzqC/EQ6TSeaacvUyzqD1YZlUJ/OPTUWzymeM92q ydFiWIVPlMfUW1Aox9l+I3jz/bVKHo35klEcbIYmWTUC/f34MDsQ7XXPIgzqLYax QBn/cocvY4XJwIhcKzW2YixeiY5VXhQvTIzrINyL8VDYDUY8WDh5/QTOTPslRZHo wk3A14eiANXbajQ0gP3wtyhKPMv6qwl00+v4inKYNCniH2nQ9KIxqGaamGnwlvU9 nC/JV12OZixOjzym8TfkfLfv56uZojor52uZN5qTCSg4oi9mrI4167Ry7RibWstS yX+S3WhheFKbPgs+mgpqrWizFPdiLgWlOjNJW192fQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:50 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 0929b76f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:27 +0000 (UTC) Date: Wed, 15 May 2024 08:50:47 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 05/10] refs: rename `is_special_ref()` to `is_pseudo_ref()` Message-ID: <9087696d8206c9a099463c27c9274b7bab2b86dc.1715755591.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 434c4da7ce..c1c406fc5f 100644 --- a/refs.c +++ b/refs.c @@ -1872,13 +1872,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. @@ -1887,17 +1887,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; @@ -1908,7 +1908,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 Wed May 15 06:50: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: 13664713 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F097C43AA2 for ; Wed, 15 May 2024 06:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755858; cv=none; b=WqvIr2lTXu6Yr7ibZGMBAApkhfUoU2vVuFoUerD4/aWRn3SUXImG+LxeKph8jurrSZCfVu/QgkT7Lcuwt6jL6I0JnA0/jdJmYrOq8Z75cwmnHmltIh0ZdJukjHepHVz6D5FUxXSgWDuhdGzvYdhkAxXGOcuZjcxQvLy2M3U7TDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755858; c=relaxed/simple; bh=1WgV7JPSJ045xVp3ygSo6IxrxNULl2vN6J7CH2orFnM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jAb76wsnK22sUfZGakTP3ElUWM8Nw85A7XLti8Zr1V5ezu7hghFD2ZVR6Yueeq3xgMkwb9gYbUcFrslPS3FROEZV89ESTj9wfXnYyvbbmVdzXp4KC8X9/453eCgvBnE3+PT8DhyrvltVbw8+/qvdn5/6d9OOzZkcGrgcn2/g4uM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=iTWwR+0N; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DCwv+JuQ; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="iTWwR+0N"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DCwv+JuQ" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2D9411140197; Wed, 15 May 2024 02:50:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:50: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=1715755856; x=1715842256; bh=YHMZgg/YbJ 5KBr45ahQ4BfqSyAJOEyvhjY4AdGqVHC0=; b=iTWwR+0NrlLrPBQfhgkpJwZ7IN LpZpXY2UEQgjixA368hGhj4GwplToBxrkaWRgl1Cz1euUTGcWbWvxIJmELt4xXvK UWuErsOcAANGvYhONW9wPN6YW5XqHi02sDs/wfDwd5naasGy3nNSoVwlZRMKW5Ld Yk6HDw9PIqn7Gc999SvGh3FafeS+o0BsNYvf2/ih7QABM9Qm0//w17uZi4FhEmvT K73NKW7vKRCwjuluoD16cElxr1AuHTFf6VaHc1LlFaNMey899dUTd4MfmoYCMkmk XcVb+sTFBmefzXyGtEcGghCI3n3BAUivsdUnHFRle+CY5FWXNG4vEfnT/rVw== 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=1715755856; x=1715842256; bh=YHMZgg/YbJ5KBr45ahQ4BfqSyAJO EyvhjY4AdGqVHC0=; b=DCwv+JuQeKAQZvmD6gaaTW5DyFExjcx07q23LAlOMgpI nXzzdkmwkl0Re0IDRyvJajw3M2yQoCBN3Tm2nNYQz+vyF8QAHA49F8rvdIR19Flh ZSEE7nE4cYw+tc4/Sb8kXc1z8ANnTUSZp2txwX06mZmLKHoVqnWYF4oNuAYzJWRt Uhxg7I9wiCW7UOXFxy9WOf1j0ko/nb3A6Ov3axNOivVzL+6n5swfj8oZpA64E6wi ldNEY4UGIonJ/El2BIPayi3Vh21oTBrK+fbiQ/Ll0hHOWfx71kvfJ1JjDwkaZYet ZjaEIEGLSSQjm9rc181TwmifuXsatgCdn/sNMv1fhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:54 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 56773455 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:31 +0000 (UTC) Date: Wed, 15 May 2024 08:50:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 06/10] refs: do not check ref existence in `is_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: 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. 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`, but then read it via `is_null_oid()`. We have now changed terminology to clarify that pseudorefs are really only "MERGE_HEAD" and "FETCH_HEAD", whereas all the other refs that live in the root of the ref hierarchy are just plain refs. Thus, we do not need to check whether the ref is symbolic or not. In fact, we can now avoid looking up the ref completely as the name is sufficient for us to figure out whether something would be a root ref or not. This change of course changes semantics for our callers. As there are only three of them we can assess each of them individually: - "ref-filter.c:ref_kind_from_refname()" uses it to classify refs. It's clear that the intent is to classify based on the ref name, only. - "refs/reftable_backend.c:reftable_ref_iterator_advance()" uses it to filter root refs. Again, using existence checks is pointless here as the iterator has just surfaced the ref, so we know it does exist. - "refs/files_backend.c:add_pseudoref_and_head_entries()" uses it to determine whether it should add a ref to the root directory of its iterator. This had the effect that we skipped over any files that are either a symbolic ref, or which are not a ref at all. The new behaviour is to include symbolic refs know, which aligns us with the adapted terminology. Furthermore, files which look like root refs but aren't are now mark those as "broken". As broken refs are not surfaced by our tooling, this should not lead to a change in user-visible behaviour, but may cause us to emit warnings. This feels like the right thing to do as we would otherwise just silently ignore corrupted root refs completely. So in all cases the existence check was either superfluous, not in line with the adapted terminology or masked potential issues. This commit thus changes the behaviour as proposed and drops the existence check altogether. 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 --- ref-filter.c | 2 +- refs.c | 19 +++++-------------- refs.h | 5 +++-- refs/files-backend.c | 4 ++-- refs/reftable-backend.c | 2 +- t/t6302-for-each-ref-filter.sh | 17 +++++++++++++++++ 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 361beb6619..23e81e3e04 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_root_ref(get_main_ref_store(the_repository), refname)) + if (is_root_ref(refname)) return FILTER_REFS_PSEUDOREFS; return FILTER_REFS_OTHERS; diff --git a/refs.c b/refs.c index c1c406fc5f..4fec29e660 100644 --- a/refs.c +++ b/refs.c @@ -856,7 +856,7 @@ static int is_root_ref_syntax(const char *refname) return 1; } -int is_root_ref(struct ref_store *refs, const char *refname) +int is_root_ref(const char *refname) { static const char *const irregular_root_refs[] = { "AUTO_MERGE", @@ -865,26 +865,17 @@ int is_root_ref(struct ref_store *refs, const char *refname) "NOTES_MERGE_REF", "MERGE_AUTOSTASH", }; - struct object_id oid; size_t i; if (!is_root_ref_syntax(refname)) return 0; - 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); - } + if (ends_with(refname, "_HEAD")) + return 1; 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); - } + if (!strcmp(refname, irregular_root_refs[i])) + return 1; return 0; } diff --git a/refs.h b/refs.h index d0374c3275..8a574a22c7 100644 --- a/refs.h +++ b/refs.h @@ -1052,7 +1052,8 @@ extern struct ref_namespace_info ref_namespace[NAMESPACE__COUNT]; void update_ref_namespace(enum ref_namespace namespace, char *ref); /* - * Check whether the reference is an existing root reference. + * Check whether the provided name names a root reference. This function only + * performs a syntactic check. * * A root ref is a reference that lives in the root of the reference hierarchy. * These references must conform to special syntax: @@ -1076,7 +1077,7 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref); * * - MERGE_AUTOSTASH */ -int is_root_ref(struct ref_store *refs, const char *refname); +int is_root_ref(const char *refname); int is_headref(struct ref_store *refs, const char *refname); diff --git a/refs/files-backend.c b/refs/files-backend.c index 0fcb601444..06240ce327 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -351,8 +351,8 @@ 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(de->d_name) || + is_headref(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 36ab3357a7..bc927ef17b 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -354,7 +354,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_root_ref(iter->ref.refname) || is_headref(&iter->refs->base, iter->ref.refname)))) { continue; } 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 Wed May 15 06:50: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: 13664714 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 A0DC343AA2 for ; Wed, 15 May 2024 06:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755863; cv=none; b=O2Wf6J7cTWnoW0uf5sAVZIbScG/ouAfFA84/5JIfynl8rtbZifQDX0oArLNwX0kkgnF07+iBu0Olad71+/ZKksVyVRh/RjvbpR74lCaFBxKEg3fmvFYfcNKkvxxjD4oqLjqsx8SJLwl3OI0eea9KVc810xEvvL8hHTC/EDqT5tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755863; c=relaxed/simple; bh=vFMXqcxUMiLtjQd9gLzM2YquBGo9qfMmUD3uTr2qEwo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZLKtoI9bQ7U7Y1tkRWXEH2g9cABl7LdWTY+XmHGOcakwa/Rj1zToGpbTWk0ptI4FQm1nIxAldB8mYSwExyGUs9hMUBg7bkIHqVK0V9ZNK5v2TAZ+fNMbosLJK3Js5vkjND0/dg7uSSVNKNxqyVJbAMRXmim97rZaxhrQZG/8b6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=RJcT6k9b; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EXNOa/It; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="RJcT6k9b"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EXNOa/It" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id D467A1381184; Wed, 15 May 2024 02:51:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:51:00 -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=1715755860; x=1715842260; bh=/WJnePAzIK TsEBkLth0cvDssKG8XeXXG6FTDywnZ2E0=; b=RJcT6k9bLcRLtERvjl2gUDsX4F iDiNsGGXkT40adK6/7UIqFsdWvJC7LR8DZV9zSF7Bpa01EG1u8C38OsUJwADYYRP CFNw5cVUUWOCytdnvFPxvrUrr1AG8ztNcOoTARnvS5UIGAsck6OEVRWwvt/qhlKq TjW84KnFNP8QOnP94vu87nyaoeQ7ONhwXwiJhGKJfgRF484b1aCTOde6gyZsJNm3 0wRbeSRM8nSp2QFeUjeiiupC/te6Pc3g2Bb+AtQV8dKdLhm0eyMpBtta8NEa2ojt VCdu3/YEIwZ+0ZVpOczvHe0ppmlzrXBITB9wZirfTeC8p/dPTajPdKcX5A8A== 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=1715755860; x=1715842260; bh=/WJnePAzIKTsEBkLth0cvDssKG8X eXXG6FTDywnZ2E0=; b=EXNOa/ItIX0E8r0y4BNJSUWJBVFxbtyWq8Ko5Ly/treu rUcWDzxhs5t2TKlhReBz8WzXoPXmKsF2y4xiupV0GV0tc8X3UQBbJY40E+oiq6rc VW6PwYzvtuXMJUjd5SmFCB19mkYlhDD3nPMtkRoLB7H1dtfnwtFPRaZIAIZXUJhD /gh5PNam784YQrh+hnqWTWJE66FBFiRvwQt22l/CDotfOWSDstZ+2ADQ25H/QnKP zJMG9hQcmUukRUnjTEH+FVriS0p0w+hlfgNY9Iv7EtNhzjyrnKCLT/K9TldD6mRJ nqM2ccdvN6a+gSF5OJLbefNTYltbtLO61q8WiHRUdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:50:59 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c76796f7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:36 +0000 (UTC) Date: Wed, 15 May 2024 08:50:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 07/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 call both `is_root_ref()` and `is_headref()` together. This also aligns behaviour or `is_root_ref()` and `is_headref()` such that we stop checking for ref existence. This changes semantics for our backends: - In the reftable backend we already know that the ref must exist because `is_headref()` is called as part of the ref iterator. The existence check is thus redundant, and the change is safe to do. - In the files backend we use it when populating root refs, where we would skip adding the "HEAD" file if it was not possible to resolve it. The new behaviour is to instead mark "HEAD" as broken, which will cause us to emit warnings in various places. As there are no callers of `is_headref()` left afer the refactoring, we can absorb it completely into `is_root_ref()`. Signed-off-by: Patrick Steinhardt --- refs.c | 9 +-------- refs.h | 5 ++--- refs/files-backend.c | 3 +-- refs/reftable-backend.c | 3 +-- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/refs.c b/refs.c index 4fec29e660..9fb1061d52 100644 --- a/refs.c +++ b/refs.c @@ -859,6 +859,7 @@ static int is_root_ref_syntax(const char *refname) int is_root_ref(const char *refname) { static const char *const irregular_root_refs[] = { + "HEAD", "AUTO_MERGE", "BISECT_EXPECTED_REV", "NOTES_MERGE_PARTIAL", @@ -880,14 +881,6 @@ int is_root_ref(const char *refname) return 0; } -int is_headref(struct ref_store *refs, const char *refname) -{ - if (!strcmp(refname, "HEAD")) - return refs_ref_exists(refs, refname); - - return 0; -} - static int is_current_worktree_ref(const char *ref) { return is_root_ref_syntax(ref) || is_per_worktree_ref(ref); } diff --git a/refs.h b/refs.h index 8a574a22c7..8489b45265 100644 --- a/refs.h +++ b/refs.h @@ -1060,7 +1060,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. * @@ -1079,6 +1080,4 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref); */ int is_root_ref(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 06240ce327..6f9a631592 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(de->d_name) || - is_headref(ref_store, de->d_name))) + if (dtype == DT_REG && is_root_ref(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 bc927ef17b..821acd461a 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -354,8 +354,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->ref.refname) || - is_headref(&iter->refs->base, iter->ref.refname)))) { + is_root_ref(iter->ref.refname))) { continue; } From patchwork Wed May 15 06:51: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: 13664715 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C8BB43AA2 for ; Wed, 15 May 2024 06:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755867; cv=none; b=i/ke/wsU8Qt9mS3vPsCpzBCBtYqyu9F3c93jkZbQhP4u90DrKOhk/BJ41D23H4fScDtDuqIfuAuR4ch2Io4jIfZG3SrEtKkyKTsMaDTqxEuuJ7aCWl+AzXYIsvPwGCDUuxU7HZ86QJqzLV2BgnAKFKJ5S+iPPXB23pAVphsbm2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755867; c=relaxed/simple; bh=7mP3HgpFX84d7LZirz1ZCAxaq4KFYGG8EL1WqctNPrk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nxExdFzpy6KdlDgWOg3U0/fy3XSb7EGQr9j8SFnEGAwxAP0dyXfVfcGq0fONyo56ELAEQa8NgThJVcFZij4xabw32PmTYqwDShtdRzvrAeiiflGCR3xfd5oDQ3pr2rIxfnETOMW2X701oS8oh74VsoK4EkffTWDYLCV9TjdZMq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Rg5KMvNQ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bjN2zvdS; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Rg5KMvNQ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bjN2zvdS" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 8BA8A114017E; Wed, 15 May 2024 02:51:05 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 15 May 2024 02:51: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=1715755865; x=1715842265; bh=HZ1jZ16TfA Oda/sFVnEaQu5iF45jzBbUuFB1PhF99fo=; b=Rg5KMvNQjja8OjUi3DvP1gL16p HuTU8f6xEe3Pj+zKrAkKFpc2ZQSojiubLc62BMyTzPk4bVzkQ3wh6KbeInefPM4w z+gwrBOPA8q13bosAwYoO1u1g/qhjh4dIPnDvvBO+/vTjxKBgIADkcXE+Ty410u3 jPxepjU4XaMBrPlK8XVAF/9Ck0cg/mB+trNsD/uk5LrV88mxFU3kS6kRNNyep36a jE6wGbZN0e4MGIG8W1tzbHSZV5I6GVsNAH2ybvwj0XDUKMsGRU/V568qdi4+oPv2 KknMpneUIzKcC8awfVSgfsR9rrOCAtxDb0v+LsGK3YZM7LevNpGo89W8kSlA== 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=1715755865; x=1715842265; bh=HZ1jZ16TfAOda/sFVnEaQu5iF45j zBbUuFB1PhF99fo=; b=bjN2zvdSX0Zu9KZb+G+WYAZbf+GxXV+5cv7lJYSBDvde Y4LHDDCMFz7NjVNwUq3JGUdGGMQ0IY14aQ6B1MSDfUNATLd2K1Iwm5C1rWIwR7eI 84TvVKICEu0RDQUHeI0lD+wXkkeMko1Z+DFv8lpYSNdDNNBQ8AV8ETKVLibbC/po AiRf2Ed4BuFTjV8yugJDM/Ek+eQene7+aNTAKTZHFh0JvfxpK0AYNOmNChtnFOrG mGHZrqvaIBUMLC5l/GPdDi3UmzZpQQTTCuMYVsMU36zfKdV4Nwpsz5ToFzkgN0xn BxmfkkNdOP/loXaYtTmjJGzf5FH068Nj7cncFsuw4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:51:03 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 82373e17 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:41 +0000 (UTC) Date: Wed, 15 May 2024 08:51:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 08/10] refs: pseudorefs are no refs Message-ID: <5709d7f780a990ef28bb1bd7de3d336ea994a8d5.1715755591.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 9fb1061d52..2074281a0e 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; @@ -868,7 +899,8 @@ int is_root_ref(const char *refname) }; size_t i; - if (!is_root_ref_syntax(refname)) + if (!is_root_ref_syntax(refname) || + is_pseudo_ref(refname)) return 0; if (ends_with(refname, "_HEAD")) @@ -1856,37 +1888,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 Wed May 15 06:51:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664716 Received: from fhigh2-smtp.messagingengine.com (fhigh2-smtp.messagingengine.com [103.168.172.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 283A94C62E for ; Wed, 15 May 2024 06:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.153 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755873; cv=none; b=cfhZ3c6RE52Ws4l9pSo0+27AuCd0doqxWhX0MdetSh/VJy35pcyGxMBVrRRd4mllB7wH/c9jjf9qkrAsERgWBnPw/EoSwozVDxYDggVzlBWu2hA5ZlUcLqQCGF/V3OvqeS90dalxz7bbM/8P2b6d40opwGQFi6d95h5lQp5P8UM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755873; c=relaxed/simple; bh=ju+bKAx5I6JVpQlwJmrPeKmCk3hEfSVaFk4IMdxbOZk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jM40ao1OkY6628+l8nucTGFQkMyN89bGOjmuJFpWgmQFuwul6gP6YI7sV4lT20JY9pDcErlIpohP9Ngs8DxyYar6wPEaQ76QzgInoa1qAzmSaEJOcacdQSRtKMPB/56eaBH4gGiyG3yUHM6PEMhlLV1+C7CD9neqMJRiK1UHeXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=QVwHYjyw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=b2woRis0; arc=none smtp.client-ip=103.168.172.153 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="QVwHYjyw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="b2woRis0" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3F075114017E; Wed, 15 May 2024 02:51:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 15 May 2024 02:51: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=1715755870; x=1715842270; bh=WK7BgqG7Ug KwFr+VCwAM/jcRFEexSnofeAC1otEEAsE=; b=QVwHYjywCs4r2QlXhk8EaErnMH nsqWGnyNrmM7xyNnUkI0pZm2DWc1nWqpO8aiBADiyJX1oJQfFf0E38u+YX1J19Kw 2+ott7sLK0xpbGXJaRLtwfzfRWjjFodcg03qys4smgkZ4kkLWfYS/1B5xywz95D9 lNvKXUkeFLBIhGp+rMxrpr0Mm1x7u8FvCzzCliyCigBDV0FYE+eo1BYoyJvXRrAJ QTYwvwbsR3tAtxk/9v4tZnjbnxpNuA5AiFw1ukCxaaICFswjbPE8/P+Vs72ZzAa1 TMTOrV1XX/Z6YF2PQQYdQ/71TF3nizNi3vkpmHt/ovJOET+yTK2BNLuZ/mbg== 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=1715755870; x=1715842270; bh=WK7BgqG7UgKwFr+VCwAM/jcRFEex SnofeAC1otEEAsE=; b=b2woRis0vZJoT54FfL6ByDYQSEtDJ+7H51loAR631dfX XhOJ/j9+ZwVjLZMaEb36/Zn8bXJFU6fOv96gnz3t5/dNR6CJueZ3ddk5g8yxsgH9 YJDqvF96oHowHfUq7eIReJSW1ISqHBK0viP9NjMl+xAeL0scP322ERplGMulJHfF oxbRJB8qh8ir/aQHAM836HE4/kebkFnwhPCJhZM/vrPP4h40PUUEGfXfoW7o3GVB vgBt5uppUeJrt9IcmXEuXZwsA/03cV2VQYhR7LMQfeCtVvxLM1EcNzqvZnDEzyus EgIfjHJ0Nubv9d30fvLxy4LOcXoph62nrEaZI0uMgQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:51:08 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id f2d1cb45 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:45 +0000 (UTC) Date: Wed, 15 May 2024 08:51:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 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 23e81e3e04..41f639bc2f 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(refname)) + if (is_pseudo_ref(refname)) return FILTER_REFS_PSEUDOREFS; + if (is_root_ref(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 2074281a0e..c13b8ff6d8 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 8489b45265..dc4358727f 100644 --- a/refs.h +++ b/refs.h @@ -1080,4 +1080,22 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref); */ int is_root_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). + */ +int is_pseudo_ref(const char *refname); + #endif /* REFS_H */ From patchwork Wed May 15 06:51:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13664717 Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (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 D6EEE4F1FC for ; Wed, 15 May 2024 06:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755876; cv=none; b=drbcVLLAla7msSr1e1+DmTauBncD9D7zCnYO502VxH7C+YScw1N60W24gnJUZ+VGDJP5IGjkia2dcaUyb7raHVnnPA9dkBmFzGFWfSZSqmaCaTB6ppSHligfv36RgsM9Icab8IbgTuk9UpGQdZD3YufYj/3omcv2/6MlG8pu7wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715755876; c=relaxed/simple; bh=zQOg0n8UU2e0fYUiJFRXDOOmeQ+0kge3FQjwVfsVpus=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VZzyfq6Nk+KiVEyWAx5rw07/sDjASCklklYhHKZfOttEOYSH2i6qLJ2WMbaeOQN9RUqZREn4BJTdGMt2e9KxsDG/zzrz3Vy9vdKSEd7AJWjBnVlT2l/EsBXSqfBBVRDUaVEvfpms6/D1k2893SNcFY9F3jtKHOZ95Tuuiq5RglM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=kmJ0vgAn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cOWrYokH; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="kmJ0vgAn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cOWrYokH" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 05BED1381171; Wed, 15 May 2024 02:51:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 15 May 2024 02:51:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715755874; x=1715842274; bh=5IP6Gy8Ldk cTh+X5ZsPykC0IRx1WnEAXLECn+tlhf9w=; b=kmJ0vgAnZ5arYOdttEkdpiC8aT Vu3HZc9xjAuNNYT4VapAc6MViu6PeQHhR9uqCf7l8yd7nI/SVeCUU7yv2zvOCLwg brJ2IFj5tmXfzf26tG3W/2oV2NWfMt7YokhlNvOjRoYYGLk0x7tFl+AQl5kUAx6c BtVl56uX2XcOhbof/AzPyQ0HM5jeLT030HMBJvixFKR4l4e1RlceTWT/YFggBvuU LAcYipt+lCiFnXry2U5woe6U27V02oz42/v1QcBzs8Af7V3QE9mXhWrFFGr69PQm Ef32YRPrOlX06auV+z7BIrnUPcUH4dxodWhd9VeUo78CzGKkGcugjYQUEuyQ== 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=1715755874; x=1715842274; bh=5IP6Gy8LdkcTh+X5ZsPykC0IRx1W nEAXLECn+tlhf9w=; b=cOWrYokHqmQQcjDUxA2C/P6+RpB1BQ8woQO96iYpT6t9 RTs5+38+wT7ZUUgpLj6fROAjAzE9/XJKQbboDRqjvwV2ba76abEt3cQb/a5zItIM DlN85QjH1szaHnONO44qMNhnw0wzmQQdoeDeP4fW+8tslOcRDVIo20p/aQUudH30 hKZ7amDyz5eSr3995wgoKd3ptrTLBZzqWJFImWWSaLrQnfqt09DcJqpS9cwUo9+b af00STkcv1ogtZ6JZnBw8dJF5Kh2iV4zUW+9TI9biYb61yV3Tvo+Iqi7F17nwGLA o5URw9/88rLczYayu/0GfxIUvAy0+DjulvN/FjqnMQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdegjedguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 May 2024 02:51:12 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id c91f9eb8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 15 May 2024 06:50:50 +0000 (UTC) Date: Wed, 15 May 2024 08:51:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Karthik Nayak , Phillip Wood , Junio C Hamano , Justin Tobler , Kristoffer Haugsbakk , =?iso-8859-1?q?Jean-No=EBl?= AVILA Subject: [PATCH v5 10/10] refs: refuse to write pseudorefs Message-ID: <15595991dce11b7666d8447691e5977635cef1ca.1715755591.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 c13b8ff6d8..9abd9e5b86 100644 --- a/refs.c +++ b/refs.c @@ -1263,6 +1263,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 9441793d06..2af277be9a 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)"