git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 25, 2026, 02:16 UTC
Message-ID
<xmqqecdezfr1.fsf@gitster.g>
In-Reply-To
<20261023185007.21642-1-colinlewishinton@gmail.com>
Colin Hinton <colinlewishinton@gmail.com> writes:
One more thing.
Show 27 quoted lines
> @@ -1978,16 +1990,19 @@ static int do_fetch(struct transport *transport,
>  		if (transport->remote->fetch.nr) {
>  			refspec_ref_prefixes(&transport->remote->fetch,
>  					     &transport_ls_refs_options.ref_prefixes);
> -			/*
> -			 * See remote.c's handling of remote.<name>.followRemoteHEAD
> -			 * for the analogous, still-unresolved case.
> -			 */
> -			if (transport->remote->follow_remote_head)
> -				follow_remote_head = transport->remote->follow_remote_head;
> -			else if (config->follow_remote_head_seen)
> -				follow_remote_head = get_follow_remote_head(config->follow_remote_head_raw);
> -			else
> +			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;
> +			}
>  		}

This part of the code becomes overly deeply indented, and more importantly, the outer conditional around here has been reworked by another topic and the code that learns follow_remote_head will have to be reused elsewhere, which would lead to a nasty merge conflict.

I'd like to see this part refactored into a separate helper function, by squashing something like this on top of this patch.

Thanks.
 builtin/fetch.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)
diff --git c/builtin/fetch.c w/builtin/fetch.c
index bb59e70865..77e3276cc4 100644
--- c/builtin/fetch.c
+++ w/builtin/fetch.c
@@ -1946,6 +1946,28 @@ static void collect_updated_tips(struct oidset *tips, struct ref *ref_map)
 	}
 }
 
+static int lazy_follow_remote_head(const struct transport *transport,
+				   const struct fetch_config *config,
+				   const char **no_warn_branch)
+{
+	int ret = BUILTIN_FOLLOW_REMOTE_HEAD_DFLT;
+
+	if (transport->remote->follow_remote_head_seen) {
+		char *key = xstrfmt("remote.%s.followRemoteHEAD",
+				    transport->remote->name);
+		ret = get_follow_remote_head(
+			transport->remote->follow_remote_head_raw,
+			key, no_warn_branch);
+		free(key);
+	} else if (config->follow_remote_head_seen) {
+		ret = get_follow_remote_head(
+			config->follow_remote_head_raw,
+			"fetch.followRemoteHEAD", NULL);
+	}
+
+	return ret;
+}
+
 static int do_fetch(struct transport *transport,
 		    struct refspec *rs,
 		    const struct fetch_config *config,
@@ -1990,19 +2012,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 =
+				lazy_follow_remote_head(transport, config,
+							&no_warn_branch);
 		}
 		if (branch && branch_has_merge_config(branch) &&
 		    !strcmp(branch->remote_name, transport->remote->name)) {
Previous: Junio C HamanoNext: Colin Hinton
Message 10 of 19 in “remote.c: defer remote.<name>.followRemoteHEAD validation”
  1. remote.c: defer remote.<name>.followRemoteHEAD validationColin Hinton, Oct 18, 2026
  2. Junio C HamanoOct 19, 2026
  3. Matt HunterOct 19, 2026
  4. Colin HintonOct 21, 2026
  5. Matt HunterOct 22, 2026
  6. remote.c: defer remote.<name>.followRemoteHEAD validationColin Hinton, Oct 23, 2026
  7. Junio C HamanoOct 23, 2026
  8. Matt HunterOct 24, 2026
  9. Junio C HamanoOct 24, 2026
  10. Junio C HamanoOct 25, 2026
  11. Colin HintonOct 28, 2026
  12. Junio C HamanoOct 28, 2026
  13. Matt HunterOct 30, 2026
  14. Junio C HamanoOct 30, 2026
  15. Matt HunterNov 1, 2026
  16. Junio C HamanoNov 6, 2026
  17. Matt HunterNov 6, 2026
  18. Junio C HamanoNov 6, 2026
  19. Colin HintonNov 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.