🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #2038

Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD validation

#2038
From: "Matt Hunter"
Date: Sun, 01 Nov 2026 00:00
120 lines
12459 bytes
On Fri Oct 30, 2026 at 11:12 AM EDT, Junio C Hamano wrote:
> "Matt Hunter" <m@lfurio.us> writes:
>> ...
>> I wonder if it makes sense to incorporate such a new helper function
>> into the existing 'get_follow_remote_head()', since it would be the only
>> place using it.
>
> I am not sure what being the only place has to do with avoiding to
> split a helper function out to clarify the main logic flow, though.
> And simultaneously, another topic wants to have this piece of logic
> twice.

I should explain myself better.  I don't mean Colin should avoid
splitting out logic from the main flow in do_fetch.  But the end result
can be reached without introducing a new function.  I find needing to
hold fewer functions in my head makes the code easier to reason about,
though that is a subjective point.

The idea in my head is below and is
Signed-off-by: Matt Hunter <m@lfurio.us>
Feel free to run with this or not.

diff --git a/builtin/fetch.c b/builtin/fetch.c
index bb59e70865ff..844ff5105f91 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -196,23 +196,44 @@ static int git_fetch_config(const char *k, const char *v,
 	return git_default_config(k, v, ctx, cb);
 }
 
-static enum follow_remote_head_settings get_follow_remote_head(const char *setting,
-    const char *key, const char **no_warn_branch)
+static enum follow_remote_head_settings get_follow_remote_head(
+		const struct transport *transport, const struct fetch_config *config,
+		const char **no_warn_branch)
 {
-	if (!setting)
-		die(_("missing value for '%s'"), key);
-	else if (!strcmp(setting, "never"))
-		return FOLLOW_REMOTE_NEVER;
-	else if (!strcmp(setting, "create"))
-		return FOLLOW_REMOTE_CREATE;
-	else if (!strcmp(setting, "warn"))
-		return FOLLOW_REMOTE_WARN;
-	else if (no_warn_branch && skip_prefix(setting, "warn-if-not-", no_warn_branch))
-		return FOLLOW_REMOTE_WARN;
-	else if (!strcmp(setting, "always"))
-		return FOLLOW_REMOTE_ALWAYS;
-	warning(_("unrecognized %s value '%s' ignored"), key, setting);
-	return BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;
+	int ret = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;
+	char *key = NULL;
+	const char *setting = NULL;
+
+	if (transport->remote->follow_remote_head_seen) {
+		key = xstrfmt("remote.%s.followRemoteHEAD", transport->remote->name);
+		setting = transport->remote->follow_remote_head_raw;
+	} else if (config->follow_remote_head_seen) {
+		key = xstrdup("fetch.followRemoteHEAD");
+		setting = config->follow_remote_head_raw;
+		no_warn_branch = NULL;
+	}
+
+	if (key) {
+		if (!setting)
+			die(_("missing value for '%s'"), key);
+		else if (!strcmp(setting, "never"))
+			ret = FOLLOW_REMOTE_NEVER;
+		else if (!strcmp(setting, "create"))
+			ret = FOLLOW_REMOTE_CREATE;
+		else if (!strcmp(setting, "warn"))
+			ret = FOLLOW_REMOTE_WARN;
+		else if (no_warn_branch &&
+				skip_prefix(setting, "warn-if-not-", no_warn_branch))
+			ret = FOLLOW_REMOTE_WARN;
+		else if (!strcmp(setting, "always"))
+			ret = FOLLOW_REMOTE_ALWAYS;
+		else
+			warning(_("unrecognized %s value '%s' ignored"), key, setting);
+
+		free(key);
+	}
+
+	return ret;
 }
 
 static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
