]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: limit shared symref check only for local branches
authorOrgad Shaneh <orgads@gmail.com>
Mon, 16 May 2022 08:41:41 +0000 (08:41 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 May 2022 17:58:01 +0000 (10:58 -0700)
This check was introduced in 8ee5d73137f (Fix fetch/pull when run without
--update-head-ok, 2008-10-13) in order to protect against replacing the ref
of the active branch by mistake, for example by running git fetch origin
master:master.

It was later extended in 8bc1f39f411 (fetch: protect branches checked out
in all worktrees, 2021-12-01) to scan all worktrees.

This operation is very expensive (takes about 30s in my repository) when
there are many tags or branches, and it is executed on every fetch, even if
no local heads are updated at all.

Limit it to protect only refs/heads/* to improve fetch performance.

Signed-off-by: Orgad Shaneh <orgads@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c

index e3791f09ed51d0d96b945b747d3dd74ad2d63165..eeee5ac8f15ece4399380838a64e476ab7654d20 100644 (file)
@@ -1440,6 +1440,7 @@ static void check_not_current_branch(struct ref *ref_map,
        const struct worktree *wt;
        for (; ref_map; ref_map = ref_map->next)
                if (ref_map->peer_ref &&
+                   starts_with(ref_map->peer_ref->name, "refs/heads/") &&
                    (wt = find_shared_symref(worktrees, "HEAD",
                                             ref_map->peer_ref->name)) &&
                    !wt->is_bare)