tag.c: use 'ref-filter' data structures
[gitweb.git] / path.c
diff --git a/path.c b/path.c
index 586f2c90a3c0def34016a692a14e335a46c015ed..95acbafa6883b4418f19a208cb9889f5642f3925 100644 (file)
--- a/path.c
+++ b/path.c
@@ -224,39 +224,10 @@ const char *mkpath(const char *fmt, ...)
        return cleanup_path(pathname->buf);
 }
 
-void home_config_paths(char **global, char **xdg, char *file)
+static void do_submodule_path(struct strbuf *buf, const char *path,
+                             const char *fmt, va_list args)
 {
-       char *xdg_home = getenv("XDG_CONFIG_HOME");
-       char *home = getenv("HOME");
-       char *to_free = NULL;
-
-       if (!home) {
-               if (global)
-                       *global = NULL;
-       } else {
-               if (!xdg_home) {
-                       to_free = mkpathdup("%s/.config", home);
-                       xdg_home = to_free;
-               }
-               if (global)
-                       *global = mkpathdup("%s/.gitconfig", home);
-       }
-
-       if (xdg) {
-               if (!xdg_home)
-                       *xdg = NULL;
-               else
-                       *xdg = mkpathdup("%s/git/%s", xdg_home, file);
-       }
-
-       free(to_free);
-}
-
-const char *git_path_submodule(const char *path, const char *fmt, ...)
-{
-       struct strbuf *buf = get_pathname();
        const char *git_dir;
-       va_list args;
 
        strbuf_addstr(buf, path);
        if (buf->len && buf->buf[buf->len - 1] != '/')
@@ -270,11 +241,27 @@ const char *git_path_submodule(const char *path, const char *fmt, ...)
        }
        strbuf_addch(buf, '/');
 
-       va_start(args, fmt);
        strbuf_vaddf(buf, fmt, args);
-       va_end(args);
        strbuf_cleanup_path(buf);
-       return buf->buf;
+}
+
+char *git_pathdup_submodule(const char *path, const char *fmt, ...)
+{
+       va_list args;
+       struct strbuf buf = STRBUF_INIT;
+       va_start(args, fmt);
+       do_submodule_path(&buf, path, fmt, args);
+       va_end(args);
+       return strbuf_detach(&buf, NULL);
+}
+
+void strbuf_git_path_submodule(struct strbuf *buf, const char *path,
+                              const char *fmt, ...)
+{
+       va_list args;
+       va_start(args, fmt);
+       do_submodule_path(buf, path, fmt, args);
+       va_end(args);
 }
 
 int validate_headref(const char *path)
@@ -931,3 +918,28 @@ int is_ntfs_dotgit(const char *name)
                        len = -1;
                }
 }
+
+char *xdg_config_home(const char *filename)
+{
+       const char *home, *config_home;
+
+       assert(filename);
+       config_home = getenv("XDG_CONFIG_HOME");
+       if (config_home && *config_home)
+               return mkpathdup("%s/git/%s", config_home, filename);
+
+       home = getenv("HOME");
+       if (home)
+               return mkpathdup("%s/.config/git/%s", home, filename);
+       return NULL;
+}
+
+GIT_PATH_FUNC(git_path_cherry_pick_head, "CHERRY_PICK_HEAD")
+GIT_PATH_FUNC(git_path_revert_head, "REVERT_HEAD")
+GIT_PATH_FUNC(git_path_squash_msg, "SQUASH_MSG")
+GIT_PATH_FUNC(git_path_merge_msg, "MERGE_MSG")
+GIT_PATH_FUNC(git_path_merge_rr, "MERGE_RR")
+GIT_PATH_FUNC(git_path_merge_mode, "MERGE_MODE")
+GIT_PATH_FUNC(git_path_merge_head, "MERGE_HEAD")
+GIT_PATH_FUNC(git_path_fetch_head, "FETCH_HEAD")
+GIT_PATH_FUNC(git_path_shallow, "shallow")