Skip to content

Commit f7400da

Browse files
orgadsgitster
authored andcommitted
fetch: limit shared symref check only for local branches
This check was introduced in 8ee5d73 (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 8bc1f39 (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>
1 parent e54793a commit f7400da

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

builtin/fetch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ static void check_not_current_branch(struct ref *ref_map,
14401440
const struct worktree *wt;
14411441
for (; ref_map; ref_map = ref_map->next)
14421442
if (ref_map->peer_ref &&
1443+
starts_with(ref_map->peer_ref->name, "refs/heads/") &&
14431444
(wt = find_shared_symref(worktrees, "HEAD",
14441445
ref_map->peer_ref->name)) &&
14451446
!wt->is_bare)

0 commit comments

Comments
 (0)