Web lists-archives.com

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

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@xxxxxxxxxxxxx>
Signed-off-by: SZEDER Gábor <szeder.dev@xxxxxxxxx>

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))