Skip to content

Commit 7442c00

Browse files
committed
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 parent 72df17c commit 7442c00

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

include/git2/remote.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ typedef int GIT_CALLBACK(git_push_negotiation)(const git_push_update **updates,
499499
*/
500500
typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, const char *status, void *data);
501501

502+
#ifndef GIT_DEPRECATE_HARD
502503
/**
503504
* Callback to resolve URLs before connecting to remote
504505
*
@@ -510,8 +511,10 @@ typedef int GIT_CALLBACK(git_push_update_reference_cb)(const char *refname, cons
510511
* @param direction GIT_DIRECTION_FETCH or GIT_DIRECTION_PUSH
511512
* @param payload Payload provided by the caller
512513
* @return 0 on success, GIT_PASSTHROUGH or an error
514+
* @deprecated Use `git_remote_set_instance_url`
513515
*/
514516
typedef int GIT_CALLBACK(git_url_resolve_cb)(git_buf *url_resolved, const char *url, int direction, void *payload);
517+
#endif
515518

516519
/**
517520
* Callback invoked immediately before we attempt to connect to the
@@ -620,11 +623,18 @@ struct git_remote_callbacks {
620623
*/
621624
void *payload;
622625

626+
#ifdef GIT_DEPRECATE_HARD
627+
void *reserved;
628+
#else
623629
/**
624630
* Resolve URL before connecting to remote.
625631
* The returned URL will be used to connect to the remote instead.
632+
*
633+
* This callback is deprecated; users should use
634+
* git_remote_ready_cb and configure the instance URL instead.
626635
*/
627636
git_url_resolve_cb resolve_url;
637+
#endif
628638
};
629639

630640
#define GIT_REMOTE_CALLBACKS_VERSION 1

src/remote.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,16 @@ int git_remote_set_pushurl(git_repository *repo, const char *remote, const char*
682682
return set_url(repo, remote, CONFIG_PUSHURL_FMT, url);
683683
}
684684

685-
static int resolve_url(git_buf *resolved_url, const char *url, int direction, const git_remote_callbacks *callbacks)
686-
{
685+
static int resolve_url(
686+
git_buf *resolved_url,
687+
const char *url,
688+
int direction,
689+
const git_remote_callbacks *callbacks)
690+
{
691+
#ifdef GIT_DEPRECATE_HARD
692+
GIT_UNUSED(direction);
693+
GIT_UNUSED(callbacks);
694+
#else
687695
int status, error;
688696

689697
if (callbacks && callbacks->resolve_url) {
@@ -698,11 +706,16 @@ static int resolve_url(git_buf *resolved_url, const char *url, int direction, co
698706
return status;
699707
}
700708
}
709+
#endif
701710

702711
return git_buf_sets(resolved_url, url);
703712
}
704713

705-
int git_remote__urlfordirection(git_buf *url_out, struct git_remote *remote, int direction, const git_remote_callbacks *callbacks)
714+
int git_remote__urlfordirection(
715+
git_buf *url_out,
716+
struct git_remote *remote,
717+
int direction,
718+
const git_remote_callbacks *callbacks)
706719
{
707720
const char *url = NULL;
708721

tests/network/remote/remotes.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void test_network_remote_remotes__remote_ready(void)
9898
git_buf_dispose(&url);
9999
}
100100

101+
#ifndef GIT_DEPRECATE_HARD
101102
static int urlresolve_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
102103
{
103104
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
111112

112113
return GIT_OK;
113114
}
115+
#endif
114116

115117
void test_network_remote_remotes__urlresolve(void)
116118
{
119+
#ifndef GIT_DEPRECATE_HARD
117120
git_buf url = GIT_BUF_INIT;
118121

119122
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
@@ -131,8 +134,10 @@ void test_network_remote_remotes__urlresolve(void)
131134
cl_assert_equal_s(url.ptr, "pushresolve");
132135

133136
git_buf_dispose(&url);
137+
#endif
134138
}
135139

140+
#ifndef GIT_DEPRECATE_HARD
136141
static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *url, int direction, void *payload)
137142
{
138143
GIT_UNUSED(url_resolved);
@@ -141,9 +146,11 @@ static int urlresolve_passthrough_callback(git_buf *url_resolved, const char *ur
141146
GIT_UNUSED(payload);
142147
return GIT_PASSTHROUGH;
143148
}
149+
#endif
144150

145151
void test_network_remote_remotes__urlresolve_passthrough(void)
146152
{
153+
#ifndef GIT_DEPRECATE_HARD
147154
git_buf url = GIT_BUF_INIT;
148155
const char *orig_url = "git://github.com/libgit2/libgit2";
149156

@@ -161,6 +168,7 @@ void test_network_remote_remotes__urlresolve_passthrough(void)
161168
cl_assert_equal_s(url.ptr, orig_url);
162169

163170
git_buf_dispose(&url);
171+
#endif
164172
}
165173

166174
void test_network_remote_remotes__instance_url(void)

0 commit comments

Comments
 (0)