summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-01-23 01:25:22 -0500
committerJunio C Hamano <gitster@pobox.com>2013-01-23 12:57:50 -0800
commit9edbb8b1c1fdb199b47650f50fc432b1bfcb9039 (patch)
tree4c551f5dba34ddffe178616bf6487d789a8acdae /submodule.c
parent0a5987fe5e0cea23245e0beab6eb47131864b276 (diff)
downloadgit-9edbb8b1c1fdb199b47650f50fc432b1bfcb9039.tar.gz
submodule: use parse_config_key when parsing config
This makes the code a lot simpler to read by dropping a whole bunch of constant offsets. As a bonus, it means we also feed the whole config variable name to our error functions: [before] $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout fatal: bad foo.fetchrecursesubmodules argument: bogus [after] $ git -c submodule.foo.fetchrecursesubmodules=bogus checkout fatal: bad submodule.foo.fetchrecursesubmodules argument: bogus Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/submodule.c b/submodule.c
index 2f55436234..25413deb1f 100644
--- a/submodule.c
+++ b/submodule.c
@@ -126,15 +126,16 @@ void gitmodules_config(void)
int parse_submodule_config_option(const char *var, const char *value)
{
- int len;
struct string_list_item *config;
struct strbuf submodname = STRBUF_INIT;
+ const char *name, *key;
+ int namelen;
- var += 10; /* Skip "submodule." */
+ if (parse_config_key(var, "submodule", &name, &namelen, &key) < 0 || !name)
+ return 0;
- len = strlen(var);
- if ((len > 5) && !strcmp(var + len - 5, ".path")) {
- strbuf_add(&submodname, var, len - 5);
+ if (!strcmp(key, "path")) {
+ strbuf_add(&submodname, name, namelen);
config = unsorted_string_list_lookup(&config_name_for_path, value);
if (config)
free(config->util);
@@ -142,22 +143,22 @@ int parse_submodule_config_option(const char *var, const char *value)
config = string_list_append(&config_name_for_path, xstrdup(value));
config->util = strbuf_detach(&submodname, NULL);
strbuf_release(&submodname);
- } else if ((len > 23) && !strcmp(var + len - 23, ".fetchrecursesubmodules")) {
- strbuf_add(&submodname, var, len - 23);
+ } else if (!strcmp(key, "fetchrecursesubmodules")) {
+ strbuf_add(&submodname, name, namelen);
config = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, submodname.buf);
if (!config)
config = string_list_append(&config_fetch_recurse_submodules_for_name,
strbuf_detach(&submodname, NULL));
config->util = (void *)(intptr_t)parse_fetch_recurse_submodules_arg(var, value);
strbuf_release(&submodname);
- } else if ((len > 7) && !strcmp(var + len - 7, ".ignore")) {
+ } else if (!strcmp(key, "ignore")) {
if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
strcmp(value, "all") && strcmp(value, "none")) {
warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value, var);
return 0;
}
- strbuf_add(&submodname, var, len - 7);
+ strbuf_add(&submodname, name, namelen);
config = unsorted_string_list_lookup(&config_ignore_for_name, submodname.buf);
if (config)
free(config->util);