@matheusbsbs / matheus-bagliano / commits / 3e19816dc0
Fork 0

ls-remote: simplify UNLEAK() usage

We UNLEAK() the "sorting" list created by parsing command-line options (which is essentially used until the program exits). But we do so right before leaving the cmd_ls_remote() function, which means we have to hit all of the exits. But the point of UNLEAK() is that it's an annotation which doesn't impact the variable itself. We can mark it as soon as we're done writing its value, and then we only have to do so once. This gives us a minor code reduction, and serves as a better example of how UNLEAK() can be used. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 13, 2020 at 11:55 UTC 3e19816dc044a4aca4a15276c92f804c44d0f65f
1 file changed +3 -5
builtin/ls-remote.c
+3 -5
@@ -83,6 +83,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
83 PARSE_OPT_STOP_AT_NON_OPTION);
84 dest = argv[0];
85
86 + UNLEAK(sorting);
87 +
88 if (argc > 1) {
89 int i;
90 pattern = xcalloc(argc, sizeof(const char *));
@@ -107,7 +109,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
109
110 if (get_url) {
111 printf("%s\n", *remote->url);
110 - UNLEAK(sorting);
112 return 0;
113 }
114
@@ -122,10 +123,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
123 int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
124 repo_set_hash_algo(the_repository, hash_algo);
125 }
125 - if (transport_disconnect(transport)) {
126 - UNLEAK(sorting);
126 + if (transport_disconnect(transport))
127 return 1;
128 - }
128
129 if (!dest && !quiet)
130 fprintf(stderr, "From %s\n", *remote->url);
@@ -150,7 +149,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
149 status = 0; /* we found something */
150 }
151
153 - UNLEAK(sorting);
152 ref_array_clear(&ref_array);
153 return status;
154 }