Skip to content

Commit 55d354d

Browse files
authored
Merge pull request libgit2#4785 from tiennou/fix/cleanup-remote
remote: store the connection data in a private struct
2 parents db17b31 + 1c17688 commit 55d354d

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

src/push.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ int git_push_set_options(git_push *push, const git_push_options *opts)
7373
GITERR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options");
7474

7575
push->pb_parallelism = opts->pb_parallelism;
76-
push->custom_headers = &opts->custom_headers;
76+
push->connection.custom_headers = &opts->custom_headers;
77+
push->connection.proxy = &opts->proxy_opts;
7778

7879
return 0;
7980
}
@@ -475,7 +476,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
475476
int error;
476477

477478
if (!git_remote_connected(push->remote) &&
478-
(error = git_remote_connect(push->remote, GIT_DIRECTION_PUSH, callbacks, NULL, push->custom_headers)) < 0)
479+
(error = git_remote__connect(push->remote, GIT_DIRECTION_PUSH, callbacks, &push->connection)) < 0)
479480
return error;
480481

481482
if ((error = filter_refs(push->remote)) < 0 ||

src/push.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "git2.h"
1313
#include "refspec.h"
14+
#include "remote.h"
1415

1516
typedef struct push_spec {
1617
struct git_refspec refspec;
@@ -40,7 +41,7 @@ struct git_push {
4041

4142
/* options */
4243
unsigned pb_parallelism;
43-
const git_strarray *custom_headers;
44+
git_remote_connection_opts connection;
4445
};
4546

4647
/**

src/remote.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ static int set_transport_custom_headers(git_transport *t, const git_strarray *cu
657657
return t->set_custom_headers(t, custom_headers);
658658
}
659659

660-
int git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_proxy_options *proxy, const git_strarray *custom_headers)
660+
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn)
661661
{
662662
git_transport *t;
663663
const char *url;
@@ -676,8 +676,8 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
676676
payload = callbacks->payload;
677677
}
678678

679-
if (proxy)
680-
GITERR_CHECK_VERSION(proxy, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
679+
if (conn->proxy)
680+
GITERR_CHECK_VERSION(conn->proxy, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
681681

682682
t = remote->transport;
683683

@@ -701,11 +701,11 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
701701
if (!t && (error = git_transport_new(&t, remote, url)) < 0)
702702
return error;
703703

704-
if ((error = set_transport_custom_headers(t, custom_headers)) != 0)
704+
if ((error = set_transport_custom_headers(t, conn->custom_headers)) != 0)
705705
goto on_error;
706706

707707
if ((error = set_transport_callbacks(t, callbacks)) < 0 ||
708-
(error = t->connect(t, url, credentials, payload, proxy, direction, flags)) != 0)
708+
(error = t->connect(t, url, credentials, payload, conn->proxy, direction, flags)) != 0)
709709
goto on_error;
710710

711711
remote->transport = t;
@@ -721,6 +721,16 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
721721
return error;
722722
}
723723

724+
int git_remote_connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_proxy_options *proxy, const git_strarray *custom_headers)
725+
{
726+
git_remote_connection_opts conn;
727+
728+
conn.proxy = proxy;
729+
conn.custom_headers = custom_headers;
730+
731+
return git_remote__connect(remote, direction, callbacks, &conn);
732+
}
733+
724734
int git_remote_ls(const git_remote_head ***out, size_t *size, git_remote *remote)
725735
{
726736
assert(remote);
@@ -949,21 +959,20 @@ int git_remote_fetch(
949959
bool prune = false;
950960
git_buf reflog_msg_buf = GIT_BUF_INIT;
951961
const git_remote_callbacks *cbs = NULL;
952-
const git_strarray *custom_headers = NULL;
953-
const git_proxy_options *proxy = NULL;
962+
git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
954963

955964
if (opts) {
956965
GITERR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
957966
cbs = &opts->callbacks;
958-
custom_headers = &opts->custom_headers;
967+
conn.custom_headers = &opts->custom_headers;
959968
update_fetchhead = opts->update_fetchhead;
960969
tagopt = opts->download_tags;
961970
GITERR_CHECK_VERSION(&opts->proxy_opts, GIT_PROXY_OPTIONS_VERSION, "git_proxy_options");
962-
proxy = &opts->proxy_opts;
971+
conn.proxy = &opts->proxy_opts;
963972
}
964973

965974
/* Connect and download everything */
966-
if ((error = git_remote_connect(remote, GIT_DIRECTION_FETCH, cbs, proxy, custom_headers)) != 0)
975+
if ((error = git_remote__connect(remote, GIT_DIRECTION_FETCH, cbs, &conn)) != 0)
967976
return error;
968977

969978
error = git_remote_download(remote, refspecs, opts);
@@ -2373,8 +2382,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
23732382
git_push *push;
23742383
git_refspec *spec;
23752384
const git_remote_callbacks *cbs = NULL;
2376-
const git_strarray *custom_headers = NULL;
2377-
const git_proxy_options *proxy = NULL;
2385+
git_remote_connection_opts conn = GIT_REMOTE_CONNECTION_OPTIONS_INIT;
23782386

23792387
assert(remote);
23802388

@@ -2385,12 +2393,12 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
23852393

23862394
if (opts) {
23872395
cbs = &opts->callbacks;
2388-
custom_headers = &opts->custom_headers;
2389-
proxy = &opts->proxy_opts;
2396+
conn.custom_headers = &opts->custom_headers;
2397+
conn.proxy = &opts->proxy_opts;
23902398
}
23912399

23922400
if (!git_remote_connected(remote) &&
2393-
(error = git_remote_connect(remote, GIT_DIRECTION_PUSH, cbs, proxy, custom_headers)) < 0)
2401+
(error = git_remote__connect(remote, GIT_DIRECTION_PUSH, cbs, &conn)) < 0)
23942402
goto cleanup;
23952403

23962404
free_refspecs(&remote->active_refspecs);

src/remote.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ struct git_remote {
3636
int passed_refspecs;
3737
};
3838

39+
typedef struct git_remote_connection_opts {
40+
const git_strarray *custom_headers;
41+
const git_proxy_options *proxy;
42+
} git_remote_connection_opts;
43+
44+
#define GIT_REMOTE_CONNECTION_OPTIONS_INIT { NULL, NULL }
45+
46+
int git_remote__connect(git_remote *remote, git_direction direction, const git_remote_callbacks *callbacks, const git_remote_connection_opts *conn);
47+
3948
const char* git_remote__urlfordirection(struct git_remote *remote, int direction);
4049
int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url);
4150

0 commit comments

Comments
 (0)