From 054d208b66675daa8a1f0aaf953e29b16f69e8b4 Mon Sep 17 00:00:00 2001 From: Maik Riechert Date: Sat, 28 Nov 2026 21:27:25 +0000 Subject: [PATCH] worktree add: skip HEAD reads for destination checks add_worktree() calls get_worktrees() to check whether the destination matches a registered worktree. This also resolves HEAD for the enumerated worktrees, although check_candidate_path() only needs their paths, IDs and lock state. Use get_worktrees_without_reading_head() for the destination check to avoid these unnecessary lookups. Measured with 'git worktree add --detach --no-checkout' on a repository with 200 existing linked worktrees (median of seven runs per version, warm caches): before after files 11.13 ms 6.77 ms reftable 18.86 ms 7.60 ms Signed-off-by: Maik Riechert --- builtin/worktree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index 77ecd0f71f4247..82a93b0adfa650 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -473,7 +473,7 @@ static int add_worktree(const char *path, const char *refname, struct ref_store *wt_refs; struct repo_config_values *cfg = repo_config_values(the_repository); - worktrees = get_worktrees(the_repository); + worktrees = get_worktrees_without_reading_head(the_repository); check_candidate_path(path, opts->force, worktrees, "add"); free_worktrees(worktrees); worktrees = NULL;