cache.h: Introduce a generic "xdg_config_home_for(…)" function
Current implementation of `xdg_config_home(filename)` returns `$XDG_CONFIG_HOME/git/$filename`, with the `git` subdirectory inserted between the `XDG_CONFIG_HOME` environment variable and the parameter. This patch introduces a `xdg_config_home_for(subdir, filename)` function which is more generic. It only concatenates "$XDG_CONFIG_HOME", or "$HOME/.config" if the former isn’t defined, with the parameters, without adding `git` in between. `xdg_config_home(filename)` is now implemented by calling `xdg_config_home_for("git", filename)` but this new generic function can be used to compute the configuration directory of other programs. Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr> Acked-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ebf3c04b26
commit
cb7db5bbd5
7
cache.h
7
cache.h
@ -1286,6 +1286,13 @@ int is_ntfs_dotmailmap(const char *name);
|
|||||||
*/
|
*/
|
||||||
int looks_like_command_line_option(const char *str);
|
int looks_like_command_line_option(const char *str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a newly allocated string with the evaluation of
|
||||||
|
* "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
|
||||||
|
* "$HOME/.config/$subdir/$filename". Return NULL upon error.
|
||||||
|
*/
|
||||||
|
char *xdg_config_home_for(const char *subdir, const char *filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a newly allocated string with the evaluation of
|
* Return a newly allocated string with the evaluation of
|
||||||
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
|
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
|
||||||
|
13
path.c
13
path.c
@ -1503,21 +1503,28 @@ int looks_like_command_line_option(const char *str)
|
|||||||
return str && str[0] == '-';
|
return str && str[0] == '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *xdg_config_home(const char *filename)
|
char *xdg_config_home_for(const char *subdir, const char *filename)
|
||||||
{
|
{
|
||||||
const char *home, *config_home;
|
const char *home, *config_home;
|
||||||
|
|
||||||
|
assert(subdir);
|
||||||
assert(filename);
|
assert(filename);
|
||||||
config_home = getenv("XDG_CONFIG_HOME");
|
config_home = getenv("XDG_CONFIG_HOME");
|
||||||
if (config_home && *config_home)
|
if (config_home && *config_home)
|
||||||
return mkpathdup("%s/git/%s", config_home, filename);
|
return mkpathdup("%s/%s/%s", config_home, subdir, filename);
|
||||||
|
|
||||||
home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
if (home)
|
if (home)
|
||||||
return mkpathdup("%s/.config/git/%s", home, filename);
|
return mkpathdup("%s/.config/%s/%s", home, subdir, filename);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *xdg_config_home(const char *filename)
|
||||||
|
{
|
||||||
|
return xdg_config_home_for("git", filename);
|
||||||
|
}
|
||||||
|
|
||||||
char *xdg_cache_home(const char *filename)
|
char *xdg_cache_home(const char *filename)
|
||||||
{
|
{
|
||||||
const char *home, *cache_home;
|
const char *home, *cache_home;
|
||||||
|
Loading…
Reference in New Issue
Block a user