Skip to content

Commit ca46310

Browse files
committed
Merge branch 'jk/remote-wo-url'
Memory ownership rules for the in-core representation of remote.*.url configuration values have been straightened out, which resulted in a few leak fixes and code clarification. * jk/remote-wo-url: remote: drop checks for zero-url case remote: always require at least one url in a remote t5801: test remote.*.vcs config t5801: make remote-testgit GIT_DIR setup more robust remote: allow resetting url list config: document remote.*.url/pushurl interaction remote: simplify url/pushurl selection remote: use strvecs to store remote url/pushurl remote: transfer ownership of memory in add_url(), etc remote: refactor alias_url() memory ownership archive: fix check for missing url
2 parents 24cbd29 + aecd794 commit ca46310

15 files changed

+174
-162
lines changed

Documentation/config/remote.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ remote.pushDefault::
55

66
remote.<name>.url::
77
The URL of a remote repository. See linkgit:git-fetch[1] or
8-
linkgit:git-push[1].
8+
linkgit:git-push[1]. A configured remote can have multiple URLs;
9+
in this case the first is used for fetching, and all are used
10+
for pushing (assuming no `remote.<name>.pushurl` is defined).
11+
Setting this key to the empty string clears the list of urls,
12+
allowing you to override earlier config.
913

1014
remote.<name>.pushurl::
1115
The push URL of a remote repository. See linkgit:git-push[1].
16+
If a `pushurl` option is present in a configured remote, it
17+
is used for pushing instead of `remote.<name>.url`. A configured
18+
remote can have multiple push URLs; in this case a push goes to
19+
all of them. Setting this key to the empty string clears the
20+
list of urls, allowing you to override earlier config.
1221

1322
remote.<name>.proxy::
1423
For remotes that require curl (http, https and ftp), the URL to

