remote: deprecate resolve_url callback 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
diff --git a/include/git2/remote.h b/include/git2/remote.h
index b75a991..1f52fcd 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 8050e65..73375b3 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 4a9f5ae..ed6a890 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)