From patchwork Fri May 10 08:48: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: 13661053 Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 75D8614A0AD for ; Fri, 10 May 2024 08:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330894; cv=none; b=mayUj4Ka86Oswly327TnF3BZwp0czYvY3bR0ji6uw72yWuqQwNp0Jbwgllovpxqcyl3Z2qDE0cFt/RrxiqWEff+oRWXF5HdHLwSP9Dw9QHj1/vf4xyyabLDRs7xiUjwxAR7brDZRQjRUyDsQG9svXCwyhI1CwUxwKyeZbuCLR7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330894; c=relaxed/simple; bh=TznbHIGVjzStsJIrVXfWsGKLdlsgYBZ1C392R9vJxxc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wz+Ny/S+6x9LYo3M+00P0npld5IoEl5s7FxgPVY/Ll2KyzGoTWpaWGuNWUip/aeYhu+tB30f09tZwANq4xudejDBxeDFJVWwefiUvV1CdUE02qlnSwzRCCOxild6wEKh4ZAfFjW6LdlRHMX6p7z8X7n3YiOQcXowdtH3czzG4S4= 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=a64MS1t4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WoYA8pmZ; arc=none smtp.client-ip=64.147.123.159 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="a64MS1t4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WoYA8pmZ" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 4582318000DF; Fri, 10 May 2024 04:48:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 10 May 2024 04:48:11 -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=1715330890; x=1715417290; bh=tF9jPXSkmF ov/BLoDV7LvAkJ4kqjbA6FLNY6UyprSaM=; b=a64MS1t4lm9qtIyZGzj1GAPBZm 1em8Z8zW1sC6zw8067YSRSxGiYNd47TrDdhe486K8RXR8+BVhoQA0CnCm6mHFMVm xtmOYkEUlGWXpCFgG2V8hl22rga52mJbNSRzbUrDHvn0wyosD1MJrkA/9ppa6cV3 jGAHMPBKiOJFVoP03dsH50ez67h7AnjHZQYTlVPdYRAz2G6x2sxoP/o5SgjKXvCZ fTSxF8WXemVepRIxwSVevjt5Hbav+fq/DMsdiuwucLEtt27voED+1JKTazYz4Kiz hjcVhStB4c5YaeAvRx0SefELbM7AckMI8VKExu7xBIHdUn+YPh/pz6dl3PZw== 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=1715330890; x=1715417290; bh=tF9jPXSkmFov/BLoDV7LvAkJ4kqj bA6FLNY6UyprSaM=; b=WoYA8pmZDg6E7V5WQMSsiS7Y/Sout2KnLliT1seRPr84 d6K6YCzuY7XeIwJiRU3Qua76xAnkcIuiTV6a4H9cyhXlNJKL4Wn3q7RUzGY/R4WL 0plSLAMgrNNzJ4I+RvjPH+U+339o4Zz26ZNUBwuSJbLN0Qyb4bGdPOuwwDtYBlXL 5ACq/uNby+e8LnG4x8V/eJJVR7btlI+X8bfiOahl8iBNiW218CIEiXxT9wwvz4UO krI4fzFnTkNpZqjHWeifO2r4s2bztRALLi6jtiYLyfP9eF7pVZXWIJczypIDnCzh f5WoLF3FxvJ1MDlYrbJKbwGNRuomvPBmrLSb7uLzZw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:09 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8aa587cb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:47:56 +0000 (UTC) Date: Fri, 10 May 2024 10:48:06 +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 v4 01/10] Documentation/glossary: redefine pseudorefs as special refs Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Nowadays, Git knows about three different kinds of refs. As defined in gitglossary(7): - Regular refs that start with "refs/", like "refs/heads/main". - Pseudorefs, which live in the root directory. These must have all-caps names and must be a file that start with an object hash. Consequently, symbolic refs are not pseudorefs because they do not start with an object hash. - Special refs, of which we only have "FETCH_HEAD" and "MERGE_HEAD". This state is extremely confusing, and I would claim that most folks don't fully understand what is what here. The current definitions also have several problems: - Where does "HEAD" fit in? It's not a pseudoref because it can be a symbolic ref. It's not a regular ref because it does not start with "refs/". And it's not a special ref, either. - There is a strong overlap between pseudorefs and special refs. The pseudoref section for example mentions "MERGE_HEAD", even though it is a special ref. Is it thus both a pseudoref and a special ref? - Why do we even need to distinguish refs that live in the root from other refs when they behave just like a regular ref anyway? In other words, the current state is quite a mess and leads to wild inconsistencies without much of a good reason. The original reason why pseudorefs were introduced is that there are some refs that sometimes behave like a ref, even though they aren't a ref. And we really only have two of these nowadays, namely "MERGE_HEAD" and "FETCH_HEAD". Those files are never written via the ref backends, but are instead written by git-fetch(1), git-pull(1) and git-merge(1). They contain additional metadata that highlights where a ref has been fetched from or the list of commits that have been merged. This original intent in fact matches the definition of special refs that we have recently introduced in 8df4c5d205 (Documentation: add "special refs" to the glossary, 2024-01-19). Due to the introduction of the new reftable backend we were forced to distinguish those refs more clearly such that we don't ever try to read or write them via the reftable backend. In the same series, we also addressed all the other cases where we used to write those special refs via the filesystem directly, thus circumventing the ref backend, to instead write them via the backends. Consequently, there are no other refs left anymore which are special. Let's address this mess and return the pseudoref terminology back to its original intent: a ref that sometimes behave like a ref, but which isn't really a ref because it gets written to the filesystem directly. Or in other words, let's redefine pseudorefs to match the current definition of special refs. As special refs and pseudorefs are now the same per definition, we can drop the "special refs" term again. It's not exposed to our users and thus they wouldn't ever encounter that term anyway. Refs that live in the root of the ref hierarchy but which are not pseudorefs will be further defined in a subsequent commit. Signed-off-by: Patrick Steinhardt --- Documentation/glossary-content.txt | 40 +++++++++--------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index d71b199955..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 Fri May 10 08:48: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: 13661054 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 83A1614A0AD for ; Fri, 10 May 2024 08:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330897; cv=none; b=Rhbf2NMYDeNnNK21vAAPLYYUnHuBBroCZrWOKQm1zzITsoDzCZNlwyM2mqPJogXc0bdci5YyVigvg5AOHgpFYfi0waos7CNpPMXnBm8EBzdrCsDykPiOF5vRmmYQwafE9/piSEN2wmZyjyZwTJs/Ps6STvZWkIF8+kVJkwSPXvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330897; c=relaxed/simple; bh=9FaISbscAIsRhj0bfHbywBoMGlSE/hpXRHpgziYtfdc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tbbzjPGv7tRZFOxd6KDP3/Z5YIJpgMb5aeQ/i5yasODZeNDCw7KpBj36skLtIket2H3vJvPlNTZHhApjjwAireIpOyNfGC9ilqO1ahsozswF5FKcze0E8FSCpE6iO3ulJUqYtt8ZDWZN2OI+wwFiUoKW202q7UwdgNetswGdScg= 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=u33HMdH3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hg/HWYPN; arc=none smtp.client-ip=64.147.123.149 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="u33HMdH3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hg/HWYPN" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 4BABC1C000F3; Fri, 10 May 2024 04:48:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 10 May 2024 04:48:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715330894; x=1715417294; bh=MEDK2w1aHL ihXx6ZtkNWIuk4veq4f7qX5JPAOQwQbbQ=; b=u33HMdH3loIsuLIBtSvZpqIvWI QXyfCLV1yj9yaZ4ctihWm3LcdbBMNaGzZnDuOmpD9elLVJZB4SdMRP5uwPzPzAIO exldb43eARbMHwmYIUNmJfzfr5ZD4eVFnDeImbf2RLTeOBLokJl1rDi+m+2juIbK xWilIWWE+rxjrsAqG/Nd8jKQzKpxOfYjtsEW3q4nWVK11sW6pVXhQ1b/Gpkhtssd Oo1qp48wFBMIfP0r5PhwOBjF7J/b0OhJuDXLQ5T24KJXDDNmqIsSq2mIbfVfkvYn ZAD1wS9lhqRckS8BZPVoW5wDOZJ6zEPGF38MOjfTpDN4fS77GMZ/uvtoIIgg== 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=1715330894; x=1715417294; bh=MEDK2w1aHLihXx6ZtkNWIuk4veq4 f7qX5JPAOQwQbbQ=; b=hg/HWYPNrtuLVDyL8xIo7rO1PUDJaypOxE2WE8IZSctQ bOOcyc7/HXv8amjhS9iq7llfduQbyFBirZutBUtDX5S7aotEPWYDnZ3iXERspleJ W1Gfmp/w6PtawJdU5ymD/lJYOIRc/cufbJo+2Lp1TPjc2tgG6ElLbd9J9uCQUlO2 sjBiHOmVxVjaVWeQzlZwjimmuPMKIgIxUDiDLpfhsjkqjolPH7e/EQNHHK7ZCcfD 0KNQqGbyljFN/UVUBkdeF5ZU2pBb0NIdSMMJHP1uG8Zie1Z/NfL16CCslbrqAhsP E7YekJl9M5wg/R4piXcw9rMT8pE8sl4iz0nx4k7xIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:13 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 6224c8ba (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:01 +0000 (UTC) Date: Fri, 10 May 2024 10:48: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 v4 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 Fri May 10 08:48:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661055 Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 653A215F40C for ; Fri, 10 May 2024 08:48:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330902; cv=none; b=V0emNWU3CSTnCccHSHjDq+Z7Z6HtFMlWXQQX10znYnxmmSPFoox34upQVeSVE1/FoyZFGJOHC3cDw0FKlmtvHgAIwEmTrwtUBb+CsL1OWKC27Pn3OFsyo3svx/pHfnnq/Fz+lwY9B5Ysh/6aOAMfErRqQXIK2KoEZ6MTQp1ptvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330902; c=relaxed/simple; bh=l5tvIdZC9TD3rJEbVcdBmxWq7V8VsLHeRsfGn2HeVIo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gHKIQ3T/o4Bc/gN2nM2OSXW0SMSwCplh9wKvW3RZ/I+Uu9f8TfLeJnzth3D4Y6j/UrTtxWOE3Z6Pq04t8rEWMDBTQUMY6Xxac4zI+gjXQBYxH2Zbyt/psM3EoXYGypyLwg447mWTDw/20rgICI9gzAvGberumsBa7Jy3471dgnc= 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=WlR3xera; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Na11S2dz; arc=none smtp.client-ip=64.147.123.159 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="WlR3xera"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Na11S2dz" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 3B1011800109; Fri, 10 May 2024 04:48:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 10 May 2024 04:48:20 -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=1715330899; x=1715417299; bh=53tIwq2Ih5 cIx0HpLrFJrek7tknxrouW/va3dv5TS8M=; b=WlR3xera8hoTpkAfdaVvXdYRHw 2Eo9CKwr1bOHJaM2A+cFNmYMzRs69iKjzHfW91uhRSBNn+W4kPwW912BXsVNimWO os/nZBdMJNQLOTS1tbQ0oFejFR+i45c9onQD4PFzoWgE1d7RFVm1SbFybvNIVvwW q/pnxGZHt90PPPxWyWuQ3640sIjmwCJ2tHHF9eNuubAa5mR4F7lL7fbsL93Frp+J EEK6oVZvO8N3Zn6m1dQu9Y7zOWI6eqG2SgMwaW0FV+wRZ0EdmAYZS5Twnrc5Df6W YlTiGJ0afV9jUK3p6qjxFfl6zQTaGkMwJxURkLds0NXDX9oeD8jU/KqT5czA== 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=1715330899; x=1715417299; bh=53tIwq2Ih5cIx0HpLrFJrek7tknx rouW/va3dv5TS8M=; b=Na11S2dzHAd9FhQTblES+WGU8M5XmET5Fd04lakJbdMd LLfDjY9CA+NeahubE9RlaTLrSEuNLpg6LvkCXItYtQT+gq5PxofA1eEysI5cEdlY 5+JcRazKM9pVMXJcNKU6dDVDH04sykrjjVf/cgf1rHS9aWalppLFi51qtlKIp32N CBFbpzncSFxoBpajprSaIK3LISHU6HisLkDNdERR0Y5rAXJxyolbzwpV7a0q0zhI bHdAWlFItbyqL6Fo15yvu/bD6kAkGsahbb57piCjgK8IKvczWz71yEEGvIglOCxl jtH5uebrV6wQL57a526ko7dLrM9vz7CoQ0Mgh2Cnug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:18 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 06be75a7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:05 +0000 (UTC) Date: Fri, 10 May 2024 10:48:15 +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 v4 03/10] Documentation/glossary: define root refs as refs Message-ID: <79249962f5798ac31724d32233ce814d99afd649.1715330206.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 Fri May 10 08:48:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661056 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 4BF8715F40C for ; Fri, 10 May 2024 08:48:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330907; cv=none; b=EwuyboSh3RV9p2WKpE4BXcDZbOJpKRAcOGAmtryX8WAc4WJCFX1iZ7jYRhArR4Kuko3cP8mIstZe3aW/vDigPzICMeD/XWxhTFkw4nlpkLYe/mOYpjx2Un3CrYTYzUpMJFUrjekdMG+UuO16An0weg1KNa7ENKyOcpQxIyvvoFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330907; c=relaxed/simple; bh=zLfFryk77Gf2iUsZD9yOjwEQqfvCqYIncfs6F7AyVvk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=icV3IvXGG5mM0Y1idXmvN1MmvmdrfZ6PlKbXM7siwz6Ox7bXGLfMPVqD7o30XXlVSdqKbby25dNerBrMarGecquICkTGLum/RzlDdBCA5JmfhNbrKI/rtasjhWfGvYZkeQZESk8yqV+UQYnbN0jLBg55wxpB7DbVsqTsrz1TZUI= 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=lz1pBkBM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RFhVLSKe; arc=none smtp.client-ip=64.147.123.149 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="lz1pBkBM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RFhVLSKe" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 299361C000F3; Fri, 10 May 2024 04:48:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 10 May 2024 04:48:25 -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=1715330904; x=1715417304; bh=8YFPulj4zu wVQQMxOwsvE6ds5d493mJhxZlO4Wic6Ss=; b=lz1pBkBMJ6VZPDV2197F0OnPXd +mFKCxezoW0o8IqZ0qEp2Yyjvtb+gwQlbD6TVkDGjWPMkkZvttLzBADCa9ehXNzA rPDWIuiPKBEkSCiA10eJW4HaFHY6YGF/CYfP+mssquUJpbFN6WRYRgMzMWbp1V5l JeS/jeCvjRjAL+foxh7PqL7lZvLvT7klSoojvZPIc7GHCxg2IN+pTU1s9DV+VqBG h+Mhh3hqES2KCblu03mYh1OxN2yqMIXsL6y1ebikJv6uCUkstc37LYaBwFWzSjEE Mxkoy/R2u3KKgmKAUlhXIQPa+Zh3At/5QdXlAvcq+Z9z9tE1NHKgBsdG+S8w== 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=1715330904; x=1715417304; bh=8YFPulj4zuwVQQMxOwsvE6ds5d49 3mJhxZlO4Wic6Ss=; b=RFhVLSKe70CJEMitMNUiVBaIzEhkY3iT4DIVtNELY2+8 ujxJTrEm2VdqUTG8oq9K5w/nt5N93W1pzuho1b+j7ItyuDIHPEs1U7Hd5Q9IsBKU WBruc5JXnN95yPFmkZWAvJq4s81vxqkGhueq2vlRQF0cV2Uz3+v7/5LWSOjaP7zS HvO/zO2ayOUrIpk8ZZulIKQuwS7n3OvYLj1UyRBCXT7Rbbl+teJe7ENsVf7FKI53 iQdxGjf6AoeXjkmYZAso/T86/DLePKj6CqoLby62z4Ju5u+8QzIrYcP9l6i4nm/G yw9CdhYrypDUyis30lnjxCXFP2JNpGbk7KPt7hUmyA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:23 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 55853e25 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:11 +0000 (UTC) Date: Fri, 10 May 2024 10:48:21 +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 v4 04/10] refs: rename `is_pseudoref()` to `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: 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 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 Fri May 10 08:48:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661057 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 1709915F40C for ; Fri, 10 May 2024 08:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330912; cv=none; b=jYLx51sLpe6f5CH9ip+Y7kudPTeTFjB5lhymYOyTRVkUs9qrmspEMD2STbabd2VAFdYDX22ck8nYzdUuivlNB1cvLLhP/mXF7A88OMGFZaw9sJfjpOtQFM97cRXecVwyBAFXYnzEi3qhZKiS1DZEOtra1qfgRrHix25ntg/gtDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330912; c=relaxed/simple; bh=Qm0v3n3cT6p7CopohHHj2US+nmVWtP9O7WA5m25MK1Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bkSIzCYAukfDcT/ob+Yd094LhbMM4JQfe/P/gyuHL/ntM6UQO5pe+5iARfNun12NcVKdgqIRQWipZLhgwIzGDLKdDtm8q5zjnrexwm7mblL2D6xffAMZ8Id0Hjt0nCqn9buSxn3PeY/QGXC+6KgA7Fab/BokgpwL6/2DyJylrf0= 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=CswoF7YE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UKrf86an; arc=none smtp.client-ip=64.147.123.149 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="CswoF7YE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UKrf86an" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id 1E5831C000F5; Fri, 10 May 2024 04:48:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 10 May 2024 04:48:30 -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=1715330909; x=1715417309; bh=NkJB0JE2g1 g+427Ni3GUN07MPLRO8YiWLgoCIDjskSM=; b=CswoF7YEsePv9QGKluSEHWIMNb ygcw5PyNVIZVDttZLHBRWsVvxmnNBX7C9Lb/MoKO1t/8nPcoGZSbCJoAYAXYoqUM SUyYc1/QFjEkzN1kIOEE92DZGYSZxyFIkRzgdydHYyk3fekVHFWOFOm1UtUEjeqC MudjH9JAAnWSXtg9N9oR3eABde/EZv8vnzEdazgoU5/EVSzN44nsgs0zblptq+gO XXe7ZFGdKl90FVr032sSZ2pfA1WinQfmW6X6yRXaA20AJAdgTRmGLSETQ0CJz+yC yrs6amYFJ8d9Y7LnRwxHf1J9rEGoRWYFZKDR6xzyFt7s6YzSS4AO7wMUgZsw== 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=1715330909; x=1715417309; bh=NkJB0JE2g1g+427Ni3GUN07MPLRO 8YiWLgoCIDjskSM=; b=UKrf86anEwFvNOtwR3sFQFfcpQnYdaskCM/T7bgIEKCr QJ4bq5tZvI3YjlBeQFtZRWpASaFTaSjOCJXpLSC2tHx+914MhMf8DGdIAVdJdtRg YtJo+T13gIQ1MaBNAQGmcwe9UxuDsTHRk/VbJvXhwpwHSVCYD81+G75G9fb16A2V nEIU2J9qs48RSYY0PcLgF2aXz6APZGfA/x86ySEBYQ9wWaprM0PBYIbqdzdaXuIM HUPDYjfPA5mvEARgtHbh4SX5/qxdIZTI9OMX4s4FsfQZHVy/jgViC2brCah9nCgP oOPCT4Hr90MdPYzST9Sn9Zgv/oAuzM9Fg+d082M15w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:27 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4de4c7f8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:15 +0000 (UTC) Date: Fri, 10 May 2024 10:48:26 +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 v4 05/10] refs: refname `is_special_ref()` to `is_pseudo_ref()` Message-ID: <2c09bc7690f1126d5f72ae809fad5e4832beb8b4.1715330206.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Rename `is_special_ref()` to `is_pseudo_ref()` to adapt to the newly defined terminology in our gitglossary(7). Note that in the preceding commit we have just renamed `is_pseudoref()` to `is_root_ref()`, where there may be confusion for in-flight patch series that add new calls to `is_pseudoref()`. In order to intentionally break such patch series we have thus picked `is_pseudo_ref()` instead of `is_pseudoref()` as the new name. Signed-off-by: Patrick Steinhardt --- refs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/refs.c b/refs.c index 0a4acde3ca..6266f77474 100644 --- a/refs.c +++ b/refs.c @@ -1876,13 +1876,13 @@ static int refs_read_special_head(struct ref_store *ref_store, return result; } -static int is_special_ref(const char *refname) +static int is_pseudo_ref(const char *refname) { /* - * Special references are refs that have different semantics compared - * to "normal" refs. These refs can thus not be stored in the ref - * backend, but must always be accessed via the filesystem. The - * following refs are special: + * Pseudorefs are refs that have different semantics compared to + * "normal" refs. These refs can thus not be stored in the ref backend, + * but must always be accessed via the filesystem. The following refs + * are pseudorefs: * * - FETCH_HEAD may contain multiple object IDs, and each one of them * carries additional metadata like where it came from. @@ -1891,17 +1891,17 @@ static int is_special_ref(const char *refname) * heads. * * Reading, writing or deleting references must consistently go either - * through the filesystem (special refs) or through the reference + * through the filesystem (pseudorefs) or through the reference * backend (normal ones). */ - static const char * const special_refs[] = { + static const char * const pseudo_refs[] = { "FETCH_HEAD", "MERGE_HEAD", }; size_t i; - for (i = 0; i < ARRAY_SIZE(special_refs); i++) - if (!strcmp(refname, special_refs[i])) + for (i = 0; i < ARRAY_SIZE(pseudo_refs); i++) + if (!strcmp(refname, pseudo_refs[i])) return 1; return 0; @@ -1912,7 +1912,7 @@ int refs_read_raw_ref(struct ref_store *ref_store, const char *refname, unsigned int *type, int *failure_errno) { assert(failure_errno); - if (is_special_ref(refname)) + if (is_pseudo_ref(refname)) return refs_read_special_head(ref_store, refname, oid, referent, type, failure_errno); From patchwork Fri May 10 08:48:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661058 Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 5403415F40C for ; Fri, 10 May 2024 08:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330917; cv=none; b=okbERK2cUtb/wVaz1F6eUfpRg2NObRrbxzOCCYvGjS6j9LHAXJD+Mt3Zs59JteVoGTNZwrIEGUXuvy65ISIgxEah5CNyxfhfW/Tf4yUZ9rIrtzobcLwGPibFJhQUexpwKHge/39UlaPGVnk9rgH/wkoPgaGRrTM8Cm6MYJk6ATA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330917; c=relaxed/simple; bh=Wh2r4dQudXOI/fAnDiay1pORjIEx6Dpz9jhCqUz6O3I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VhEy/y4istE5c3dsrmLmTmlGOWDLnJAFdaLXpyuOxLESrYTdlZAlzN9KHDCkTotnBGIao/wpH7OXnQoI5NbiCog8rKabf7zlOt9Zq2BQ+eb9WLAFACH8zzyAFGHMKtrU1ZI7ppG90KlthdkPF8HSLhMXW4wb8KQuFj4kZ1R5Dfc= 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=oV5ph2V4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UJGSrgYJ; arc=none smtp.client-ip=64.147.123.159 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="oV5ph2V4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UJGSrgYJ" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.west.internal (Postfix) with ESMTP id 26C361800137; Fri, 10 May 2024 04:48:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 10 May 2024 04:48:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715330914; x=1715417314; bh=raxYrptLK4 zWy4rwZNQ35iNmKJTm7/DsUyIRLSf6PX0=; b=oV5ph2V4l65cTnA5vxTU0EJDI6 Ov+yOkse5XM3CPikUj3nmLw8ub3QSipxvwswnMQVxGmUw+j9csWR1sMOe5x+4Hk7 9ppCO5ZXThTsrp5UblQpGNxKROU4jhX1n3zxRDlqn41Eey+Aurf3+haGhys5Ynjr 1QY6ewqQ9f9qaksrA9zI/WctT+wksr+R/vGudcyIvs83fPKY1/FhIC259HoEdrM/ ZDAht5klh1nZXjW0wgin+thrIvlXJ5joaZKirdXiKCUr4vsG1o0utOL7tmSq6eoL VF+dR4SjjcptcCJxqbjYQ7LUPPXZWb8Lety8dBpQp6gOOGOIaD3B0GlTkwJA== 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=1715330914; x=1715417314; bh=raxYrptLK4zWy4rwZNQ35iNmKJTm 7/DsUyIRLSf6PX0=; b=UJGSrgYJ6pG/5NdER7MIoGopnTrgfXTFu9X/3AK+czJO p7Ws3/NbnZIf3qwmma2l6CtRqBtNKVJoTwYsRcPKZgzbiRwQMk1wnEsXeuwn04r1 ay9F6Wxp/DEX4XOpaecSQmWlCGPGWhxdf2QmlwKAl0T5aZ7Zce2QycIxVoF4tthb tmtERtRSkdpBEvLDWqwpxM7i+Chv+4sR/uE0swxY++zD7zf+5kqwo21Pn7BxdGyv OoAmNbblXIvXiellAQb4ibW3+4MDU+7p46253Xi+ndJeBKzK1Y01qP3IRWqZ97G9 G/X1hUzhAm/SOfWYzc3UX1Ev9V0dQRHOEZuzOU5sxA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:32 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 4c18ae5a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:20 +0000 (UTC) Date: Fri, 10 May 2024 10:48:30 +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 v4 06/10] refs: root refs can be symbolic refs Message-ID: <5e402811a668ae7659175c6f91da6bbb982bacf1.1715330206.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Before this patch series, root refs except for "HEAD" and our special refs were classified as pseudorefs. Furthermore, our terminology clarified that pseudorefs must not be symbolic refs. This restriction is enforced in `is_root_ref()`, which explicitly checks that a supposed root ref resolves to an object ID without recursing. This has been extremely confusing right from the start because (in old terminology) a ref name may sometimes be a pseudoref and sometimes not depending on whether it is a symbolic or regular ref. This behaviour does not seem reasonable at all and I very much doubt that it results in anything sane. Last but not least, the current behaviour can actually lead to a segfault when calling `is_root_ref()` with a reference that either does not exist or that is a symbolic ref because we never initialized `oid`. Let's loosen the restrictions in accordance to the new definition of root refs, which are simply plain refs that may as well be a symbolic ref. Consequently, we can just check for the ref to exist instead of requiring it to be a regular ref. Add a test that verifies that this does not change user-visible behaviour. Namely, we still don't want to show broken refs to the user by default in git-for-each-ref(1). What this does allow though is for internal callers to surface dangling root refs when they pass in the `DO_FOR_EACH_INCLUDE_BROKEN` flag. Signed-off-by: Patrick Steinhardt --- refs.c | 31 ++++++++++++++++++++----------- refs.h | 3 ++- t/t6302-for-each-ref-filter.sh | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/refs.c b/refs.c index 6266f77474..d63d60a0dc 100644 --- a/refs.c +++ b/refs.c @@ -869,28 +869,37 @@ 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)) 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 (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) diff --git a/refs.h b/refs.h index d0374c3275..b15ac3835e 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 reference is an existing root reference. A root reference + * that is a dangling symbolic ref is considered to exist. * * A root ref is a reference that lives in the root of the reference hierarchy. * These references must conform to special syntax: 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 Fri May 10 08:48:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661059 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 655E8161325 for ; Fri, 10 May 2024 08:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330922; cv=none; b=quzm5NOBACiLaf/QW3X4a/i+NM5MNkgZfwzFYzVYy12+qdYDtPXl7Elus2LuV9dyj+0AIQ+COHTLbT5AMd2Tqq96QEEO3S19hClTOAlf9dEqeEeC96SE8Z3q9lTkTIVAYoL0XmXuitI2EZNInyU9FXU23smTh5yyzCmiKyrZfWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330922; c=relaxed/simple; bh=nRREW9CXSvItZ/sCqa7eKyOUGDca84oQOC30NC3XgHw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u1hHm/56upffOU6mD+40SWeZJ9uQIquox2IwS67nG+EiA79gUZeLNs1tTrilPXkeKdZ2AjuiZC9XYhHTA0a6L0ReENwZ0FeU7hgy4RtwLwpHMcgnv302HCU7MZ5/KXLuoSEE8YT4XEZQQkroZ0f+Gw6CjydHUagCtGOZ2y52xYg= 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=AtGk+wdk; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FZ480gdE; arc=none smtp.client-ip=64.147.123.149 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="AtGk+wdk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FZ480gdE" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 23C221C000F3; Fri, 10 May 2024 04:48:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 10 May 2024 04:48:40 -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=1715330919; x=1715417319; bh=fn34Ya9O4P ObdxH6vSmoW26D55ECB9lnUhi2Vq7VXw0=; b=AtGk+wdkuj6rRnWQd0GHH/tdwL ctCSZI0KMejj/n35HuxeSDFmTqgXLwRJFp2Qun5Q0+oWUtSLMyrZcOGh94ridgpF mPkLsqUiG2shkcqaQyYZPG5UWT+JqsJZnS58utg1UXJLoirmkPvD/621zl/iRtuc USoe65+SDKm0qHMQnrIydujXcKi6jch2KJI+/eLoTzqtZQgd+K7kPeQJc2aGUG5E HrDEPJ0mC5mnlX5lSa6QXQDkzizUzQeec9Z5x40Ajwza7i4akya5h/ZLyO5/OYIe EvcXkfliWu+L7SH0tu2mCmplydznGahq8vmF2FCLMJrBkhAk9DEEyXF2lgWg== 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=1715330919; x=1715417319; bh=fn34Ya9O4PObdxH6vSmoW26D55EC B9lnUhi2Vq7VXw0=; b=FZ480gdEDUlbS0AzBInX5Lj6iXdKYu7aoBG/6ICYbKln fNba7/7A7rh83DkzUOCrVNVyAOK+Hou+886VKIrcRKiU4zttD+1NYskV+HkHRj71 fBsHmr6PHJOyezx6RgZJ9eNWXvn9uJtzMzLySt1OgZNj2Raj2tOKNeTvn6hO8tVh F7kWU4KiaQcTOq889fAMTSDNQJcseCsX/u/IABMyGH0Wi09Gexhw03Xo4DSx1ZNs VgQSTE30cal61eTVA+b/u6sNoEuiElkH8UtpVX/Gf+0Hwr4vPyeafQu2zAtriWec a+uzUIPvraVPHNJ75UZHtBFhY6ZMey/xSETy113gxg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:37 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 5e6de8b2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:25 +0000 (UTC) Date: Fri, 10 May 2024 10:48:35 +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 v4 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 called both `is_root_ref()` and `is_headref()`. This also aligns behaviour or `is_root_ref()` and `is_headref()` such that we also return a trueish value when the ref is a dangling symbolic ref. As there are no callers of `is_headref()` left afer the refactoring we 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 d63d60a0dc..077ae5756a 100644 --- a/refs.c +++ b/refs.c @@ -863,6 +863,7 @@ static int is_root_ref_syntax(const char *refname) int is_root_ref(struct ref_store *refs, const char *refname) { static const char *const irregular_root_refs[] = { + "HEAD", "AUTO_MERGE", "BISECT_EXPECTED_REV", "NOTES_MERGE_PARTIAL", @@ -902,14 +903,6 @@ int is_root_ref(struct ref_store *refs, const char *refname) return ret; } -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 b15ac3835e..f6f4d61e1b 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(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 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 36ab3357a7..7ad4337229 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->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 Fri May 10 08:48:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661060 Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 6889C16191E for ; Fri, 10 May 2024 08:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330927; cv=none; b=jyAjBEhfv7oCSaPoPyziNYJhVaxT5rYlmQMuwN3poX/QlZiOPC/l2tro58Ij1L5Mi2HtM9o1S/ybWDz0vj8PPHr6LxX7ItpAaWcREc66glZjFLbDuXsDDf74QX4vzA/41c0LA/WQNxoQLIm1LTciDFHRWfK11bJ2OVmQO+Cpj1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330927; c=relaxed/simple; bh=K+gBb6aC/dX8HpJfKUbrOWEv/HzbSGMPsvlYa0EPLG8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=krwAorbUF8emq2aWrMQhtgA8JDMMwBLUfq2mbE3EXicgWUfXB7lRnw6/nd/k7MDZc0C7vcxt+5cCQfWjoWqVIYnFObFZ2hGagngI60Ipg/J8Yucqd6d3cy+c62NjyK0mv8X0LlT1U+Umr0HACqOlIaW+8h6gQfT0tX0vM2rqoGI= 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=HErebf7s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ijSto615; arc=none smtp.client-ip=64.147.123.159 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="HErebf7s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ijSto615" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.west.internal (Postfix) with ESMTP id 0CBDB18000FA; Fri, 10 May 2024 04:48:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 10 May 2024 04:48:45 -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=1715330924; x=1715417324; bh=HXMXZr7fLZ voBMzl7VitVkDovqhk7hf+UBqIRyukYxA=; b=HErebf7sf5fSGM7TUxvaYhCklD 9u71Gmpce9yiWKeuvkSIah4Zkm0ZOi5Y9ypt6+mHIyb95Nul9sbVib1XZO23O0NS QKZgEOou64lf+Os7zV2Kl4tUgV7cj8WD1yLIEOKZkiuMn3OdTGwWBT6oimgO1TC2 C2Ex3PrzfIk54SKLRRZ1Fu6w9N4zoe9fM9QOxdDGy2Axj6ZZZFfw9Rb8inT0RRVz kzzMks1e3Gg7JlYYwZVXdTWAAAS3OzsnZIkf6P9cHnPautFIQWvyhvdZCsRwuX9D RdYyq/vUCo7p0T6d4iRL9X+YwkHE8YVNPLturAkvytfyADEDEbUdGP3B+8VA== 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=1715330924; x=1715417324; bh=HXMXZr7fLZvoBMzl7VitVkDovqhk 7hf+UBqIRyukYxA=; b=ijSto615Vv+VR5GEZiPiiIdTn436YKY5Pgbjyu9pdG69 uWIjEXAtJrOrJsWG7GFi/nKyr/x4KejHT9Ma+V1R31ZHMpc1G0BJSKXXJCjUoVg/ IASfpskhQWoxyuP26WK7uGAwm7PQAXZmThjPi0BXoIAMcuTGhvKqODswEDFN1N90 10dxvmu1lDX8MYYXedJEX5GxK/BAM21fZWHS4mpCpQMAHjgdzX7EmmUAozunr2hZ 5uGxFuXfDbokmza4MniX0YVv/djvML32Die+l68ilcaSjZk2v28fQ58HXarpkEfe Bp6XOhhLNXDkmMU+bbWmt/CsWwp2+HL4tq8O4lXxiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:42 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 2abf18e6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:30 +0000 (UTC) Date: Fri, 10 May 2024 10:48:40 +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 v4 08/10] refs: pseudorefs are no refs Message-ID: <19af8c754c5d88cfdf6c86d5a8136a97e6094185.1715330206.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 077ae5756a..f5e98e5b46 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; @@ -876,7 +907,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; /* @@ -1878,37 +1910,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 Fri May 10 08:48:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661061 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 2761016191E for ; Fri, 10 May 2024 08:48:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330932; cv=none; b=avIULPwKYTb13fVGLk7FIRKvxZYjG18Ypor4aNpPv98hiwvK9nsM680XfhYq5rFZTxqYMXqeFVmH3Itqxth2R87gK/oro5d+NfUwg3VHV06Eo+9hK8JK8NVHWgWthxYBcAfn/Q0gGxiIGVNnmt6imZRj6VhZRxFsOgneA8/qbh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330932; c=relaxed/simple; bh=NefqH34taI8e9F+w2IdYS9zTSknexbcWY5VDLrhnLT4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u1fPUzPzRTyD+sp3MN0na2XIvbchDcxvPMz7S9M837GK6O4ZRQyUZQ1DR1Zv/fZiJdku6CdTVaKh1nAOWie06u2SedhdET7i5OGR9RkpdZ5jtEvQPlwg0UoFAj2wkmg/OcKGMlVNUsLHJP3bBgSsLd+SbM2NHOF32Ln10NLJx98= 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=q2dlcDzz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Ld+pVVRh; arc=none smtp.client-ip=64.147.123.149 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="q2dlcDzz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Ld+pVVRh" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.west.internal (Postfix) with ESMTP id 077141C000FC; Fri, 10 May 2024 04:48:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 10 May 2024 04:48:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715330929; x=1715417329; bh=GUZwx+Mess 3P6tijL5FWYfAuO75K0nztYeYZzaHVcAc=; b=q2dlcDzzNzjULyHJ94QVW03Rhd UzZJBr7gpyosSbqziPROqsJbM23S6CMsjPuwswY7RKPxUgKSwzFxXDmNRwgs0poS XuwWhg5+dD/QOMu2gZymBdykiufBb9XAQBS33ikfm9tUbrlgkMhtymu5Gy3EoAF/ pquosgr4FBvDeL3wGPWkJB3spYuHz5195nvz+Fh1XKpaC0Seq8d+Slu4fykM6+uV 4gsivxL503NgmExJzLPIYqa0r9vGzVCgqed9u9O8e9OpuERDIsPrEcQCF9mtEucj /w9bsCpWMx+O6U168s2No7wum8cjGK8BwV2Abh/0or2fB0vmFu0Jb5N7yCRg== 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=1715330929; x=1715417329; bh=GUZwx+Mess3P6tijL5FWYfAuO75K 0nztYeYZzaHVcAc=; b=Ld+pVVRhYeazkabnNYXQUJJJtFTBFqCXWr1sl/yIRWB/ Iz+N7g8i06DqwpIJaqnwPzm/dr6QG7Seuez2WPo7FKSL5RV2r+xA8DHnq6IubE9u +sKiwwiTRTPO4bAlJ1vF0xgTW4Bj5k0qdb+W/pqvpfcwC3L9MhHVslEuxPFetrNN 1Jrqby2KwnlhPdRwFNy+He8kYsjpa0Snb5R9WBfkM/W2reuErNTHh4jSIMHADbzU Ysh/SH52/9q4mSmsOWyvhKXKhKlN5cG7DSkkmNTOZ4jM3i+idXndaZm1rCsZwzSj IlYbSWxi057yfMudwuC2aLedGfKGTQJgp8D7MvMY5w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:47 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b7eac8c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:35 +0000 (UTC) Date: Fri, 10 May 2024 10:48:45 +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 v4 09/10] ref-filter: properly distinuish pseudo and root refs Message-ID: <86f7f2d2d83774544e3f2fb1c2ec37cbd41e26be.1715330206.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 f5e98e5b46..c882ece6e7 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 f6f4d61e1b..815dc514c7 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(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 Fri May 10 08:48: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: 13661062 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 2FC888BE8 for ; Fri, 10 May 2024 08:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330938; cv=none; b=jZYfeWgnRWWiPWNlqQZkEQgmiMJHkbNoEsmbRSKUxvarIPdMW9oaitoH4hXnqhbtrkVWGQtNF/qna9sDKvD6YejovoRKkUaATPP0ahc5rud6MirJHY5aMzdGH7w5bc10AvgM5GjqDuT0fqRQeN2AfFhE1jVrRskUdofA7ny2kiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715330938; c=relaxed/simple; bh=O+h3lDmgTU2pdHkz0t/J+aJRbmfIHbMINiYGjfozrIY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OXI1NAJf7/za67uBDnq5GZH/GQE72kq06u2g6QKbvwrnIaswmek9bKVH8+xwfX8MBXtb2et9gkMXDkz6OCbV9EkUR7DN9HQ6p74AfqZ1jczhzm8XB7Dj8CpSzuqVqp3NywmbdfmHWV7t3H+L/+pp0KpHIn5410xIX8eBwcvdH+Q= 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=mMNaPhYa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cfuK2p19; arc=none smtp.client-ip=64.147.123.149 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="mMNaPhYa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cfuK2p19" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id E60641C000F3; Fri, 10 May 2024 04:48:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 10 May 2024 04:48: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=1715330935; x=1715417335; bh=SeomFHX+9n iIhonAM4APdY+geeUveyCLqfU682b2QRg=; b=mMNaPhYaESM1uIANzUmeo67US3 CiMwBQMXDk9dKbWIQs05WSLzwV5BhW72AWXQZsCi9pxZaW/Wm+deMMRZuQ5PeFX8 sRTEcAd7d1k6Q9bANfQL8cmP7OWhEOAVHXFjF+Emnlpv/ZhqhGGwFQSgbMIERdKW giPBdQkcHm+FP0HhP9YxiaZf6FciguqOK3eDRhpL04lXx0mzcoTx2S02p5tDd0vr j5O11nEFIjIcnC/z3RPuJbR6G5WkvxT+2oDT98GtsY+0atX4Ouijv6InQZW4G0PN OpycNd0t11nEUeQlQV6NNLbMU+DGe2rzQIf3D5xwl8CCEon74wkPZ9ZJjFgA== 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=1715330935; x=1715417335; bh=SeomFHX+9niIhonAM4APdY+geeUv eyCLqfU682b2QRg=; b=cfuK2p190sX85wC3oUasTNTb5KYqb5hf6C5ZQAmoNtYg x/hpR6lXcbgVHi1KMmKqItWrVC+CyTzkfc9+Pkg5oRgCbc/fZvlUSNiZoK1Ura7k 7k/G2FCv5JCEsJ1tCOxTHQVXZWu+fkR7JeP1kX0gmwucIRfo9WPyCWMcE4bXw2R/ +eLgAuJ5ptbNae/F5+o4gKTn81cB+rPW16wYIL4fAfyAn+JiMAcgNypmrq2UUVwe 1+dRZe/9Lw3s4QlZqkTbaJwnrzGYwJr1xBOJ7AUUx/KFBVyZYdIi0dJJreiPx02a zPH+2bOiyDAy0+Nb1cfyZKx2lt7IEhwmOJPJGI6IsA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 May 2024 04:48:53 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 78c28c2a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 May 2024 08:48:40 +0000 (UTC) Date: Fri, 10 May 2024 10:48: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 v4 10/10] refs: refuse to write pseudorefs Message-ID: <640d3b169fc6abaaf121b90f43f5f4c4145ec08d.1715330206.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 c882ece6e7..f2507c5a74 100644 --- a/refs.c +++ b/refs.c @@ -1285,6 +1285,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)"