Skip to content

Commit 9edbb8b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Acked-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0a5987f commit 9edbb8b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

submodule.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,38 +126,39 @@ void gitmodules_config(void)
126126

127127
int parse_submodule_config_option(const char *var, const char *value)
128128
{
129-
int len;
130129
struct string_list_item *config;
131130
struct strbuf submodname = STRBUF_INIT;
131+
const char *name, *key;
132+
int namelen;
132133

133-
var += 10; /* Skip "submodule." */
134+
if (parse_config_key(var, "submodule", &name, &namelen, &key) < 0 || !name)
135+
return 0;
134136

135-
len = strlen(var);
136-
if ((len > 5) && !strcmp(var + len - 5, ".path")) {
137-
strbuf_add(&submodname, var, len - 5);
137+
if (!strcmp(key, "path")) {
138+
strbuf_add(&submodname, name, namelen);
138139
config = unsorted_string_list_lookup(&config_name_for_path, value);
139140
if (config)
140141
free(config->util);
141142
else
142143
config = string_list_append(&config_name_for_path, xstrdup(value));
143144
config->util = strbuf_detach(&submodname, NULL);
144145
strbuf_release(&submodname);
145-
} else if ((len > 23) && !strcmp(var + len - 23, ".fetchrecursesubmodules")) {
146-
strbuf_add(&submodname, var, len - 23);
146+
} else if (!strcmp(key, "fetchrecursesubmodules")) {
147+
strbuf_add(&submodname, name, namelen);
147148
config = unsorted_string_list_lookup(&config_fetch_recurse_submodules_for_name, submodname.buf);
148149
if (!config)
149150
config = string_list_append(&config_fetch_recurse_submodules_for_name,
150151
strbuf_detach(&submodname, NULL));
151152
config->util = (void *)(intptr_t)parse_fetch_recurse_submodules_arg(var, value);
152153
strbuf_release(&submodname);
153-
} else if ((len > 7) && !strcmp(var + len - 7, ".ignore")) {
154+
} else if (!strcmp(key, "ignore")) {
154155
if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
155156
strcmp(value, "all") && strcmp(value, "none")) {
156157
warning("Invalid parameter \"%s\" for config option \"submodule.%s.ignore\"", value, var);
157158
return 0;
158159
}
159160

160-
strbuf_add(&submodname, var, len - 7);
161+
strbuf_add(&submodname, name, namelen);
161162
config = unsorted_string_list_lookup(&config_ignore_for_name, submodname.buf);
162163
if (config)
163164
free(config->util);

0 commit comments

Comments
 (0)