diff mbox series

[v3,1/3] builtin/fetch: use goto cleanup in cmd_fetch()

Message ID 20211222001134.28933-2-chooglen@google.com (mailing list archive)
State Accepted
Commit bec587d4c11e851c1e7b5ed7890d627c8346d1cb
Headers show
Series builtin/fetch: skip unnecessary tasks when using --negotiate-only | expand

Commit Message

Glen Choo Dec. 22, 2021, 12:11 a.m. UTC
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 was not
reused.

Signed-off-by: Glen Choo <chooglen@google.com>
---
 builtin/fetch.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/builtin/fetch.c b/builtin/fetch.c
index f7abbc31ff..eab73d7417 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2076,7 +2076,8 @@  int cmd_fetch(int argc, const char **argv, const char *prefix)
 			gtransport->smart_options->acked_commits = &acked_commits;
 		} else {
 			warning(_("Protocol does not support --negotiate-only, exiting."));
-			return 1;
+			result = 1;
+			goto cleanup;
 		}
 		if (server_options.nr)
 			gtransport->server_options = &server_options;
@@ -2132,8 +2133,6 @@  int cmd_fetch(int argc, const char **argv, const char *prefix)
 		strvec_clear(&options);
 	}
 
-	string_list_clear(&list, 0);
-
 	prepare_repo_settings(the_repository);
 	if (fetch_write_commit_graph > 0 ||
 	    (fetch_write_commit_graph < 0 &&
@@ -2151,5 +2150,7 @@  int cmd_fetch(int argc, const char **argv, const char *prefix)
 	if (enable_auto_gc)
 		run_auto_maintenance(verbosity < 0);
 
+ cleanup:
+	string_list_clear(&list, 0);
 	return result;
 }