]> git.ipfire.org Git - thirdparty/git.git/blobdiff - path.c
sequencer (rebase -i): respect strategy/strategy_opts settings
[thirdparty/git.git] / path.c
diff --git a/path.c b/path.c
index 9bfaeda2071636ec8a5a5ee32491494f5f83211c..efcedafba6f2c0cae218f2d32425c13272df8dea 100644 (file)
--- a/path.c
+++ b/path.c
@@ -6,6 +6,7 @@
 #include "string-list.h"
 #include "dir.h"
 #include "worktree.h"
+#include "submodule-config.h"
 
 static int get_st_mode_bits(const char *path, int *mode)
 {
@@ -469,12 +470,16 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
        return pathname->buf;
 }
 
-static void do_submodule_path(struct strbuf *buf, const char *path,
-                             const char *fmt, va_list args)
+/* Returns 0 on success, negative on failure. */
+#define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1
+static int do_submodule_path(struct strbuf *buf, const char *path,
+                            const char *fmt, va_list args)
 {
        const char *git_dir;
        struct strbuf git_submodule_common_dir = STRBUF_INIT;
        struct strbuf git_submodule_dir = STRBUF_INIT;
+       const struct submodule *sub;
+       int err = 0;
 
        strbuf_addstr(buf, path);
        strbuf_complete(buf, '/');
@@ -485,6 +490,17 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
                strbuf_reset(buf);
                strbuf_addstr(buf, git_dir);
        }
+       if (!is_git_directory(buf->buf)) {
+               gitmodules_config();
+               sub = submodule_from_path(null_sha1, path);
+               if (!sub) {
+                       err = SUBMODULE_PATH_ERR_NOT_CONFIGURED;
+                       goto cleanup;
+               }
+               strbuf_reset(buf);
+               strbuf_git_path(buf, "%s/%s", "modules", sub->name);
+       }
+
        strbuf_addch(buf, '/');
        strbuf_addbuf(&git_submodule_dir, buf);
 
@@ -495,27 +511,38 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
 
        strbuf_cleanup_path(buf);
 
+cleanup:
        strbuf_release(&git_submodule_dir);
        strbuf_release(&git_submodule_common_dir);
+
+       return err;
 }
 
 char *git_pathdup_submodule(const char *path, const char *fmt, ...)
 {
+       int err;
        va_list args;
        struct strbuf buf = STRBUF_INIT;
        va_start(args, fmt);
-       do_submodule_path(&buf, path, fmt, args);
+       err = do_submodule_path(&buf, path, fmt, args);
        va_end(args);
+       if (err) {
+               strbuf_release(&buf);
+               return NULL;
+       }
        return strbuf_detach(&buf, NULL);
 }
 
-void strbuf_git_path_submodule(struct strbuf *buf, const char *path,
-                              const char *fmt, ...)
+int strbuf_git_path_submodule(struct strbuf *buf, const char *path,
+                             const char *fmt, ...)
 {
+       int err;
        va_list args;
        va_start(args, fmt);
-       do_submodule_path(buf, path, fmt, args);
+       err = do_submodule_path(buf, path, fmt, args);
        va_end(args);
+
+       return err;
 }
 
 static void do_git_common_path(struct strbuf *buf,
@@ -964,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
@@ -987,17 +1014,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;