]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-remote: simplify UNLEAK() usage
authorJeff King <peff@peff.net>
Thu, 13 Aug 2020 15:55:51 +0000 (11:55 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Aug 2020 18:05:26 +0000 (11:05 -0700)
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>
builtin/ls-remote.c

index 3a4dd12903206ae47fd4683e3bef1a7371d67d55..5f969eb879dddc8f300d6528600e66802e84bddb 100644 (file)
@@ -83,6 +83,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                             PARSE_OPT_STOP_AT_NON_OPTION);
        dest = argv[0];
 
+       UNLEAK(sorting);
+
        if (argc > 1) {
                int i;
                pattern = xcalloc(argc, sizeof(const char *));
@@ -107,7 +109,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
        if (get_url) {
                printf("%s\n", *remote->url);
-               UNLEAK(sorting);
                return 0;
        }
 
@@ -122,10 +123,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
                repo_set_hash_algo(the_repository, hash_algo);
        }
-       if (transport_disconnect(transport)) {
-               UNLEAK(sorting);
+       if (transport_disconnect(transport))
                return 1;
-       }
 
        if (!dest && !quiet)
                fprintf(stderr, "From %s\n", *remote->url);
@@ -150,7 +149,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                status = 0; /* we found something */
        }
 
-       UNLEAK(sorting);
        ref_array_clear(&ref_array);
        return status;
 }