builtin/archive.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ static int run_remote_archiver(int argc, const char **argv,
3131
struct packet_reader reader;
3232

3333
_remote = remote_get(remote);
34-
if (!_remote->url[0])
35-
die(_("git archive: Remote with no URL"));
36-
transport = transport_get(_remote, _remote->url[0]);
34+
transport = transport_get(_remote, _remote->url.v[0]);
3735
transport_connect(transport, "git-upload-archive", exec, fd);
3836

3937
/*

builtin/clone.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12941294
refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix,
12951295
branch_top.buf);
12961296

1297-
path = get_repo_path(remote->url[0], &is_bundle);
1297+
path = get_repo_path(remote->url.v[0], &is_bundle);
12981298
is_local = option_local != 0 && path && !is_bundle;
12991299
if (is_local) {
13001300
if (option_depth)
@@ -1316,7 +1316,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
13161316
if (option_local > 0 && !is_local)
13171317
warning(_("--local is ignored"));
13181318

1319-
transport = transport_get(remote, path ? path : remote->url[0]);
1319+
transport = transport_get(remote, path ? path : remote->url.v[0]);
13201320
transport_set_verbosity(transport, option_verbosity, option_progress);
13211321
transport->family = family;
13221322
transport->cloning = 1;

builtin/ls-remote.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
112112
die("bad repository '%s'", dest);
113113
die("No remote configured to list refs from.");
114114
}
115-
if (!remote->url_nr)
116-
die("remote %s has no configured URL", dest);
117115

118116
if (get_url) {
119-
printf("%s\n", *remote->url);
117+
printf("%s\n", remote->url.v[0]);
120118
return 0;
121119
}
122120

@@ -133,7 +131,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
133131
}
134132

135133
if (!dest && !quiet)
136-
fprintf(stderr, "From %s\n", *remote->url);
134+
fprintf(stderr, "From %s\n", remote->url.v[0]);
137135
for ( ; ref; ref = ref->next) {
138136
struct ref_array_item *item;
139137
if (!check_ref_type(ref, flags))

builtin/push.c

+4-24
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ static void set_refspecs(const char **refs, int nr, const char *repo)
141141
free_refs(local_refs);
142142
}
143143

144-
static int push_url_of_remote(struct remote *remote, const char ***url_p)
145-
{
146-
if (remote->pushurl_nr) {
147-
*url_p = remote->pushurl;
148-
return remote->pushurl_nr;
149-
}
150-
*url_p = remote->url;
151-
return remote->url_nr;
152-
}
153-
154144
static NORETURN void die_push_simple(struct branch *branch,
155145
struct remote *remote)
156146
{
@@ -434,8 +424,7 @@ static int do_push(int flags,
434424
struct remote *remote)
435425
{
436426
int i, errs;
437-
const char **url;
438-
int url_nr;
427+
struct strvec *url;
439428
struct refspec *push_refspec = &rs;
440429

441430
if (push_options->nr)
@@ -448,19 +437,10 @@ static int do_push(int flags,
448437
setup_default_push_refspecs(&flags, remote);
449438
}
450439
errs = 0;
451-
url_nr = push_url_of_remote(remote, &url);
452-
if (url_nr) {
453-
for (i = 0; i < url_nr; i++) {
454-
struct transport *transport =
455-
transport_get(remote, url[i]);
456-
if (flags & TRANSPORT_PUSH_OPTIONS)
457-
transport->push_options = push_options;
458-
if (push_with_options(transport, push_refspec, flags))
459-
errs++;
460-
}
461-
} else {
440+
url = push_url_of_remote(remote);
441+
for (i = 0; i < url->nr; i++) {
462442
struct transport *transport =
463-
transport_get(remote, NULL);
443+
transport_get(remote, url->v[i]);
464444
if (flags & TRANSPORT_PUSH_OPTIONS)
465445
transport->push_options = push_options;
466446
if (push_with_options(transport, push_refspec, flags))

builtin/remote.c

+26-62
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ static int migrate_file(struct remote *remote)
619619
int i;
620620

621621
strbuf_addf(&buf, "remote.%s.url", remote->name);
622-
for (i = 0; i < remote->url_nr; i++)
623-
git_config_set_multivar(buf.buf, remote->url[i], "^$", 0);
622+
for (i = 0; i < remote->url.nr; i++)
623+
git_config_set_multivar(buf.buf, remote->url.v[i], "^$", 0);
624624
strbuf_reset(&buf);
625625
strbuf_addf(&buf, "remote.%s.push", remote->name);
626626
for (i = 0; i < remote->push.raw_nr; i++)
@@ -1002,8 +1002,7 @@ static int get_remote_ref_states(const char *name,
10021002
struct transport *transport;
10031003
const struct ref *remote_refs;
10041004

1005-
transport = transport_get(states->remote, states->remote->url_nr > 0 ?
1006-
states->remote->url[0] : NULL);
1005+
transport = transport_get(states->remote, states->remote->url.v[0]);
10071006
remote_refs = transport_get_remote_refs(transport, NULL);
10081007

10091008
states->queried = 1;
@@ -1213,15 +1212,15 @@ static int get_one_entry(struct remote *remote, void *priv)
12131212
{
12141213
struct string_list *list = priv;
12151214
struct strbuf remote_info_buf = STRBUF_INIT;
1216-
const char **url;
1217-
int i, url_nr;
1215+
struct strvec *url;
1216+
int i;
12181217

1219-
if (remote->url_nr > 0) {
1218+
if (remote->url.nr > 0) {
12201219
struct strbuf promisor_config = STRBUF_INIT;
12211220
const char *partial_clone_filter = NULL;
12221221

12231222
strbuf_addf(&promisor_config, "remote.%s.partialclonefilter", remote->name);
1224-
strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url[0]);
1223+
strbuf_addf(&remote_info_buf, "%s (fetch)", remote->url.v[0]);
12251224
if (!git_config_get_string_tmp(promisor_config.buf, &partial_clone_filter))
12261225
strbuf_addf(&remote_info_buf, " [%s]", partial_clone_filter);
12271226

@@ -1230,16 +1229,10 @@ static int get_one_entry(struct remote *remote, void *priv)
12301229
strbuf_detach(&remote_info_buf, NULL);
12311230
} else
12321231
string_list_append(list, remote->name)->util = NULL;
1233-
if (remote->pushurl_nr) {
1234-
url = remote->pushurl;
1235-
url_nr = remote->pushurl_nr;
1236-
} else {
1237-
url = remote->url;
1238-
url_nr = remote->url_nr;
1239-
}
1240-
for (i = 0; i < url_nr; i++)
1232+
url = push_url_of_remote(remote);
1233+
for (i = 0; i < url->nr; i++)
12411234
{
1242-
strbuf_addf(&remote_info_buf, "%s (push)", url[i]);
1235+
strbuf_addf(&remote_info_buf, "%s (push)", url->v[i]);
12431236
string_list_append(list, remote->name)->util =
12441237
strbuf_detach(&remote_info_buf, NULL);
12451238
}
@@ -1295,28 +1288,20 @@ static int show(int argc, const char **argv, const char *prefix)
12951288

12961289
for (; argc; argc--, argv++) {
12971290
int i;
1298-
const char **url;
1299-
int url_nr;
1291+
struct strvec *url;
13001292

13011293
get_remote_ref_states(*argv, &info.states, query_flag);
13021294

13031295
printf_ln(_("* remote %s"), *argv);
1304-
printf_ln(_(" Fetch URL: %s"), info.states.remote->url_nr > 0 ?
1305-
info.states.remote->url[0] : _("(no URL)"));
1306-
if (info.states.remote->pushurl_nr) {
1307-
url = info.states.remote->pushurl;
1308-
url_nr = info.states.remote->pushurl_nr;
1309-
} else {
1310-
url = info.states.remote->url;
1311-
url_nr = info.states.remote->url_nr;
1312-
}
1313-
for (i = 0; i < url_nr; i++)
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++)
13141299
/*
13151300
* TRANSLATORS: the colon ':' should align
13161301
* with the one in " Fetch URL: %s"
13171302
* translation.
13181303
*/
1319-
printf_ln(_(" Push URL: %s"), url[i]);
1304+
printf_ln(_(" Push URL: %s"), url->v[i]);
13201305
if (!i)
13211306
printf_ln(_(" Push URL: %s"), _("(no URL)"));
13221307
if (no_query)
@@ -1453,10 +1438,7 @@ static int prune_remote(const char *remote, int dry_run)
14531438
}
14541439

