From: Elijah Newren <newren@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
Mathew George <mathewegeorge@gmail.com>,
git@vger.kernel.org
Subject: Re: [PATCH 11/11] remote: drop checks for zero-url case
Date: Tue, 25 Jun 2024 10:37:14 -0700 [thread overview]
Message-ID: <CABPp-BHdVp+4s7QN0xiXFzoimtDwMPbb4Gw=Kb5MsBoY+SNLvA@mail.gmail.com> (raw)
In-Reply-To: <20240614104203.GK222445@coredump.intra.peff.net>
On Fri, Jun 14, 2024 at 4:12 AM Jeff King <peff@peff.net> wrote:
>
> Now that the previous commit removed the possibility that a "struct
> remote" will ever have zero url fields, we can drop a number of
> redundant checks and untriggerable code paths.
Ooh, nice.
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Note for reviewers: the hunk in builtin/push.c is funny. The original
> code was:
>
> if (url->nr) {
> for (i = 0; i < url->nr; i++) {
> do this
> }
> } else {
> do that
> }
>
> And I removed the "do that" part along with the if/else to become:
>
> for (i = 0; i < url->nr; i++) {
> do this
> }
>
>
> But because "this" and "that" were so similar, and because the
> indentation of "this" in the loop was now the same of the old "that",
> the diff makes it look like I dropped the first half of the conditional.
Thanks for adding this comment; was very helpful while reviewing.
> builtin/archive.c | 2 --
> builtin/ls-remote.c | 2 --
> builtin/push.c | 13 ++-----------
> builtin/remote.c | 13 +++----------
> t/helper/test-bundle-uri.c | 2 --
> transport.c | 17 +++++++----------
> 6 files changed, 12 insertions(+), 37 deletions(-)
>
> diff --git a/builtin/archive.c b/builtin/archive.c
> index 0d9aff7e6f..7234607aaa 100644
> --- a/builtin/archive.c
> +++ b/builtin/archive.c
> @@ -31,8 +31,6 @@ static int run_remote_archiver(int argc, const char **argv,
> struct packet_reader reader;
>
> _remote = remote_get(remote);
> - if (!_remote->url.nr)
> - die(_("git archive: Remote with no URL"));
> transport = transport_get(_remote, _remote->url.v[0]);
> transport_connect(transport, "git-upload-archive", exec, fd);
>
> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
> index 4c04dbbf19..8f3a64d838 100644
> --- a/builtin/ls-remote.c
> +++ b/builtin/ls-remote.c
> @@ -109,8 +109,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
> die("bad repository '%s'", dest);
> die("No remote configured to list refs from.");
> }
> - if (!remote->url.nr)
> - die("remote %s has no configured URL", dest);
>
> if (get_url) {
> printf("%s\n", remote->url.v[0]);
> diff --git a/builtin/push.c b/builtin/push.c
> index 00d99af1a8..8260c6e46a 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -438,18 +438,9 @@ static int do_push(int flags,
> }
> errs = 0;
> url = push_url_of_remote(remote);
> - if (url->nr) {
> - for (i = 0; i < url->nr; i++) {
> - struct transport *transport =
> - transport_get(remote, url->v[i]);
> - if (flags & TRANSPORT_PUSH_OPTIONS)
> - transport->push_options = push_options;
> - if (push_with_options(transport, push_refspec, flags))
> - errs++;
> - }
> - } else {
> + for (i = 0; i < url->nr; i++) {
> struct transport *transport =
> - transport_get(remote, NULL);
> + transport_get(remote, url->v[i]);
> if (flags & TRANSPORT_PUSH_OPTIONS)
> transport->push_options = push_options;
> if (push_with_options(transport, push_refspec, flags))
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 06c09ed060..c5c94d4dbd 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -1002,8 +1002,7 @@ static int get_remote_ref_states(const char *name,
> struct transport *transport;
> const struct ref *remote_refs;
>
> - transport = transport_get(states->remote, states->remote->url.nr > 0 ?
> - states->remote->url.v[0] : NULL);
> + transport = transport_get(states->remote, states->remote->url.v[0]);
> remote_refs = transport_get_remote_refs(transport, NULL);
>
> states->queried = 1;
> @@ -1294,8 +1293,7 @@ static int show(int argc, const char **argv, const char *prefix)
> get_remote_ref_states(*argv, &info.states, query_flag);
>
> printf_ln(_("* remote %s"), *argv);
> - printf_ln(_(" Fetch URL: %s"), info.states.remote->url.nr > 0 ?
> - info.states.remote->url.v[0] : _("(no URL)"));
> + printf_ln(_(" Fetch URL: %s"), info.states.remote->url.v[0]);
> url = push_url_of_remote(info.states.remote);
> for (i = 0; i < url->nr; i++)
> /*
> @@ -1440,10 +1438,7 @@ static int prune_remote(const char *remote, int dry_run)
> }
>
> printf_ln(_("Pruning %s"), remote);
> - printf_ln(_("URL: %s"),
> - states.remote->url.nr
> - ? states.remote->url.v[0]
> - : _("(no URL)"));
> + printf_ln(_("URL: %s"), states.remote->url.v[0]);
>
> for_each_string_list_item(item, &states.stale)
> string_list_append(&refs_to_prune, item->util);
> @@ -1632,8 +1627,6 @@ static int get_url(int argc, const char **argv, const char *prefix)
> }
>
> url = push_mode ? push_url_of_remote(remote) : &remote->url;
> - if (!url->nr)
> - die(_("no URLs configured for remote '%s'"), remotename);
>
> if (all_mode) {
> for (i = 0; i < url->nr; i++)
> diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c
> index 3285dd962e..0c5fa723d8 100644
> --- a/t/helper/test-bundle-uri.c
> +++ b/t/helper/test-bundle-uri.c
> @@ -88,8 +88,6 @@ static int cmd_ls_remote(int argc, const char **argv)
> die(_("bad repository '%s'"), dest);
> die(_("no remote configured to get bundle URIs from"));
> }
> - if (!remote->url.nr)
> - die(_("remote '%s' has no configured URL"), dest);
>
> transport = transport_get(remote, NULL);
> if (transport_get_remote_bundle_uri(transport) < 0) {
> diff --git a/transport.c b/transport.c
> index eba92eb7e0..a324045240 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -1112,6 +1112,7 @@ static struct transport_vtable builtin_smart_vtable = {
> struct transport *transport_get(struct remote *remote, const char *url)
> {
> const char *helper;
> + const char *p;
> struct transport *ret = xcalloc(1, sizeof(*ret));
>
> ret->progress = isatty(2);
> @@ -1127,19 +1128,15 @@ struct transport *transport_get(struct remote *remote, const char *url)
> ret->remote = remote;
> helper = remote->foreign_vcs;
>
> - if (!url && remote->url.nr)
> + if (!url)
> url = remote->url.v[0];
> ret->url = url;
>
> - /* maybe it is a foreign URL? */
> - if (url) {
> - const char *p = url;
> -
> - while (is_urlschemechar(p == url, *p))
> - p++;
> - if (starts_with(p, "::"))
> - helper = xstrndup(url, p - url);
> - }
> + p = url;
> + while (is_urlschemechar(p == url, *p))
> + p++;
> + if (starts_with(p, "::"))
> + helper = xstrndup(url, p - url);
>
> if (helper) {
> transport_helper_init(ret, helper);
> --
> 2.45.2.937.g0bcb3c087a
So, after reading the first 8 patches, I only kinda skimmed 9 and 10,
thinking "I don't really care about these remote helper things and
don't have an opinion on them -- besides, I'm sure Peff is picking
something reasonable", but I'm always a fan of code simplifications
like this patch. It makes it tempting to go back and read those last
two patches a little closer. Almost tempting enough, in fact. ;-)
next prev parent reply other threads:[~2024-06-25 17:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-09 6:51 Cannot override `remote.origin.url` with `-c` option Mathew George
2024-06-11 7:51 ` Jeff King
2024-06-11 15:28 ` Junio C Hamano
2024-06-13 10:24 ` Jeff King
2024-06-14 10:24 ` [PATCH 0/11] allow overriding remote.*.url Jeff King
2024-06-14 10:25 ` [PATCH 01/11] archive: fix check for missing url Jeff King
2024-06-14 10:26 ` [PATCH 02/11] remote: refactor alias_url() memory ownership Jeff King
2024-06-14 17:05 ` Junio C Hamano
2024-06-14 10:27 ` [PATCH 03/11] remote: transfer ownership of memory in add_url(), etc Jeff King
2024-06-14 17:04 ` Junio C Hamano
2024-06-16 4:59 ` Jeff King
2024-06-17 17:42 ` Junio C Hamano
2024-06-25 17:30 ` Elijah Newren
2024-06-14 10:28 ` [PATCH 04/11] remote: use strvecs to store remote url/pushurl Jeff King
2024-06-25 17:32 ` Elijah Newren
2024-06-14 10:29 ` [PATCH 05/11] remote: simplify url/pushurl selection Jeff King
2024-06-25 17:33 ` Elijah Newren
2024-06-14 10:30 ` [PATCH 06/11] config: document remote.*.url/pushurl interaction Jeff King
2024-06-25 17:34 ` Elijah Newren
2024-06-14 10:31 ` [PATCH 07/11] remote: allow resetting url list Jeff King
2024-06-25 17:35 ` Elijah Newren
2024-06-14 10:31 ` [PATCH 08/11] t5801: make remote-testgit GIT_DIR setup more robust Jeff King
2024-06-25 17:36 ` Elijah Newren
2024-06-14 10:34 ` [PATCH 09/11] t5801: test remote.*.vcs config Jeff King
2024-06-14 10:37 ` [PATCH 10/11] remote: always require at least one url in a remote Jeff King
2024-06-14 10:42 ` [PATCH 11/11] remote: drop checks for zero-url case Jeff King
2024-06-25 17:37 ` Elijah Newren [this message]
2024-06-25 17:44 ` [PATCH 0/11] allow overriding remote.*.url Elijah Newren
2024-06-26 20:40 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABPp-BHdVp+4s7QN0xiXFzoimtDwMPbb4Gw=Kb5MsBoY+SNLvA@mail.gmail.com' \
--to=newren@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mathewegeorge@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).