fetch: avoid unnecessary work when there is no current branch

As pointed out by CodeQL, `branch_get()` may return `NULL`, in which case `branch_has_merge_config()` would return early, but we can even avoid enumerating the refs prefixes in that case, saving even more CPU cycles. Technically, we should enclose these two statements in an `if (branch) {...}` block, but the indentation is already quite deep, therefore I refrained from doing that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 15, 2025 at 13:11 UTC 6c91162449cb0a2fe3c42a1caa232444afed9c7c
1 file changed +1 -1
builtin/fetch.c
+1 -1
@@ -1728,7 +1728,7 @@ static int do_fetch(struct transport *transport,
1728 if (transport->remote->follow_remote_head != FOLLOW_REMOTE_NEVER)
1729 do_set_head = 1;
1730 }
1731 - if (branch_has_merge_config(branch) &&
1731 + if (branch && branch_has_merge_config(branch) &&
1732 !strcmp(branch->remote_name, transport->remote->name)) {
1733 int i;
1734 for (i = 0; i < branch->merge_nr; i++) {