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 <sunshine@sunshineco.com> CC: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Oct 12, 2015 at 10:58 UTC 147875fd25ca21c580102529dd51de15acae178c
1 file changed +29 -45
submodule-config.c
+29 -45
@@ -257,78 +257,62 @@ static int parse_config(const char *var, const char *value, void *data)
257 if (!name_and_item_from_var(var, &name, &item))
258 return 0;
259
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);
263
264 if (!strcmp(item.buf, "path")) {
264 - struct strbuf path = STRBUF_INIT;
265 - if (!value) {
265 + if (!value)
266 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)
268 warn_multiple_config(me->commit_sha1, submodule->name,
269 "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);
276 }
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);
277 } else if (!strcmp(item.buf, "fetchrecursesubmodules")) {
278 /* when parsing worktree configurations we can die early */
279 int die_on_error = is_null_sha1(me->gitmodules_sha1);
280 if (!me->overwrite &&
285 - submodule->fetch_recurse != RECURSE_SUBMODULES_NONE) {
281 + submodule->fetch_recurse != RECURSE_SUBMODULES_NONE)
282 warn_multiple_config(me->commit_sha1, submodule->name,
283 "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,
287 die_on_error);
288 } 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)
292 warn_multiple_config(me->commit_sha1, submodule->name,
293 "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"))
298 warning("Invalid parameter '%s' for config option "
299 "'submodule.%s.ignore'", value, var);
308 - goto release_return;
300 + else {
301 + free((void *) submodule->ignore);
302 + submodule->ignore = xstrdup(value);
303 }
310 -
311 - free((void *) submodule->ignore);
312 - strbuf_addstr(&ignore, value);
313 - submodule->ignore = strbuf_detach(&ignore, NULL);
304 } else if (!strcmp(item.buf, "url")) {
315 - struct strbuf url = STRBUF_INIT;
305 if (!value) {
306 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) {
308 warn_multiple_config(me->commit_sha1, submodule->name,
309 "url");
323 - goto release_return;
310 + } else {
311 + free((void *) submodule->url);
312 + submodule->url = xstrdup(value);
313 }
325 -
326 - free((void *) submodule->url);
327 - strbuf_addstr(&url, value);
328 - submodule->url = strbuf_detach(&url, NULL);
314 }
315
331 -release_return:
316 strbuf_release(&name);
317 strbuf_release(&item);
318