[PATCH 06/11] fetch: avoid unnecessary work when there is no current branch
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 15, 2025, 13:11 UTC
- Message-ID
- <dff0a3ec886cdccf199bdc3881094ec0ab8b3bca.1747314709.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1891.git.1747314709.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
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> --- builtin/fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c index c1a1434c7096..40a0e8d24434 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1728,7 +1728,7 @@ static int do_fetch(struct transport *transport, if (transport->remote->follow_remote_head != FOLLOW_REMOTE_NEVER) do_set_head = 1; } - if (branch_has_merge_config(branch) && + if (branch && branch_has_merge_config(branch) && !strcmp(branch->remote_name, transport->remote->name)) { int i; for (i = 0; i < branch->merge_nr; i++) {
-- gitgitgadget