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; }