summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-05-10 22:50:16 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-11 13:30:08 +0100
commit0e7ab1c4968629b8d42c193eebda48ef146d8e77 (patch)
treeff246ac9ddc5bef47d25a9d5b5da2e9402f02d64
parent2bbcdee6b666f34e83d1cf9ca9badc66258202d6 (diff)
downloadlibgit2-ethomson/update_tips_spec.tar.gz
remote: add git_refspec to update_tipsethomson/update_tips_spec
-rw-r--r--examples/fetch.c10
-rw-r--r--include/git2/remote.h7
-rw-r--r--src/libgit2/push.c6
-rw-r--r--src/libgit2/remote.c21
-rw-r--r--tests/libgit2/network/fetchlocal.c6
-rw-r--r--tests/libgit2/online/clone.c4
-rw-r--r--tests/libgit2/online/fetch.c8
-rw-r--r--tests/libgit2/online/push_util.c4
-rw-r--r--tests/libgit2/online/push_util.h2
-rw-r--r--tests/libgit2/submodule/update.c3
10 files changed, 46 insertions, 25 deletions
diff --git a/examples/fetch.c b/examples/fetch.c
index bbd882cfb..a7248edb6 100644
--- a/examples/fetch.c
+++ b/examples/fetch.c
@@ -13,20 +13,24 @@ static int progress_cb(const char *str, int len, void *data)
* updated. The message we output depends on whether it's a new one or
* an update.
*/
-static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
+static int update_cb(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *data)
{
char a_str[GIT_OID_SHA1_HEXSIZE+1], b_str[GIT_OID_SHA1_HEXSIZE+1];
+ git_buf remote_name;
(void)data;
+ if (git_refspec_rtransform(&remote_name, spec, refname) < 0)
+ return -1;
+
git_oid_fmt(b_str, b);
b_str[GIT_OID_SHA1_HEXSIZE] = '\0';
if (git_oid_is_zero(a)) {
- printf("[new] %.20s %s\n", b_str, refname);
+ printf("[new] %.20s %s -> %s\n", b_str, remote_name.ptr, refname);
} else {
git_oid_fmt(a_str, a);
a_str[GIT_OID_SHA1_HEXSIZE] = '\0';
- printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname);
+ printf("[updated] %.10s..%.10s %s -> %s\n", a_str, b_str, remote_name.ptr, refname);
}
return 0;
diff --git a/include/git2/remote.h b/include/git2/remote.h
index e9065b250..d1e41ff4d 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -557,7 +557,8 @@ struct git_remote_callbacks {
* Completion is called when different parts of the download
* process are done (currently unused).
*/
- int GIT_CALLBACK(completion)(git_remote_completion_t type, void *data);
+ int GIT_CALLBACK(completion)(git_remote_completion_t type,
+ void *data);
/**
* This will be called if the remote host requires
@@ -587,7 +588,9 @@ struct git_remote_callbacks {
* Each time a reference is updated locally, this function
* will be called with information about it.
*/
- int GIT_CALLBACK(update_tips)(const char *refname, const git_oid *a, const git_oid *b, void *data);
+ int GIT_CALLBACK(update_tips)(const char *refname,
+ const git_oid *a, const git_oid *b, git_refspec *spec,
+ void *data);
/**
* Function to call with progress information during pack
diff --git a/src/libgit2/push.c b/src/libgit2/push.c
index 8b47abc24..b7ac38b73 100644
--- a/src/libgit2/push.c
+++ b/src/libgit2/push.c
@@ -215,10 +215,12 @@ int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
if (fire_callback && callbacks && callbacks->update_tips) {
error = callbacks->update_tips(git_str_cstr(&remote_ref_name),
- &push_spec->roid, &push_spec->loid, callbacks->payload);
+ &push_spec->roid, &push_spec->loid, &push_spec->refspec, callbacks->payload);
- if (error < 0)
+ if (error < 0) {
+ git_error_set_after_callback_function(error, "git_remote_push");
goto on_error;
+ }
}
}
diff --git a/src/libgit2/remote.c b/src/libgit2/remote.c
index fee2a7f39..a6dffadde 100644
--- a/src/libgit2/remote.c
+++ b/src/libgit2/remote.c
@@ -1716,11 +1716,12 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks)
if (error < 0)
goto cleanup;
- if (callbacks && callbacks->update_tips)
- error = callbacks->update_tips(refname, &id, &zero_id, callbacks->payload);
-
- if (error < 0)
+ if (callbacks && callbacks->update_tips &&
+ (error = callbacks->update_tips(refname, &id, &zero_id,
+ NULL, callbacks->payload)) < 0) {
+ git_error_set_after_callback_function(error, "git_remote_fetch");
goto cleanup;
+ }
}
cleanup:
@@ -1733,6 +1734,7 @@ static int update_ref(
const git_remote *remote,
const char *ref_name,
git_oid *id,
+ git_refspec *spec,
const char *msg,
const git_remote_callbacks *callbacks)
{
@@ -1762,8 +1764,8 @@ static int update_ref(
return error;
if (callbacks && callbacks->update_tips &&
- (error = callbacks->update_tips(ref_name, &old_id, id, callbacks->payload)) < 0)
- return error;
+ (error = callbacks->update_tips(ref_name, &old_id, id, spec, callbacks->payload)) < 0)
+ git_error_set_after_callback_function(error, "git_remote_fetch");
return 0;
}
@@ -1870,7 +1872,8 @@ static int update_one_tip(
}
if (callbacks && callbacks->update_tips != NULL &&
- (error = callbacks->update_tips(refname.ptr, &old, &head->oid, callbacks->payload)) < 0)
+ (error = callbacks->update_tips(refname.ptr, &old,
+ &head->oid, spec, callbacks->payload)) < 0)
git_error_set_after_callback_function(error, "git_remote_fetch");
done:
@@ -1917,7 +1920,7 @@ static int update_tips_for_spec(
goto on_error;
if (spec->dst &&
- (error = update_ref(remote, spec->dst, &id, log_message, callbacks)) < 0)
+ (error = update_ref(remote, spec->dst, &id, spec, log_message, callbacks)) < 0)
goto on_error;
git_oid_cpy(&oid_head.oid, &id);
@@ -2029,7 +2032,7 @@ static int opportunistic_updates(
git_str_clear(&refname);
if ((error = git_refspec__transform(&refname, spec, head->name)) < 0 ||
- (error = update_ref(remote, refname.ptr, &head->oid, msg, callbacks)) < 0)
+ (error = update_ref(remote, refname.ptr, &head->oid, spec, msg, callbacks)) < 0)
goto cleanup;
}
diff --git a/tests/libgit2/network/fetchlocal.c b/tests/libgit2/network/fetchlocal.c
index dc37c38ab..f45ba8a4a 100644
--- a/tests/libgit2/network/fetchlocal.c
+++ b/tests/libgit2/network/fetchlocal.c
@@ -108,11 +108,12 @@ void test_network_fetchlocal__prune(void)
git_repository_free(repo);
}
-static int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, void *data)
+static int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, git_refspec *refspec, void *data)
{
GIT_UNUSED(ref);
GIT_UNUSED(old);
GIT_UNUSED(new);
+ GIT_UNUSED(refspec);
GIT_UNUSED(data);
cl_fail("update tips called");
@@ -510,13 +511,14 @@ void test_network_fetchlocal__prune_load_fetch_prune_config(void)
git_repository_free(repo);
}
-static int update_tips_error(const char *ref, const git_oid *old, const git_oid *new, void *data)
+static int update_tips_error(const char *ref, const git_oid *old, const git_oid *new, git_refspec *refspec, void *data)
{
int *callcount = (int *) data;
GIT_UNUSED(ref);
GIT_UNUSED(old);
GIT_UNUSED(new);
+ GIT_UNUSED(refspec);
(*callcount)++;
diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c
index b635739b6..b97f8f514 100644
--- a/tests/libgit2/online/clone.c
+++ b/tests/libgit2/online/clone.c
@@ -281,10 +281,10 @@ void test_online_clone__clone_mirror(void)
cl_fixture_cleanup("./foo.git");
}
-static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *payload)
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *payload)
{
int *callcount = (int*)payload;
- GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b);
+ GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b); GIT_UNUSED(spec);
*callcount = *callcount + 1;
return 0;
}
diff --git a/tests/libgit2/online/fetch.c b/tests/libgit2/online/fetch.c
index a557bbf75..8e0ed8934 100644
--- a/tests/libgit2/online/fetch.c
+++ b/tests/libgit2/online/fetch.c
@@ -39,9 +39,13 @@ void test_online_fetch__cleanup(void)
git__free(_remote_redirect_subsequent);
}
-static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *data)
{
- GIT_UNUSED(refname); GIT_UNUSED(a); GIT_UNUSED(b); GIT_UNUSED(data);
+ GIT_UNUSED(refname);
+ GIT_UNUSED(a);
+ GIT_UNUSED(b);
+ GIT_UNUSED(spec);
+ GIT_UNUSED(data);
++counter;
diff --git a/tests/libgit2/online/push_util.c b/tests/libgit2/online/push_util.c
index 94919e9b2..f96b1d5ea 100644
--- a/tests/libgit2/online/push_util.c
+++ b/tests/libgit2/online/push_util.c
@@ -35,11 +35,13 @@ void record_callbacks_data_clear(record_callbacks_data *data)
data->transfer_progress_calls = 0;
}
-int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
+int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *data)
{
updated_tip *t;
record_callbacks_data *record_data = (record_callbacks_data *)data;
+ GIT_UNUSED(spec);
+
cl_assert(t = git__calloc(1, sizeof(*t)));
cl_assert(t->name = git__strdup(refname));
diff --git a/tests/libgit2/online/push_util.h b/tests/libgit2/online/push_util.h
index 5f669feaf..c5a3d42a9 100644
--- a/tests/libgit2/online/push_util.h
+++ b/tests/libgit2/online/push_util.h
@@ -50,7 +50,7 @@ void record_callbacks_data_clear(record_callbacks_data *data);
*
* @param data (git_vector *) of updated_tip instances
*/
-int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data);
+int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *data);
/**
* Create a set of refspecs that deletes each of the inputs
diff --git a/tests/libgit2/submodule/update.c b/tests/libgit2/submodule/update.c
index 052a4a1fe..d89eff113 100644
--- a/tests/libgit2/submodule/update.c
+++ b/tests/libgit2/submodule/update.c
@@ -71,13 +71,14 @@ static int checkout_notify_cb(
return 0;
}
-static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, git_refspec *spec, void *data)
{
struct update_submodule_cb_payload *update_payload = data;
GIT_UNUSED(refname);
GIT_UNUSED(a);
GIT_UNUSED(b);
+ GIT_UNUSED(spec);
update_payload->update_tips_called = 1;