diff options
author | Huynh Khoi Nguyen Nguyen <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> | 2012-06-22 11:03:23 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-06-25 09:05:55 -0700 |
commit | 21cf32279120799a766d22416be7d82d9ecfbd04 (patch) | |
tree | 1d0d3324292a54bb70a7a3abd84fdca129313b2a /path.c | |
parent | 0e18bef7e62d6fffd09c394381056ec7a4a79840 (diff) | |
download | git-21cf32279120799a766d22416be7d82d9ecfbd04.tar.gz |
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 <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr>
Signed-off-by: Valentin Duperray <Valentin.Duperray@ensimag.imag.fr>
Signed-off-by: Franck Jonas <Franck.Jonas@ensimag.imag.fr>
Signed-off-by: Lucien Kong <Lucien.Kong@ensimag.imag.fr>
Signed-off-by: Thomas Nguy <Thomas.Nguy@ensimag.imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -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(); |