mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
config: values of pathname type can be prefixed with :(optional)
Sometimes people want to specify additional configuration data as "best effort" basis. Maybe commit.template configuration file points at somewhere in ~/template/ but on a particular system, the file may not exist and the user may be OK without using the template in such a case. When the value given to a configuration variable whose type is pathname wants to signal such an optional file, it can be marked by prepending ":(optional)" in front of it. Such a setting that is marked optional would avoid getting the command barf for a missing file, as an optional configuration setting that names a missing file is not even seen. cf. <xmqq5ywehb69.fsf@gitster.g> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
16
config.c
16
config.c
@@ -1279,11 +1279,23 @@ int git_config_string(char **dest, const char *var, const char *value)
|
||||
|
||||
int git_config_pathname(char **dest, const char *var, const char *value)
|
||||
{
|
||||
int is_optional;
|
||||
char *path;
|
||||
|
||||
if (!value)
|
||||
return config_error_nonbool(var);
|
||||
*dest = interpolate_path(value, 0);
|
||||
if (!*dest)
|
||||
|
||||
is_optional = skip_prefix(value, ":(optional)", &value);
|
||||
path = interpolate_path(value, 0);
|
||||
if (!path)
|
||||
die(_("failed to expand user dir in: '%s'"), value);
|
||||
|
||||
if (is_optional && is_missing_file(path)) {
|
||||
free(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*dest = path;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user