remote: drop checks for zero-url case
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. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 14, 2024 at 06:42 UTC
aecd794fca275b42e271b80236e95f0d288bd709
6 files changed
+12
-37
builtin/archive.c
-2
@@ -31,8 +31,6 @@ static int run_remote_archiver(int argc, const char **argv,
31
struct packet_reader reader;
32
33
_remote = remote_get(remote);
34
- if (!_remote->url.nr)
35
- die(_("git archive: Remote with no URL"));
34
transport = transport_get(_remote, _remote->url.v[0]);
35
transport_connect(transport, "git-upload-archive", exec, fd);
36
builtin/ls-remote.c
-2
@@ -109,8 +109,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
109
die("bad repository '%s'", dest);
110
die("No remote configured to list refs from.");
111
}
112
- if (!remote->url.nr)
113
- die("remote %s has no configured URL", dest);
112
113
if (get_url) {
114
printf("%s\n", remote->url.v[0]);
builtin/push.c
+2
-11
@@ -438,18 +438,9 @@ static int do_push(int flags,
438
}
439
errs = 0;
440
url = push_url_of_remote(remote);
441
- if (url->nr) {
442
- for (i = 0; i < url->nr; i++) {
443
- struct transport *transport =
444
- transport_get(remote, url->v[i]);
445
- if (flags & TRANSPORT_PUSH_OPTIONS)
446
- transport->push_options = push_options;
447
- if (push_with_options(transport, push_refspec, flags))
448
- errs++;
449
- }
450
- } else {
441
+ for (i = 0; i < url->nr; i++) {
442
struct transport *transport =
452
- transport_get(remote, NULL);
443
+ transport_get(remote, url->v[i]);
444
if (flags & TRANSPORT_PUSH_OPTIONS)
445
transport->push_options = push_options;
446
if (push_with_options(transport, push_refspec, flags))
builtin/remote.c
+3
-10
@@ -1002,8 +1002,7 @@ static int get_remote_ref_states(const char *name,
1002
struct transport *transport;
1003
const struct ref *remote_refs;
1004
1005
- transport = transport_get(states->remote, states->remote->url.nr > 0 ?
1006
- states->remote->url.v[0] : NULL);
1005
+ transport = transport_get(states->remote, states->remote->url.v[0]);
1006
remote_refs = transport_get_remote_refs(transport, NULL);
1007
1008
states->queried = 1;
@@ -1294,8 +1293,7 @@ static int show(int argc, const char **argv, const char *prefix)
1293
get_remote_ref_states(*argv, &info.states, query_flag);
1294
1295
printf_ln(_("* remote %s"), *argv);
1297
- printf_ln(_(" Fetch URL: %s"), info.states.remote->url.nr > 0 ?
1298
- info.states.remote->url.v[0] : _("(no URL)"));
1296
+ printf_ln(_(" Fetch URL: %s"), info.states.remote->url.v[0]);
1297
url = push_url_of_remote(info.states.remote);
1298
for (i = 0; i < url->nr; i++)
1299
/*
@@ -1440,10 +1438,7 @@ static int prune_remote(const char *remote, int dry_run)
1438
}
1439
1440
printf_ln(_("Pruning %s"), remote);
1443
- printf_ln(_("URL: %s"),
1444
- states.remote->url.nr
1445
- ? states.remote->url.v[0]
1446
- : _("(no URL)"));
1441
+ printf_ln(_("URL: %s"), states.remote->url.v[0]);
1442
1443
for_each_string_list_item(item, &states.stale)
1444
string_list_append(&refs_to_prune, item->util);
@@ -1632,8 +1627,6 @@ static int get_url(int argc, const char **argv, const char *prefix)
1627
}
1628
1629
url = push_mode ? push_url_of_remote(remote) : &remote->url;
1635
- if (!url->nr)
1636
- die(_("no URLs configured for remote '%s'"), remotename);
1630
1631
if (all_mode) {
1632
for (i = 0; i < url->nr; i++)
t/helper/test-bundle-uri.c
-2
@@ -88,8 +88,6 @@ static int cmd_ls_remote(int argc, const char **argv)
88
die(_("bad repository '%s'"), dest);
89
die(_("no remote configured to get bundle URIs from"));
90
}
91
- if (!remote->url.nr)
92
- die(_("remote '%s' has no configured URL"), dest);
91
92
transport = transport_get(remote, NULL);
93
if (transport_get_remote_bundle_uri(transport) < 0) {
transport.c
+7
-10
@@ -1112,6 +1112,7 @@ static struct transport_vtable builtin_smart_vtable = {
1112
struct transport *transport_get(struct remote *remote, const char *url)
1113
{
1114
const char *helper;
1115
+ const char *p;
1116
struct transport *ret = xcalloc(1, sizeof(*ret));
1117
1118
ret->progress = isatty(2);
@@ -1127,19 +1128,15 @@ struct transport *transport_get(struct remote *remote, const char *url)
1128
ret->remote = remote;
1129
helper = remote->foreign_vcs;
1130
1130
- if (!url && remote->url.nr)
1131
+ if (!url)
1132
url = remote->url.v[0];
1133
ret->url = url;
1134
1134
- /* maybe it is a foreign URL? */
1135
- if (url) {
1136
- const char *p = url;
1137
-
1138
- while (is_urlschemechar(p == url, *p))
1139
- p++;
1140
- if (starts_with(p, "::"))
1141
- helper = xstrndup(url, p - url);
1142
- }
1135
+ p = url;
1136
+ while (is_urlschemechar(p == url, *p))
1137
+ p++;
1138
+ if (starts_with(p, "::"))
1139
+ helper = xstrndup(url, p - url);
1140
1141
if (helper) {
1142
transport_helper_init(ret, helper);