fetch set_head: refactor to use remote directly

As a preparatory step to use even more properties from the remote struct, refactor set_head to take the entire struct as a parameter, instead of the necessary bits. This also allows consolidating the use of gtransport->remote in set_head, making the access of the remote's properties consistent in the function. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bence Ferdinandy committed Jan 26, 2025 at 23:02 UTC 638060dcb95ed7ef3b2f6e6038ac12744d8ba238
1 file changed +7 -8
builtin/fetch.c
+7 -8
@@ -1617,13 +1617,13 @@ static void report_set_head(const char *remote, const char *head_name,
1617 strbuf_release(&buf_prefix);
1618 }
1619
1620 -static int set_head(const struct ref *remote_refs, int follow_remote_head,
1621 - const char *no_warn_branch)
1620 +static int set_head(const struct ref *remote_refs, struct remote *remote)
1621 {
1622 int result = 0, create_only, is_bare, was_detached;
1623 struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
1624 b_local_head = STRBUF_INIT;
1626 - const char *remote = gtransport->remote->name;
1625 + int follow_remote_head = remote->follow_remote_head;
1626 + const char *no_warn_branch = remote->no_warn_branch;
1627 char *head_name = NULL;
1628 struct ref *ref, *matches;
1629 struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
@@ -1661,8 +1661,8 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
1661 strbuf_addstr(&b_head, "HEAD");
1662 strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
1663 } else {
1664 - strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote);
1665 - strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name);
1664 + strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote->name);
1665 + strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote->name, head_name);
1666 }
1667 /* make sure it's valid */
1668 if (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {
@@ -1678,7 +1678,7 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,
1678 if (verbosity >= 0 &&
1679 follow_remote_head == FOLLOW_REMOTE_WARN &&
1680 (!no_warn_branch || strcmp(no_warn_branch, head_name)))
1681 - report_set_head(remote, head_name, &b_local_head, was_detached);
1681 + report_set_head(remote->name, head_name, &b_local_head, was_detached);
1682
1683 cleanup:
1684 free(head_name);
@@ -1924,8 +1924,7 @@ static int do_fetch(struct transport *transport,
1924 "you need to specify exactly one branch with the --set-upstream option"));
1925 }
1926 }
1927 - if (set_head(remote_refs, transport->remote->follow_remote_head,
1928 - transport->remote->no_warn_branch))
1927 + if (set_head(remote_refs, transport->remote))
1928 ;
1929 /*
1930 * Way too many cases where this can go wrong