Skip to content

Commit deba493

Browse files
peffgitster
authored andcommitted
http_init: accept separate URL parameter
The http_init function takes a "struct remote". Part of its initialization procedure is to look at the remote's url and grab some auth-related parameters. However, using the url included in the remote is: - wrong; the remote-curl helper may have a separate, unrelated URL (e.g., from remote.*.pushurl). Looking at the remote's configured url is incorrect. - incomplete; http-fetch doesn't have a remote, so passes NULL. So http_init never gets to see the URL we are actually going to use. - cumbersome; http-push has a similar problem to http-fetch, but actually builds a fake remote just to pass in the URL. Instead, let's just add a separate URL parameter to http_init, and all three callsites can pass in the appropriate information. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 070b4dd commit deba493

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

http-fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main(int argc, const char **argv)
6363

6464
git_config(git_default_config, NULL);
6565

66-
http_init(NULL);
66+
http_init(NULL, url);
6767
walker = get_http_walker(url);
6868
walker->get_tree = get_tree;
6969
walker->get_history = get_history;

http-push.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,6 @@ int main(int argc, char **argv)
17471747
int i;
17481748
int new_refs;
17491749
struct ref *ref, *local_refs;
1750-
struct remote *remote;
17511750

17521751
git_extract_argv0_path(argv[0]);
17531752

@@ -1821,14 +1820,7 @@ int main(int argc, char **argv)
18211820

18221821
memset(remote_dir_exists, -1, 256);
18231822

1824-
/*
1825-
* Create a minimum remote by hand to give to http_init(),
1826-
* primarily to allow it to look at the URL.
1827-
*/
1828-
remote = xcalloc(sizeof(*remote), 1);
1829-
ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc);
1830-
remote->url[remote->url_nr++] = repo->url;
1831-
http_init(remote);
1823+
http_init(NULL, repo->url);
18321824

18331825
#ifdef USE_CURL_MULTI
18341826
is_running_queue = 0;

http.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static void set_from_env(const char **var, const char *envname)
369369
*var = val;
370370
}
371371

372-
void http_init(struct remote *remote)
372+
void http_init(struct remote *remote, const char *url)
373373
{
374374
char *low_speed_limit;
375375
char *low_speed_time;
@@ -433,11 +433,11 @@ void http_init(struct remote *remote)
433433
if (getenv("GIT_CURL_FTP_NO_EPSV"))
434434
curl_ftp_no_epsv = 1;
435435

436-
if (remote && remote->url && remote->url[0]) {
437-
http_auth_init(remote->url[0]);
436+
if (url) {
437+
http_auth_init(url);
438438
if (!ssl_cert_password_required &&
439439
getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") &&
440-
!prefixcmp(remote->url[0], "https://"))
440+
!prefixcmp(url, "https://"))
441441
ssl_cert_password_required = 1;
442442
}
443443

http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extern void add_fill_function(void *data, int (*fill)(void *));
8686
extern void step_active_slots(void);
8787
#endif
8888

89-
extern void http_init(struct remote *remote);
89+
extern void http_init(struct remote *remote, const char *url);
9090
extern void http_cleanup(void);
9191

9292
extern int data_received;

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ int main(int argc, const char **argv)
850850

851851
url = strbuf_detach(&buf, NULL);
852852

853-
http_init(remote);
853+
http_init(remote, url);
854854

855855
do {
856856
if (strbuf_getline(&buf, stdin, '\n') == EOF)

0 commit comments

Comments
 (0)