Skip to content

Commit 147875f

Browse files
stefanbellergitster
authored andcommitted
submodule-config: "goto" removal in parse_config()
Many components in if/else if/... cascade jumped to a shared clean-up with "goto release_return", but we can restructure the function a bit and make them disappear, which reduces the line count as well. Also reformat overlong lines and poorly indented ones while at it. The order of rules to verify the value for "ignore" used to be to complain on multiple values first and then complain to boolean, but swap the order to match how the values for "path" and "url" are verified. CC: Eric Sunshine <[email protected]> CC: Heiko Voigt <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22f698c commit 147875f

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

submodule-config.c

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -257,78 +257,62 @@ static int parse_config(const char *var, const char *value, void *data)
257257
if (!name_and_item_from_var(var, &name, &item))
258258
return 0;
259259

260-
submodule = lookup_or_create_by_name(me->cache, me->gitmodules_sha1,
261-
name.buf);
260+
submodule = lookup_or_create_by_name(me->cache,
261+
me->gitmodules_sha1,
262+
name.buf);
262263

263264
if (!strcmp(item.buf, "path")) {
264-
struct strbuf path = STRBUF_INIT;
265-
if (!value) {
265+
if (!value)
266266
ret = config_error_nonbool(var);
267-
goto release_return;
268-
}
269-
if (!me->overwrite && submodule->path != NULL) {
267+
else if (!me->overwrite && submodule->path != NULL)
270268
warn_multiple_config(me->commit_sha1, submodule->name,
271269
"path");
272-
goto release_return;
270+
else {
271+
if (submodule->path)
272+
cache_remove_path(me->cache, submodule);
273+
free((void *) submodule->path);
274+
submodule->path = xstrdup(value);
275+
cache_put_path(me->cache, submodule);
273276
}
274-
275-
if (submodule->path)
276-
cache_remove_path(me->cache, submodule);
277-
free((void *) submodule->path);
278-
strbuf_addstr(&path, value);
279-
submodule->path = strbuf_detach(&path, NULL);
280-
cache_put_path(me->cache, submodule);
281277
} else if (!strcmp(item.buf, "fetchrecursesubmodules")) {
282278
/* when parsing worktree configurations we can die early */
283279
int die_on_error = is_null_sha1(me->gitmodules_sha1);
284280
if (!me->overwrite &&
285-
submodule->fetch_recurse != RECURSE_SUBMODULES_NONE) {
281+
submodule->fetch_recurse != RECURSE_SUBMODULES_NONE)
286282
warn_multiple_config(me->commit_sha1, submodule->name,
287283
"fetchrecursesubmodules");
288-
goto release_return;
289-
}
290-
291-
submodule->fetch_recurse = parse_fetch_recurse(var, value,
284+
else
285+
submodule->fetch_recurse = parse_fetch_recurse(
286+
var, value,
292287
die_on_error);
293288
} else if (!strcmp(item.buf, "ignore")) {
294-
struct strbuf ignore = STRBUF_INIT;
295-
if (!me->overwrite && submodule->ignore != NULL) {
289+
if (!value)
290+
ret = config_error_nonbool(var);
291+
else if (!me->overwrite && submodule->ignore != NULL)
296292
warn_multiple_config(me->commit_sha1, submodule->name,
297293
"ignore");
298-
goto release_return;
299-
}
300-
if (!value) {
301-
ret = config_error_nonbool(var);
302-
goto release_return;
303-
}
304-
if (strcmp(value, "untracked") && strcmp(value, "dirty") &&
305-
strcmp(value, "all") && strcmp(value, "none")) {
294+
else if (strcmp(value, "untracked") &&
295+
strcmp(value, "dirty") &&
296+
strcmp(value, "all") &&
297+
strcmp(value, "none"))
306298
warning("Invalid parameter '%s' for config option "
307299
"'submodule.%s.ignore'", value, var);
308-
goto release_return;
300+
else {
301+
free((void *) submodule->ignore);
302+
submodule->ignore = xstrdup(value);
309303
}
310-
311-
free((void *) submodule->ignore);
312-
strbuf_addstr(&ignore, value);
313-
submodule->ignore = strbuf_detach(&ignore, NULL);
314304
} else if (!strcmp(item.buf, "url")) {
315-
struct strbuf url = STRBUF_INIT;
316305
if (!value) {
317306
ret = config_error_nonbool(var);
318-
goto release_return;
319-
}
320-
if (!me->overwrite && submodule->url != NULL) {
307+
} else if (!me->overwrite && submodule->url != NULL) {
321308
warn_multiple_config(me->commit_sha1, submodule->name,
322309
"url");
323-
goto release_return;
310+
} else {
311+
free((void *) submodule->url);
312+
submodule->url = xstrdup(value);
324313
}
325-
326-
free((void *) submodule->url);
327-
strbuf_addstr(&url, value);
328-
submodule->url = strbuf_detach(&url, NULL);
329314
}
330315

331-
release_return:
332316
strbuf_release(&name);
333317
strbuf_release(&item);
334318

0 commit comments

Comments
 (0)