git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] fetch: limit shared symref check only for local branches

From
Orgad Shaneh via GitGitGadget <gitgitgadget@gmail.com>
Date
May 16, 2022, 08:37 UTC
Message-ID
<pull.1266.git.git.1652690275625.gitgitgadget@gmail.com>
From: Orgad Shaneh <orgads@gmail.com>

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>
---
    fetch: limit shared symref check only for local branches
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1266%2Forgads%2Ffetch-perf-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1266/orgads/fetch-perf-v1
Pull-Request: https://github.com/git/git/pull/1266
 builtin/fetch.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index e3791f09ed5..4f16fc357b0 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -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)

base-commit: 277cf0bc36094f6dc4297d8c9cef79df045b735d
-- 
gitgitgadget
Next: Orgad Shaneh via GitGitGadget
Message 1 of 8 in “fetch: limit shared symref check only for local branches”
  1. fetch: limit shared symref check only for local branchesOrgad Shaneh via GitGitGadget, May 16, 2022
  2. fetch: limit shared symref check only for local branchesOrgad Shaneh via GitGitGadget, May 16, 2022
  3. Junio C HamanoMay 16, 2022
  4. Junio C HamanoMay 16, 2022
  5. Orgad ShanehMay 17, 2022
  6. Junio C HamanoMay 17, 2022
  7. Orgad ShanehMay 17, 2022
  8. Junio C HamanoMay 18, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.