From patchwork Mon Jun 3 09:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13683475 Received: from wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (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 355E57E77B for ; Mon, 3 Jun 2024 09:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407570; cv=none; b=X1lNj0FYWnwglHlUXZU6Jlq+6O0Uy30xzlAwdNX+lZHjq+MTc+VofQjdQ4lL+5c91ygsyv74+eoKU8Ffj0LCNUhPVGBoAXWml7HTgxywWARp+g+u0cz8ClPelpvp0IUPmEK7BGnotNbfjbMEbX4oboIVDbHTRpv5+dYcRD0rGsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407570; c=relaxed/simple; bh=R4E+xpBTYYk125oTk9sm/fpalXvkfaKu3NHWfvUxfZI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L4RzVZp8Mt54Su/UaC42ZN4H0SJEw90KXnVPz8Bxq5LNaLCCbbe0pyftHHJ06ytkhVVVFSLW1n8FiGZzC9OLKUFKCcnkv6irAl0fOyDJFP2sjxpo4VNDx8a9KizbyxUloLLI+xSbet44aXlAgPxHL1SRs2OnEmSD7gYHkC+jntc= 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=OmukjxOF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QYZPVDDd; arc=none smtp.client-ip=64.147.123.158 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="OmukjxOF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QYZPVDDd" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 4AAB418000F6; Mon, 3 Jun 2024 05:39:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 03 Jun 2024 05:39:28 -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=fm1; t=1717407567; x=1717493967; bh=VNRVMQLZlX IR2clCiWnjTFvM6zr6DKOp1lTLOYYTvx8=; b=OmukjxOFxqCFOQRE7KfBZmS/QR 1xgdS2PhzZ3U/noOypA6Vc3cWz9CpjI3FqoScRxC3Ajn1fRHKL/RqoIXSCaTeZpW Q4675amnq+h+bNknNwKFgfUV1ATNx4OE3bNg35IFJ0DUF4j5pOy/DqS+OI0yFqRP z7e/sVFwcRdczj2n2a+V76HerXtxe9TOu8X0LVTcNmGfrg3L1cFiJ5ciUfqik4yC b61452WOGmgXWxlpkj23QG4XZBabZocDZTHipRmKFUxoOOa3oA2nA+j1HHcFFFi7 Svi5NqhhjGV9tM4nDzgSat0rDwvGztRhu1998OZr/RGod7m2TH0ChPdSZAnw== 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= fm1; t=1717407567; x=1717493967; bh=VNRVMQLZlXIR2clCiWnjTFvM6zr6 DKOp1lTLOYYTvx8=; b=QYZPVDDdWyf/RWvn6EVi2WRv9CETCO6uGXvHvIEhNKFs OohwyWGqwPDkeE4ibN6mSFP7S2ksymIKQzc7WcHBFX90ZNGrhW5VCTaYs0PQiUXF rgUG8OnIHLvL2pQf31qYHDiPZRbRUb/PDUqHkfHyJcbyQ+H7rxrOt7Sv+Z46k6L+ wP8JWxamotabcNS108yzU62QZejEou2ARHGSGEk3KtLHstLn3C6P3TpWbb+fX2vU ZNLx67F8+P/dYMTdCGG+FxBW1tPBfmc6T4g4CF9MgXhRV13pyW+vKUkeIYsKnXSu AuVK/zRgZkYBVvkFDpvkHdvzOwdoPoMZFEEOSv//gQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jun 2024 05:39:26 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id da4773a7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 3 Jun 2024 09:39:02 +0000 (UTC) Date: Mon, 3 Jun 2024 11:39:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v3 06/27] builtin/remote: cast away constness in `get_head_names()` Message-ID: <6a3c8d351e9defcc3b700761e96c8f29f2366df0.1717402403.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: In `get_head_names()`, we assign the "refs/heads/*" string constant to `struct refspec_item::{src,dst}`, which are both non-constant pointers. Ideally, we'd refactor the code such that both of these fields were constant. But `struct refspec_item` is used for two different usecases with conflicting requirements: - To query for a source or destination based on the given refspec. The caller either sets `src` or `dst` as the branch that we want to search for, and the respective other field gets populated. The fields should be constant when being used as a query parameter, which is owned by the caller, and non-constant when being used as an out parameter, which is owned by the refspec item. This is is contradictory in itself already. - To store refspec items with their respective source and destination branches, in which case both fields should be owned by the struct. Ideally, we'd split up this interface to clearly separate between querying and storing, which would enable us to clarify lifetimes of the strings. This would be a much bigger undertaking though. Instead, accept the status quo for now and cast away the constness of the source and destination patterns. We know that those are not being written to or freed, so while this is ugly it certainly is fine for now. Signed-off-by: Patrick Steinhardt --- builtin/remote.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index d52b1c0e10..b44f580b8c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -493,12 +493,13 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat { struct ref *ref, *matches; struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; - struct refspec_item refspec; + struct refspec_item refspec = { + .force = 0, + .pattern = 1, + .src = (char *) "refs/heads/*", + .dst = (char *) "refs/heads/*", + }; - memset(&refspec, 0, sizeof(refspec)); - refspec.force = 0; - refspec.pattern = 1; - refspec.src = refspec.dst = "refs/heads/*"; get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), fetch_map, 1); @@ -507,7 +508,6 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat free_refs(fetch_map); free_refs(matches); - return 0; }