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

[PATCH] fix pushing to //server/share/dir paths on Windows

From
Johannes Sixt <j6t@kdbg.org>
Date
Dec 13, 2016, 21:32 UTC
Message-ID
<2ff2613c-47da-a780-5d38-93e16cb16328@kdbg.org>

normalize_path_copy() is not prepared to keep the double-slash of a //server/share/dir kind of path, but treats it like a regular POSIX style path and transforms it to /server/share/dir.

The bug manifests when 'git push //server/share/dir master' is run, because tmp_objdir_add_as_alternate() uses the path in normalized form when it registers the quarantine object database via link_alt_odb_entries(). Needless to say that the directory cannot be accessed using the wrongly normalized path.

Fix it by skipping all of the root part, not just a potential drive prefix. offset_1st_component takes care of this, see the implementation in compat/mingw.c::mingw_offset_1st_component().

There is a change in behavior: \\server\share is not transformed into //server/share anymore, but all subsequent directory separators are rewritten to '/'. This should not make a difference; Windows can handle the mix. In the context of 'git push' this cannot be verified, though, as there seems to be an independent bug that transforms the double '\\' to a single '\' on the way.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 Another long-standing bug uncovered by the quarantine series.
 Dscho, it looks like this could fix the original report at
 https://github.com/git-for-windows/git/issues/979
 This patch should cook well because of the change in behavior.
 I would not be surprised if there is some fall-out.
 The other bug I'm alluding to, I still have to investigate. I do
 not think that it can be counted as fall-out.
 path.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/path.c b/path.c
index 52d889c88e..02dc70fb92 100644
--- a/path.c
+++ b/path.c
@@ -991,7 +991,7 @@ const char *remove_leading_path(const char *in, const char *prefix)
  *
  * Performs the following normalizations on src, storing the result in dst:
  * - Ensures that components are separated by '/' (Windows only)
- * - Squashes sequences of '/'.
+ * - Squashes sequences of '/' except "//server/share" on Windows
  * - Removes "." components.
  * - Removes ".." components, and the components the precede them.
  * Returns failure (non-zero) if a ".." component appears as first path
@@ -1014,17 +1014,23 @@ const char *remove_leading_path(const char *in, const char *prefix)
 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
 {
 	char *dst0;
-	int i;
-
-	for (i = has_dos_drive_prefix(src); i > 0; i--)
-		*dst++ = *src++;
-	dst0 = dst;
+	int offset;
 
-	if (is_dir_sep(*src)) {
+	/*
+	 * Handle initial part of absolute path: "/", "C:/", "\\server\share/".
+	 */
+	offset = offset_1st_component(src);
+	if (offset) {
+		/* Convert the trailing separator to '/' on Windows. */
+		memcpy(dst, src, offset - 1);
+		dst += offset - 1;
 		*dst++ = '/';
-		while (is_dir_sep(*src))
-			src++;
+		src += offset;
 	}
+	dst0 = dst;
+
+	while (is_dir_sep(*src))
+		src++;
 
 	for (;;) {
 		char c = *src;
-- 
2.11.0.79.g263f27a
Next: Junio C Hamano
Message 1 of 8 in “fix pushing to //server/share/dir paths on Windows”
  1. fix pushing to //server/share/dir paths on WindowsJohannes Sixt, Dec 13, 2016
  2. Junio C HamanoDec 13, 2016
  3. Jeff KingDec 14, 2016
  4. fix pushing to //server/share/dir on WindowsJohannes Sixt, Dec 14, 2016
  5. Torsten BögershausenDec 15, 2016
  6. Jeff KingDec 15, 2016
  7. Junio C HamanoDec 15, 2016
  8. Johannes SchindelinDec 19, 2016

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.