From 21cf32279120799a766d22416be7d82d9ecfbd04 Mon Sep 17 00:00:00 2001 From: Huynh Khoi Nguyen Nguyen Date: Fri, 22 Jun 2012 11:03:23 +0200 Subject: config: read (but not write) from $XDG_CONFIG_HOME/git/config file Teach git to read the "gitconfig" information from a new location, $XDG_CONFIG_HOME/git/config; this allows the user to avoid cluttering $HOME with many per-application configuration files. In the order of reading, this file comes between the global configuration file (typically $HOME/.gitconfig) and the system wide configuration file (typically /etc/gitconfig). We do not write to this new location (yet). If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/config will be used. This is in line with XDG specification. If the new file does not exist, the behavior is unchanged. Signed-off-by: Huynh Khoi Nguyen Nguyen Signed-off-by: Valentin Duperray Signed-off-by: Franck Jonas Signed-off-by: Lucien Kong Signed-off-by: Thomas Nguy Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- path.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'path.c') diff --git a/path.c b/path.c index 6f2aa699a..66acd24fa 100644 --- 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(); -- cgit v1.2.1