diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-08-27 11:25:51 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-08-29 10:39:28 -0400 |
commit | 7442c000d95faffd9a2f44d5822101525eb8d0d9 (patch) | |
tree | 97447e6b56be4c260d4960fef8d60d9750ec82c4 | |
parent | 72df17c659619707e4e5f27b2a51db60848a1d04 (diff) | |
download | libgit2-7442c000d95faffd9a2f44d5822101525eb8d0d9.tar.gz |
remote: deprecate resolve_url callbackethomson/custom_url
Using a callback to set a resolve_url is not particularly idiomatic.
Deprecate it in favor of the `set_instance_url` and
`set_instance_pushurl` functions which can now be called from the
`git_remote_ready_cb` callback.
-rw-r--r-- | include/git2/remote.h | 10 | ||||
-rw-r--r-- | src/remote.c | 19 | ||||
-rw-r--r-- | tests/network/remote/remotes.c | 8 |
3 files changed, 34 insertions, 3 deletions
diff --git a/include/git2/remote.h b/include/git2/remote.h index b75a9911c..1f52fcd94 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -499,6 +499,7 @@ typedef int GIT_CALLBACK(git_push_negotiation)(const git_push_update **updates, */ typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data); +#ifndef GIT_DEPRECATE_HARD /** * Callback to resolve URLs before connecting to remote * @@ -510,8 +511,10 @@ typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, cons * @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH * @param payload Payload provided by the caller * @return 0 on success, GIT_PASSTHROUGH or an error + * @deprecated Use `git_remote_set_instance_url` */ typedef int GIT_CALLBACK(git_url_resolve_cb)(git_buf *url_resolved, const char *url, int direction, void *payload); +#endif /** * Callback invoked immediately before we attempt to connect to the @@ -620,11 +623,18 @@ struct git_remote_callbacks { */ void *payload; +#ifdef GIT_DEPRECATE_HARD + void *reserved; +#else /** * Resolve URL before connecting to remote. * The returned URL will be used to connect to the remote instead. + * + * This callback is deprecated; users should use + * git_remote_ready_cb and configure the instance URL instead. */ git_url_resolve_cb resolve_url; +#endif }; #define GIT_REMOTE_CALLBACKS_VERSION 1 diff --git a/src/remote.c b/src/remote.c index 8050e65f3..73375b352 100644 --- a/src/remote.c +++ b/src/remote.c @@ -682,8 +682,16 @@ int git_remote_set_pushurl(git_repository *repo, const char *remote, const char* return set_url(repo, remote, CONFIG_PUSHURL_FMT, url); } -static int resolve_url(git_buf *resolved_url, const char *url, int direction, const git_remote_callbacks *callbacks) -{ +static int resolve_url( + git_buf *resolved_url, + const char *url, + int direction, + const git_remote_callbacks *callbacks) +{ +#ifdef GIT_DEPRECATE_HARD + GIT_UNUSED(direction); + GIT_UNUSED(callbacks); +#else int status, error; if (callbacks && callbacks->resolve_url) { @@ -698,11 +706,16 @@ static int resolve_url(git_buf *resolved_url, const char *url, int direction, co return status; } } +#endif return git_buf_sets(resolved_url, url); } -int git_remote__urlfordirection(git_buf *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks) +int git_remote__urlfordirection( + git_buf *url_out, + struct git_remote *remote, + int direction, + const git_remote_callbacks *callbacks) { const char *url = NULL; diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c index 4a9f5ae72..ed6a89075 100644 --- a/tests/network/remote/remotes.c +++ b/tests/network/remote/remotes.c @@ -98,6 +98,7 @@ void test_network_remote_remotes__remote_ready(void) git_buf_dispose(&url); } +#ifndef GIT_DEPRECATE_HARD static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload) { cl_assert(strcmp(url, "git://github.com/libgit2/libgit2") == 0); @@ -111,9 +112,11 @@ static int urlresolve_callback(git_buf *url_resolved, const char *url, int direc return GIT_OK; } +#endif void test_network_remote_remotes__urlresolve(void) { +#ifndef GIT_DEPRECATE_HARD git_buf url = GIT_BUF_INIT; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; @@ -131,8 +134,10 @@ void test_network_remote_remotes__urlresolve(void) cl_assert_equal_s(url.ptr, "pushresolve"); git_buf_dispose(&url); +#endif } +#ifndef GIT_DEPRECATE_HARD static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *url, int direction, void *payload) { GIT_UNUSED(url_resolved); @@ -141,9 +146,11 @@ static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *ur GIT_UNUSED(payload); return GIT_PASSTHROUGH; } +#endif void test_network_remote_remotes__urlresolve_passthrough(void) { +#ifndef GIT_DEPRECATE_HARD git_buf url = GIT_BUF_INIT; const char *orig_url = "git://github.com/libgit2/libgit2"; @@ -161,6 +168,7 @@ void test_network_remote_remotes__urlresolve_passthrough(void) cl_assert_equal_s(url.ptr, orig_url); git_buf_dispose(&url); +#endif } void test_network_remote_remotes__instance_url(void) |