Skip to content

Commit

Permalink
remote: add git_refspec to update_tips
Browse files Browse the repository at this point in the history
  • Loading branch information
ethomson committed May 11, 2023
1 parent 2bbcdee commit 9fdac3d
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 22 deletions.
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
2 changes: 2 additions & 0 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const cli_opt_spec cli_common_opts[] = {
const cli_cmd_spec cli_cmds[] = {
{ "cat-file", cmd_cat_file, "Display an object in the repository" },
{ "clone", cmd_clone, "Clone a repository into a new directory" },
{ "fetch", cmd_fetch, "Fetch objects and refs from a remote repository" },
{ "hash-object", cmd_hash_object, "Hash a raw object and product its object ID" },
{ "hash-object", cmd_hash_object, "Hash a raw object and product its object ID" },
{ "help", cmd_help, "Display help information" },
{ NULL }
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

0 comments on commit 9fdac3d

Please sign in to comment.