oneway_merge(): only lstat() when told to update worktree
[gitweb.git] / path.c
diff --git a/path.c b/path.c
index 6f2aa699ad63c2f7c65632761efbaebb7f461868..66acd24fa8821861d032fc216f6ea6fdd711a969 100644 (file)
--- a/path.c
+++ b/path.c
@@ -87,6 +87,21 @@ char *git_pathdup(const char *fmt, ...)
        return xstrdup(path);
 }
 
+char *mkpathdup(const char *fmt, ...)
+{
+       char *path;
+       struct strbuf sb = STRBUF_INIT;
+       va_list args;
+
+       va_start(args, fmt);
+       strbuf_vaddf(&sb, fmt, args);
+       va_end(args);
+       path = xstrdup(cleanup_path(sb.buf));
+
+       strbuf_release(&sb);
+       return path;
+}
+
 char *mkpath(const char *fmt, ...)
 {
        va_list args;
@@ -122,6 +137,32 @@ char *git_path(const char *fmt, ...)
        return cleanup_path(pathname);
 }
 
+void home_config_paths(char **global, char **xdg, char *file)
+{
+       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_home)
+               *xdg = NULL;
+       else
+               *xdg = mkpathdup("%s/git/%s", xdg_home, file);
+
+       free(to_free);
+}
+
 char *git_path_submodule(const char *path, const char *fmt, ...)
 {
        char *pathname = get_pathname();