@@ -1990,19 +2011,9 @@ static int do_fetch(struct transport *transport,
 		if (transport->remote->fetch.nr) {
 			refspec_ref_prefixes(&transport->remote->fetch,
 					     &transport_ls_refs_options.ref_prefixes);
-			if (transport->remote->follow_remote_head_seen) {
-				char *key = xstrfmt("remote.%s.followRemoteHEAD", transport->remote->name);
-				follow_remote_head = get_follow_remote_head(
-					transport->remote->follow_remote_head_raw,
-					key, &no_warn_branch);
-				free(key);
-			} else if (config->follow_remote_head_seen) {
-				follow_remote_head = get_follow_remote_head(
-					config->follow_remote_head_raw,
-					"fetch.followRemoteHEAD", NULL);
-			} else {
-				follow_remote_head = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;
-			}
+			follow_remote_head =
+				get_follow_remote_head(transport, config,
+						&no_warn_branch);
 		}
 		if (branch && branch_has_merge_config(branch) &&
 		    !strcmp(branch->remote_name, transport->remote->name)) {


Admittedly, I haven't been following Harald's hn/fetch-refmap topic
closely, but am more familiar with the affected areas now.
Technical Details
Message-ID: <DMJFKJCI5DLL.12R7AMFO4DK2Y@lfurio.us>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74037-linux-kernel-git=dewy.ru
References: <20261018235508.848-1-colinlewishinton@gmail.com> <20261023185007.21642-1-colinlewishinton@gmail.com> <xmqqecdezfr1.fsf@gitster.g> <CAHeTm9NOqLA=BfTU9ABDFt8+jOzaRDPRrMNP8thzAQN2NVZAew@mail.gmail.com> <xmqqmrrxdhox.fsf@gitster.g> <DMHZCS9LOW3N.ZJ3947HUCXZ8@lfurio.us> <xmqq33tnz0hb.fsf@gitster.g>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74037-linux-kernel-git=dewy.ru
From: m@lfurio.us ("Matt Hunter")
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2] remote.c: defer remote.<name>.followRemoteHEAD
 validation
Date: Sat, 31 Oct 2026 20:00:00 -0400
Organization: Usenet Network
Message-ID: <DMJFKJCI5DLL.12R7AMFO4DK2Y@lfurio.us>
References: <20261018235508.848-1-colinlewishinton@gmail.com>
 <20261023185007.21642-1-colinlewishinton@gmail.com>
 <xmqqecdezfr1.fsf@gitster.g>
 <CAHeTm9NOqLA=BfTU9ABDFt8+jOzaRDPRrMNP8thzAQN2NVZAew@mail.gmail.com>
 <xmqqmrrxdhox.fsf@gitster.g> <DMHZCS9LOW3N.ZJ3947HUCXZ8@lfurio.us>
 <xmqq33tnz0hb.fsf@gitster.g>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2582377"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:CLnSxMvFFXeTjNGVlWf1J+ATo0s= sha256:4BbForwxX1eR86uw3CXx5Y02I5/9wvGOFBUE3eQTqaA=
	sha1:ed5nQ7x3IItUVQXufyaoJmJXtgw= sha256:TbIK5NYIyQB77f3H/bhZq58rbObgOPPig06TnwgIw5U=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id BEB9F1122C3; Sun,  1 Nov 2026 03:00:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=lfurio.us
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id zzslxrb2Sh63;
	Sun,  1 Nov 2026 03:00:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-74037-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=lfurio.us
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 0095C11228B; Sun,  1 Nov 2026 03:00:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id E753060162F; Sun,  1 Nov 2026 00:00:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793491222;
	b=sTcWihm1DoxTQSlPPEzFh2hX3ZG7h4HNj2weItfuT3hhqpFK4rE99yhafvokGrh378Pq
	 oMRvnn/mQeanw9xORr6ygcy4FfF6Pr/TLQkF16nFHlBF04lk/TVjscdX+DcDU3gjM+kKG
	 nCFZiPjq47V6XGDgsfLbmeGkkt7wTdklNGCgHuTbJCDwTh3NYFqUjbgPAkbuaxrqCS+QZ
	 ya84TmQ2zc8Qai91c6rY5liLoUOMZ5KZAbSE9vDl034c1/2cgk9Xe40/QIRAPhgv8LVjy
	 29AhKVmDW3YLTrsNTQY0QRV9ycS3DD0azO+B1k0gR8UatN+mtIBkDmVotjpJf1G4slQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793491222;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:Mime-Version:
	 Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
	 From:X-Mailer:References:In-Reply-To;
	bh=tI8HDrU9llZWAQ7I4Bv1pGlzw+vGSkFTUK4QGXfRG2k=;
	b=FDGHQOY6vSSH8wh9cYTNPUf9lqAsoXkIRjSkTVEotU78AmyoG4+YoAfI8XvBSNDVeSWW
	 cNEBQcGTGGSHE4ynMGCmk2Eopd0CjqcTMScufDBL2SPFoZQdzItbKmLBTiIMFlYo+w+xC
	 1iNOkD+zsu6icXUErP60hepbuAYsikFc14nzYHic4iT2j7KVVJUOgswHa4C5ILjgu+vcy
	 16kXqVIi4Bp27ms9aWktL9IDEZHUCi1PEJFlL4R94JKw9sRudarmmXQ2xhfOSkQfpD02L
	 zsVTQILHO2u728/GMrji+xAmlbMeLyReNDKB08P21zdbFbIRQYuxXWV87Qxu6k1J5Vw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=i99kBhJ6;
	dmarc=pass header.from=lfurio.us;
	spf=pass smtp.mailfrom=lfurio.us;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 878D7606A325;
	Sun,  1 Nov 2026 00:00:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=i99kBhJ6
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=157.230.60.252
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793491221;
	b=Mrr/tDIpi4OpnNFAVlBVgIg/4PSgEpTjJZoi+3/6eSU/6B0+LC33t9gmUH5gcaCESFea
	 NKNfr3mr6SdtqQymKQ9TyHp9SkZrHVxPmGMamfoaK6agzUM28EiHFmAIuFzGaVuNIRnhr
	 re5Sp5VgLOW7ZZYqWJ92BmB9CbtmofWYacayfa+hP7Wv0Ora+alnOEO0/gB1uMeWoX8fG
	 hxcHQS///s221iFk4v5XTHEKO0v56gZzDVLndPCWypEjRTT+D5mRFx+uNF4n+BF7IxW4p
	 o/0NL4Zy979KobEb5h1g5GxpkCan5Er59y4k7uCP+eau7mpK+E32CYXi2ferH09uJTQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793491221;
	h=DMARC-Filter:DKIM-Signature:Received:Mime-Version:
	 Content-Transfer-Encoding:Content-Type:Date:Message-Id:Subject:Cc:To:
	 From:X-Mailer:References:In-Reply-To;
	bh=tI8HDrU9llZWAQ7I4Bv1pGlzw+vGSkFTUK4QGXfRG2k=;
	b=NXXEw6JY8Qeb4qiAzGRwGxFC36JZnu02qzYhTEqVdcl1yvQ1TAQojf3pPR4+yoM0hcpq
	 k1pWHGQ0xNQLwVWL1tx0/OfMA7Cz3zPudoIZsuVizPps2swaqnsf85zHbTJhGoEoX5kke
	 xfXeE6H/7WVN8BlhmMkcq05aMXLlzDoKFgsyYJSE0f9AMZHkcxtw1t1WLK66+/z6pDwyB
	 IyWrCbhZch64EN/pz9zpJR5jaInePq55xh1N2v+ff88O8tVJFCpUJCttw+SYrm/SKJoDG
	 Yj6TlopM5iz/WcOlrcLN/kVlhFbvH2hbkHAY6AIk7rZI/tW54TmH5BDL2LKL4Q0Y6mA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=lfurio.us;
	spf=pass smtp.mailfrom=lfurio.us;
	dkim=pass header.d=lfurio.us header.i=@lfurio.us header.a=rsa-sha256 header.s=default header.b=i99kBhJ6;
	arc=none smtp.remote-ip=157.230.60.252
X-Received: from mail.normalmode.org (h01.normalmode.org [157.230.60.252])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D93E7606A320
	for <git@vger.kernel.org>; Sun,  1 Nov 2026 00:00:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D93E7606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lfurio.us
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lfurio.us
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lfurio.us; s=default;
	t=1793491213; bh=TRkc7yRePeZaTRZo7TOZl63JR7qEPkM4w1K1RKy2Zmw=;
	h=Date:Subject:Cc:To:From:References:In-Reply-To:From;
	b=i99kBhJ6pGL4J7FNgCzGqN2bZndszKPm1+pLfBR3Tp342OTbfeac+t/0hBejfYupd
	 f8R/yrMzexB0WuTQ5wm7xZ/wPxlnWcIuBWJ0iefPruYqKshcz0apGAgEa1myDTWBWy
	 /tCUVbLYaKYw24EhSZW8dQA5DoKiuX4+YzC2snCE=
X-Received: by mail.normalmode.org (Postfix) with ESMTPSA id B3C3D61512;
	Sun,  1 Nov 2026 00:00:13 +0000 (UTC)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-Cc: "Colin Hinton" <colinlewishinton@gmail.com>, <git@vger.kernel.org>
X-Mailer: aerc 0.21.0-0-g5549850facc2
X-In-Reply-To: <xmqq33tnz0hb.fsf@gitster.g>