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

[PATCH] setup.c: don't try to access '//HEAD' during repo discovery

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Nov 3, 2017, 01:06 UTC
Message-ID
<20171103010645.25499-1-szeder.dev@gmail.com>
In-Reply-To
<MWHPR21MB0159089DB91A30E5E5CFCB479E5C0@MWHPR21MB0159.namprd21.prod.outlook.com>

Commit ce9b8aab5 (setup_git_directory_1(): avoid changing global state, 2017-03-13) changed how the git directory is discovered, and as a side effect when the discovery reaches the root directory Git tries to access paths like '//HEAD' and '//objects'. This interacts badly with Cygwin, which interprets it as a UNC file share, and so demand-loads a bunch of extra DLLs and attempts to resolve/contact the server named HEAD. This obviously doesn't work too well, especially over a slow network link.

Special case the root directory in is_git_directory() to prevent accessing paths with leading double slashes.

Reported-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---

I'm not quite sure whether this is the right or complete fix. I can't test it on Cygwin, and I don't know whether Git for Windows is affected with it's drive prefixes in paths. Anyway, at least strace output on Linux looks good to me.

 setup.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/setup.c b/setup.c
index 03f51e056..0cfc5e676 100644
--- a/setup.c
+++ b/setup.c
@@ -311,6 +311,10 @@ int is_git_directory(const char *suspect)
 	int ret = 0;
 	size_t len;
 
+	/* To avoid accessing '//HEAD' & co when checking the root directory */
+	if (!strcmp(suspect, "/"))
+		suspect = "";
+
 	/* Check worktree-related signatures */
 	strbuf_addf(&path, "%s/HEAD", suspect);
 	if (validate_headref(path.buf))
-- 
2.15.0.67.gb67a46776
Previous: Jeff KingNext: Johannes Schindelin
Message 5 of 6 in “git tries to stat //HEAD when searching for a repo, leading to huge delays on Cygwin”
  1. Andrew BaumannNov 2, 2017
  2. Jeff KingNov 3, 2017
  3. Johannes SchindelinNov 3, 2017
  4. Jeff KingNov 3, 2017
  5. setup.c: don't try to access '//HEAD' during repo discoverySZEDER Gábor, Nov 3, 2017
  6. Johannes SchindelinNov 3, 2017

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.