fetch: use goto cleanup in cmd_fetch()
Replace an early return with 'goto cleanup' in cmd_fetch() so that the string_list is always cleared (the string_list_clear() call is purely cleanup; the string_list is not reused). This makes cleanup consistent so that a subsequent commit can use 'goto cleanup' to bail out early. Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Jan 18, 2022 at 16:00 UTC
bec587d4c11e851c1e7b5ed7890d627c8346d1cb
1 file changed
+4
-3
builtin/fetch.c
+4
-3
@@ -2076,7 +2076,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2076
gtransport->smart_options->acked_commits = &acked_commits;
2077
} else {
2078
warning(_("Protocol does not support --negotiate-only, exiting."));
2079
- return 1;
2079
+ result = 1;
2080
+ goto cleanup;
2081
}
2082
if (server_options.nr)
2083
gtransport->server_options = &server_options;
@@ -2132,8 +2133,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2133
strvec_clear(&options);
2134
}
2135
2135
- string_list_clear(&list, 0);
2136
-
2136
prepare_repo_settings(the_repository);
2137
if (fetch_write_commit_graph > 0 ||
2138
(fetch_write_commit_graph < 0 &&
@@ -2151,5 +2150,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
2150
if (enable_auto_gc)
2151
run_auto_maintenance(verbosity < 0);
2152
2153
+ cleanup:
2154
+ string_list_clear(&list, 0);
2155
return result;
2156
}