Skip to content

Commit 6c91162

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6552684 commit 6c91162

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ static int do_fetch(struct transport *transport,
17281728
if (transport->remote->follow_remote_head != FOLLOW_REMOTE_NEVER)
17291729
do_set_head = 1;
17301730
}
1731-
if (branch_has_merge_config(branch) &&
1731+
if (branch && branch_has_merge_config(branch) &&
17321732
!strcmp(branch->remote_name, transport->remote->name)) {
17331733
int i;
17341734
for (i = 0; i < branch->merge_nr; i++) {

0 commit comments

Comments
 (0)