diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-02-04 10:24:50 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-02-04 10:24:50 -0800 |
commit | 099ba556d05571001293c8eda10a4fc659f83f48 (patch) | |
tree | a7eb1760f82fdd9f769ea6a64e6ece7198ef471c /config.c | |
parent | 149a4211a4b8d8bbcdd72685d538d6ac7365e29e (diff) | |
parent | b3873c336cc2eb5a6eb2b10981a2ca0b65b8c987 (diff) | |
download | git-099ba556d05571001293c8eda10a4fc659f83f48.tar.gz |
Merge branch 'jk/config-parsing-cleanup'
Configuration parsing for tar.* configuration variables were
broken. Introduce a new config-keyname parser API to make the
callers much less error prone.
* jk/config-parsing-cleanup:
reflog: use parse_config_key in config callback
help: use parse_config_key for man config
submodule: simplify memory handling in config parsing
submodule: use parse_config_key when parsing config
userdiff: drop parse_driver function
convert some config callbacks to parse_config_key
archive-tar: use parse_config_key when parsing config
config: add helper function for parsing key names
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -1681,3 +1681,36 @@ int config_error_nonbool(const char *var) { return error("Missing value for '%s'", var); } + +int parse_config_key(const char *var, + const char *section, + const char **subsection, int *subsection_len, + const char **key) +{ + int section_len = strlen(section); + const char *dot; + + /* Does it start with "section." ? */ + if (prefixcmp(var, section) || var[section_len] != '.') + return -1; + + /* + * Find the key; we don't know yet if we have a subsection, but we must + * parse backwards from the end, since the subsection may have dots in + * it, too. + */ + dot = strrchr(var, '.'); + *key = dot + 1; + + /* Did we have a subsection at all? */ + if (dot == var + section_len) { + *subsection = NULL; + *subsection_len = 0; + } + else { + *subsection = var + section_len + 1; + *subsection_len = dot - *subsection; + } + + return 0; +} |