Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remote: add git_refspec to update_tips #6559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions examples/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions include/git2/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/libgit2/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/libgit2/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/libgit2/network/fetchlocal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)++;

Expand Down
4 changes: 2 additions & 2 deletions tests/libgit2/online/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/libgit2/online/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion tests/libgit2/online/push_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion tests/libgit2/online/push_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/libgit2/submodule/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down