mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'pt/xdg-config-path'
Code clean-up for xdg configuration path support. * pt/xdg-config-path: path.c: remove home_config_paths() git-config: replace use of home_config_paths() git-commit: replace use of home_config_paths() credential-store.c: replace home_config_paths() with xdg_config_home() dir.c: replace home_config_paths() with xdg_config_home() attr.c: replace home_config_paths() with xdg_config_home() path.c: implement xdg_config_home()
This commit is contained in:
43
path.c
43
path.c
@@ -224,34 +224,6 @@ const char *mkpath(const char *fmt, ...)
|
||||
return cleanup_path(pathname->buf);
|
||||
}
|
||||
|
||||
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) {
|
||||
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();
|
||||
@@ -931,3 +903,18 @@ 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user