14551440
printf_ln(_("Pruning %s"), remote);
1456-
printf_ln(_("URL: %s"),
1457-
states.remote->url_nr
1458-
? states.remote->url[0]
1459-
: _("(no URL)"));
1441+
printf_ln(_("URL: %s"), states.remote->url.v[0]);
14601442

14611443
for_each_string_list_item(item, &states.stale)
14621444
string_list_append(&refs_to_prune, item->util);
@@ -1622,8 +1604,7 @@ static int get_url(int argc, const char **argv, const char *prefix)
16221604
int i, push_mode = 0, all_mode = 0;
16231605
const char *remotename = NULL;
16241606
struct remote *remote;
1625-
const char **url;
1626-
int url_nr;
1607+
struct strvec *url;
16271608
struct option options[] = {
16281609
OPT_BOOL('\0', "push", &push_mode,
16291610
N_("query push URLs rather than fetch URLs")),
@@ -1645,27 +1626,13 @@ static int get_url(int argc, const char **argv, const char *prefix)
16451626
exit(2);
16461627
}
16471628

1648-
url_nr = 0;
1649-
if (push_mode) {
1650-
url = remote->pushurl;
1651-
url_nr = remote->pushurl_nr;
1652-
}
1653-
/* else fetch mode */
1654-
1655-
/* Use the fetch URL when no push URLs were found or requested. */
1656-
if (!url_nr) {
1657-
url = remote->url;
1658-
url_nr = remote->url_nr;
1659-
}
1660-
1661-
if (!url_nr)
1662-
die(_("no URLs configured for remote '%s'"), remotename);
1629+
url = push_mode ? push_url_of_remote(remote) : &remote->url;
16631630

16641631
if (all_mode) {
1665-
for (i = 0; i < url_nr; i++)
1666-
printf_ln("%s", url[i]);
1632+
for (i = 0; i < url->nr; i++)
1633+
printf_ln("%s", url->v[i]);
16671634
} else {
1668-
printf_ln("%s", *url);
1635+
printf_ln("%s", url->v[0]);
16691636
}
16701637

16711638
return 0;
@@ -1680,8 +1647,7 @@ static int set_url(int argc, const char **argv, const char *prefix)
16801647
const char *oldurl = NULL;
16811648
struct remote *remote;
16821649
regex_t old_regex;
1683-
const char **urlset;
1684-
int urlset_nr;
1650+
struct strvec *urlset;
16851651
struct strbuf name_buf = STRBUF_INIT;
16861652
struct option options[] = {
16871653
OPT_BOOL('\0', "push", &push_mode,
@@ -1718,12 +1684,10 @@ static int set_url(int argc, const char **argv, const char *prefix)
17181684

17191685
if (push_mode) {
17201686
strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
1721-
urlset = remote->pushurl;
1722-
urlset_nr = remote->pushurl_nr;
1687+
urlset = &remote->pushurl;
17231688
} else {
17241689
strbuf_addf(&name_buf, "remote.%s.url", remotename);
1725-
urlset = remote->url;
1726-
urlset_nr = remote->url_nr;
1690+
urlset = &remote->url;
17271691
}
17281692

17291693
/* Special cases that add new entry. */
@@ -1740,8 +1704,8 @@ static int set_url(int argc, const char **argv, const char *prefix)
17401704
if (regcomp(&old_regex, oldurl, REG_EXTENDED))
17411705
die(_("Invalid old URL pattern: %s"), oldurl);
17421706

1743-
for (i = 0; i < urlset_nr; i++)
1744-
if (!regexec(&old_regex, urlset[i], 0, NULL, 0))
1707+
for (i = 0; i < urlset->nr; i++)
1708+
if (!regexec(&old_regex, urlset->v[i], 0, NULL, 0))
17451709
matches++;
17461710
else
17471711
negative_matches++;

remote-curl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ int cmd_main(int argc, const char **argv)
15761576
if (argc > 2) {
15771577
end_url_with_slash(&url, argv[2]);
15781578
} else {
1579-
end_url_with_slash(&url, remote->url[0]);
1579+
end_url_with_slash(&url, remote->url.v[0]);
15801580
}
15811581

15821582
http_init(remote, url.buf, 0);

0 commit comments

Comments
 (0)