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

[PATCH v3 4/5] worktree repair: reduce .git file reads

From
Yoichi NAKAYAMA via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 17, 2026, 12:55 UTC
Message-ID
<e35285a4ea5a5f7b11cd112df841948e9a0a3ab9.1792241702.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2225.v3.git.1792241702.gitgitgadget@gmail.com>
From: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Pass the loaded contents of the .git file to infer_backlink().
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
---
 worktree.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/worktree.c b/worktree.c
index 3627dbc044..879941a977 100644
--- a/worktree.c
+++ b/worktree.c
@@ -806,27 +806,20 @@ static int is_main_worktree_path(struct repository *repo, const char *path)
  * Returns -1 on failure and strbuf.len on success.
  */
 static ssize_t infer_backlink(struct repository *repo,
-			      const char *gitfile,
+			      const char *dotgit_contents,
 			      struct strbuf *inferred)
 {
-	struct strbuf contents = STRBUF_INIT;
 	const char *id;
-	int err;
 
-	err = read_gitfile_raw(&contents, gitfile);
-	if (err)
-		goto error;
-	id = get_worktree_id(contents.buf);
+	id = get_worktree_id(dotgit_contents);
 	if (!*id)
 		goto error;
 	repo_common_path_replace(repo, inferred, "worktrees/%s", id);
 	if (!is_directory(inferred->buf))
 		goto error;
 
-	strbuf_release(&contents);
 	return inferred->len;
 error:
-	strbuf_release(&contents);
 	strbuf_reset(inferred); /* clear invalid path */
 	return -1;
 }
@@ -877,7 +870,7 @@ void repair_worktree_at_path(struct repository *repo,
 	}
 
 	dotgit_contents = contents.buf;
-	infer_backlink(repo, dotgit.buf, &inferred_backlink);
+	infer_backlink(repo, dotgit_contents, &inferred_backlink);
 	strbuf_realpath_forgiving(&inferred_backlink, inferred_backlink.buf, 0);
 
 	if (is_absolute_path(dotgit_contents)) {
-- 
gitgitgadget
Previous: Yoichi NAKAYAMA via GitGitGadgetNext: Yoichi NAKAYAMA via GitGitGadget
Message 22 of 23 in “worktree repair: avoid breaking unrelated .git file and gitdir”
  1. 0/2 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  2. 1/2 worktree repair: refactor and reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  3. Junio C HamanoOct 8, 2026
  4. Yoichi NAKAYAMAOct 11, 2026
  5. Yoichi NAKAYAMAOct 12, 2026
  6. 2/2 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  7. Yoichi NAKAYAMAOct 8, 2026
  8. 0/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  9. 1/5 worktree repair: align .git file handling with repair_gitfile()Yoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  10. 2/5 worktree repair: centralize inferred backlink selectionYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  11. 3/5 worktree repair: use read_gitfile_raw() in infer_backlink()Yoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  12. 4/5 worktree repair: reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  13. 5/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  14. Junio C HamanoOct 15, 2026
  15. Yoichi NAKAYAMAOct 17, 2026
  16. Junio C HamanoOct 14, 2026
  17. Yoichi NAKAYAMAOct 15, 2026
  18. 0/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  19. 1/5 worktree repair: align .git file handling with repair_gitfile()Yoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  20. 2/5 worktree repair: centralize inferred backlink selectionYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  21. 3/5 worktree repair: use read_gitfile_raw() in infer_backlink()Yoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  22. 4/5 worktree repair: reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  23. 5/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026

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.