diff options
| author | Jeff King <peff@peff.net> | 2024-06-14 06:29:09 -0400 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-06-14 09:34:38 -0700 |
| commit | b68118d2e85eef7aa993ef8e944e53b5be665160 (patch) | |
| tree | 498802a667ce3bcd3d2febf0b86c889bada10e25 /builtin/push.c | |
| parent | 8e804415fd3183f56ced0dcc168f8cb4aa790473 (diff) | |
| download | git-b68118d2e85eef7aa993ef8e944e53b5be665160.tar.gz | |
remote: simplify url/pushurl selection
When we want to know the push urls for a remote, there is some simple
logic:
- if the user configured any remote.*.pushurl keys, then those make
the complete set of push urls
- otherwise we push to all urls in remote.*.url
Many spots implement this with a level of indirection, assigning to a
local url/url_nr pair. But since both arrays are now strvecs, we can
just use a pointer to select the appropriate strvec, shortening the code
a bit.
Even though this is now a one-liner, since it is application logic that
is present in so many places, it's worth abstracting a helper function.
In fact, we already have such a function, but it's local to
builtin/push.c. So we'll just make it available everywhere via remote.h.
There are two spots to pay special attention to here:
1. in builtin/remote.c's get_url(), we are selecting first based on
push_mode and then falling back to "url" when we're in push_mode
but no pushurl is defined. The updated code makes that much more
clear, compared to the original which had an "else" fall-through.
2. likewise in that file's set_url(), we _only_ respect push_mode,
sine the point is that we are adding to pushurl in that case
(whether it is empty or not). And thus it does not use our helper
function.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/push.c')
| -rw-r--r-- | builtin/push.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/builtin/push.c b/builtin/push.c index 61b5d3afdd..00d99af1a8 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -141,16 +141,6 @@ static void set_refspecs(const char **refs, int nr, const char *repo) free_refs(local_refs); } -static int push_url_of_remote(struct remote *remote, const char ***url_p) -{ - if (remote->pushurl.nr) { - *url_p = remote->pushurl.v; - return remote->pushurl.nr; - } - *url_p = remote->url.v; - return remote->url.nr; -} - static NORETURN void die_push_simple(struct branch *branch, struct remote *remote) { @@ -434,8 +424,7 @@ static int do_push(int flags, struct remote *remote) { int i, errs; - const char **url; - int url_nr; + struct strvec *url; struct refspec *push_refspec = &rs; if (push_options->nr) @@ -448,11 +437,11 @@ static int do_push(int flags, setup_default_push_refspecs(&flags, remote); } errs = 0; - url_nr = push_url_of_remote(remote, &url); - if (url_nr) { - for (i = 0; i < url_nr; i++) { + url = push_url_of_remote(remote); + if (url->nr) { + for (i = 0; i < url->nr; i++) { struct transport *transport = - transport_get(remote, url[i]); + transport_get(remote, url->v[i]); if (flags & TRANSPORT_PUSH_OPTIONS) transport->push_options = push_options; if (push_with_options(transport, push_refspec, flags)) |
