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>
maint
Bence Ferdinandy 2025-01-26 23:02:10 +01:00 committed by Junio C Hamano
parent fbe8d3079d
commit 638060dcb9
1 changed files with 7 additions and 8 deletions

View File

@ -1617,13 +1617,13 @@ static void report_set_head(const char *remote, const char *head_name,
strbuf_release(&buf_prefix); strbuf_release(&buf_prefix);
} }


static int set_head(const struct ref *remote_refs, int follow_remote_head, static int set_head(const struct ref *remote_refs, struct remote *remote)
const char *no_warn_branch)
{ {
int result = 0, create_only, is_bare, was_detached; int result = 0, create_only, is_bare, was_detached;
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT, struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
b_local_head = STRBUF_INIT; b_local_head = STRBUF_INIT;
const char *remote = gtransport->remote->name; int follow_remote_head = remote->follow_remote_head;
const char *no_warn_branch = remote->no_warn_branch;
char *head_name = NULL; char *head_name = NULL;
struct ref *ref, *matches; struct ref *ref, *matches;
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; 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,
strbuf_addstr(&b_head, "HEAD"); strbuf_addstr(&b_head, "HEAD");
strbuf_addf(&b_remote_head, "refs/heads/%s", head_name); strbuf_addf(&b_remote_head, "refs/heads/%s", head_name);
} else { } else {
strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote); strbuf_addf(&b_head, "refs/remotes/%s/HEAD", remote->name);
strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote, head_name); strbuf_addf(&b_remote_head, "refs/remotes/%s/%s", remote->name, head_name);
} }
/* make sure it's valid */ /* make sure it's valid */
if (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) { 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,
if (verbosity >= 0 && if (verbosity >= 0 &&
follow_remote_head == FOLLOW_REMOTE_WARN && follow_remote_head == FOLLOW_REMOTE_WARN &&
(!no_warn_branch || strcmp(no_warn_branch, head_name))) (!no_warn_branch || strcmp(no_warn_branch, head_name)))
report_set_head(remote, head_name, &b_local_head, was_detached); report_set_head(remote->name, head_name, &b_local_head, was_detached);


cleanup: cleanup:
free(head_name); free(head_name);
@ -1924,8 +1924,7 @@ static int do_fetch(struct transport *transport,
"you need to specify exactly one branch with the --set-upstream option")); "you need to specify exactly one branch with the --set-upstream option"));
} }
} }
if (set_head(remote_refs, transport->remote->follow_remote_head, if (set_head(remote_refs, transport->remote))
transport->remote->no_warn_branch))
; ;
/* /*
* Way too many cases where this can go wrong * Way too many cases where this can go wrong