Skip to content

Commit 638060d

Browse files
ferdinandybgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fbe8d30 commit 638060d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

builtin/fetch.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,13 +1617,13 @@ static void report_set_head(const char *remote, const char *head_name,
16171617
strbuf_release(&buf_prefix);
16181618
}
16191619

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)
16221621
{
16231622
int result = 0, create_only, is_bare, was_detached;
16241623
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
16251624
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;
16271627
char *head_name = NULL;
16281628
struct ref *ref, *matches;
16291629
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,
16611661
strbuf_addstr(&b_head, "HEAD");
16621662
strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
16631663
} 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);
16661666
}
16671667
/* make sure it's valid */
16681668
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,
16781678
if (verbosity >= 0 &&
16791679
follow_remote_head == FOLLOW_REMOTE_WARN &&
16801680
(!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);
16821682

16831683
cleanup:
16841684
free(head_name);
@@ -1924,8 +1924,7 @@ static int do_fetch(struct transport *transport,
19241924
"you need to specify exactly one branch with the --set-upstream option"));
19251925
}
19261926
}
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))
19291928
;
19301929
/*
19311930
* Way too many cases where this can go wrong

0 commit comments

Comments
 (0)