]> git.ipfire.org Git - thirdparty/git.git/blobdiff - path.c
normalize_path_copy(): fix pushing to //server/share/dir on Windows
[thirdparty/git.git] / path.c
diff --git a/path.c b/path.c
index 259aeed846bd3dac8e10cde30a22ec1ad8697a63..f4e5ffb44bc2c4ad67c8fdec4581206c75ed2950 100644 (file)
--- a/path.c
+++ b/path.c
@@ -483,7 +483,7 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
                strbuf_addstr(buf, git_dir);
        }
        strbuf_addch(buf, '/');
-       strbuf_addstr(&git_submodule_dir, buf->buf);
+       strbuf_addbuf(&git_submodule_dir, buf);
 
        strbuf_vaddf(buf, fmt, args);
 
@@ -961,7 +961,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
@@ -984,17 +984,22 @@ 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;
+       const char *end;
 
-       for (i = has_dos_drive_prefix(src); i > 0; i--)
-               *dst++ = *src++;
+       /*
+        * Copy initial part of absolute path: "/", "C:/", "//server/share/".
+        */
+       end = src + offset_1st_component(src);
+       while (src < end) {
+               char c = *src++;
+               if (is_dir_sep(c))
+                       c = '/';
+               *dst++ = c;
+       }
        dst0 = dst;
 
-       if (is_dir_sep(*src)) {
-               *dst++ = '/';
-               while (is_dir_sep(*src))
-                       src++;
-       }
+       while (is_dir_sep(*src))
+               src++;
 
        for (;;) {
                char c = *src;