Skip to content

Commit

Permalink
Merge pull request libgit2#2284 from jacquesg/push-progress-callback
Browse files Browse the repository at this point in the history
Fire progress and update tips callbacks also for pushes.
  • Loading branch information
Vicent Marti committed Apr 25, 2014
2 parents 382d030 + 00f5dbc commit bf1e7dc
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 121 deletions.
2 changes: 1 addition & 1 deletion examples/network/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int fetch(git_repository *repo, int argc, char **argv)

// Set up the callbacks (only update_tips for now)
callbacks.update_tips = &update_cb;
callbacks.progress = &progress_cb;
callbacks.sideband_progress = &progress_cb;
callbacks.credentials = cred_acquire_cb;
git_remote_set_callbacks(remote, &callbacks);

Expand Down
2 changes: 1 addition & 1 deletion include/git2/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GIT_EXTERN(int) git_indexer_new(
const char *path,
unsigned int mode,
git_odb *odb,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_cb_payload);

/**
Expand Down
2 changes: 1 addition & 1 deletion include/git2/odb.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const gi
GIT_EXTERN(int) git_odb_write_pack(
git_odb_writepack **out,
git_odb *db,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload);

/**
Expand Down
2 changes: 1 addition & 1 deletion include/git2/pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ GIT_EXTERN(int) git_packbuilder_write(
git_packbuilder *pb,
const char *path,
unsigned int mode,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_cb_payload);

/**
Expand Down
6 changes: 3 additions & 3 deletions include/git2/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ struct git_remote_callbacks {
* progress side-band will be passed to this function (this is
* the 'counting objects' output.
*/
int (*progress)(const char *str, int len, void *data);
git_transport_message_cb sideband_progress;

/**
* Completion is called when different parts of the download
Expand All @@ -472,14 +472,14 @@ struct git_remote_callbacks {
* Returning GIT_PASSTHROUGH will make libgit2 behave as
* though this field isn't set.
*/
int (*credentials)(git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *data);
git_cred_acquire_cb credentials;

/**
* During the download of new data, this will be regularly
* called with the current count of progress done by the
* indexer.
*/
int (*transfer_progress)(const git_transfer_progress *stats, void *data);
git_transfer_progress_cb transfer_progress;

/**
* Each time a reference is updated locally, this function
Expand Down
2 changes: 1 addition & 1 deletion include/git2/sys/odb_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct git_odb_backend {

int (* writepack)(
git_odb_writepack **, git_odb_backend *, git_odb *odb,
git_transfer_progress_callback progress_cb, void *progress_payload);
git_transfer_progress_cb progress_cb, void *progress_payload);

void (* free)(git_odb_backend *);
};
Expand Down
2 changes: 1 addition & 1 deletion include/git2/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ struct git_transport {
git_transport *transport,
git_repository *repo,
git_transfer_progress *stats,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload);

/* Checks to see if the transport is connected */
Expand Down
2 changes: 1 addition & 1 deletion include/git2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ typedef struct git_transfer_progress {
* @param stats Structure containing information about the state of the transfer
* @param payload Payload provided by caller
*/
typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
typedef int (*git_transfer_progress_cb)(const git_transfer_progress *stats, void *payload);

/**
* Opaque structure representing a submodule.
Expand Down
2 changes: 1 addition & 1 deletion src/fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int git_fetch__download_pack(
git_transport *t,
git_repository *repo,
git_transfer_progress *stats,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload);

int git_fetch_setup_walk(git_revwalk **out, git_repository *repo);
Expand Down
4 changes: 2 additions & 2 deletions src/indexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct git_indexer {
unsigned int fanout[256];
git_hash_ctx hash_ctx;
git_oid hash;
git_transfer_progress_callback progress_cb;
git_transfer_progress_cb progress_cb;
void *progress_payload;
char objbuf[8*1024];

Expand Down Expand Up @@ -120,7 +120,7 @@ int git_indexer_new(
const char *prefix,
unsigned int mode,
git_odb *odb,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload)
{
git_indexer *idx;
Expand Down
2 changes: 1 addition & 1 deletion src/odb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oi
return error;
}

int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_transfer_progress_callback progress_cb, void *progress_payload)
int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_transfer_progress_cb progress_cb, void *progress_payload)
{
size_t i, writes = 0;
int error = GIT_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/odb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static void pack_backend__writepack_free(struct git_odb_writepack *_writepack)
static int pack_backend__writepack(struct git_odb_writepack **out,
git_odb_backend *_backend,
git_odb *odb,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload)
{
struct pack_backend *backend;
Expand Down
2 changes: 1 addition & 1 deletion src/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ int git_packbuilder_write(
git_packbuilder *pb,
const char *path,
unsigned int mode,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_cb_payload)
{
git_indexer *indexer;
Expand Down
50 changes: 30 additions & 20 deletions src/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ int git_push_update_tips(
int error = 0;

git_vector_foreach(&push->status, i, status) {
/* If this ref update was successful (ok, not ng), it will have an empty message */
if (status->msg)
continue;
int fire_callback = 1;

/* Find the corresponding remote ref */
fetch_spec = git_remote__matching_refspec(push->remote, status->ref);
Expand All @@ -230,24 +228,38 @@ int git_push_update_tips(
if (j == push->specs.length)
continue;

/* Update the remote ref */
if (git_oid_iszero(&push_spec->loid)) {
error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));
/* If this ref update was successful (ok, not ng), it will have an empty message */
if (status->msg == NULL) {
/* Update the remote ref */
if (git_oid_iszero(&push_spec->loid)) {
error = git_reference_lookup(&remote_ref, push->remote->repo, git_buf_cstr(&remote_ref_name));

if (!error) {
if ((error = git_reference_delete(remote_ref)) < 0) {
if (error >= 0) {
error = git_reference_delete(remote_ref);
git_reference_free(remote_ref);
goto on_error;
}
git_reference_free(remote_ref);
} else if (error == GIT_ENOTFOUND)
giterr_clear();
else
} else {
error = git_reference_create(NULL, push->remote->repo,
git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
reflog_message ? reflog_message : "update by push");
}
}

if (error < 0) {
if (error != GIT_ENOTFOUND)
goto on_error;
} else if ((error = git_reference_create(NULL, push->remote->repo,
git_buf_cstr(&remote_ref_name), &push_spec->loid, 1, signature,
reflog_message ? reflog_message : "update by push")) < 0)
goto on_error;

giterr_clear();
fire_callback = 0;
}

if (fire_callback && push->remote->callbacks.update_tips) {
error = push->remote->callbacks.update_tips(git_buf_cstr(&remote_ref_name),
&push_spec->roid, &push_spec->loid, push->remote->callbacks.payload);

if (error < 0)
goto on_error;
}
}

error = 0;
Expand Down Expand Up @@ -677,9 +689,7 @@ void git_push_status_free(push_status *status)
if (status == NULL)
return;

if (status->msg)
git__free(status->msg);

git__free(status->msg);
git__free(status->ref);
git__free(status);
}
Expand Down
4 changes: 2 additions & 2 deletions src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ int git_remote_connect(git_remote *remote, git_direction direction)
return error;

if (t->set_callbacks &&
(error = t->set_callbacks(t, remote->callbacks.progress, NULL, remote->callbacks.payload)) < 0)
(error = t->set_callbacks(t, remote->callbacks.sideband_progress, NULL, remote->callbacks.payload)) < 0)
goto on_error;

if (!remote->check_cert)
Expand Down Expand Up @@ -1246,7 +1246,7 @@ int git_remote_set_callbacks(git_remote *remote, const git_remote_callbacks *cal

if (remote->transport && remote->transport->set_callbacks)
return remote->transport->set_callbacks(remote->transport,
remote->callbacks.progress,
remote->callbacks.sideband_progress,
NULL,
remote->callbacks.payload);

Expand Down
4 changes: 2 additions & 2 deletions src/transports/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ static int local_push(

typedef struct foreach_data {
git_transfer_progress *stats;
git_transfer_progress_callback progress_cb;
git_transfer_progress_cb progress_cb;
void *progress_payload;
git_odb_writepack *writepack;
} foreach_data;
Expand All @@ -489,7 +489,7 @@ static int local_download_pack(
git_transport *transport,
git_repository *repo,
git_transfer_progress *stats,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload)
{
transport_local *t = (transport_local*)transport;
Expand Down
2 changes: 1 addition & 1 deletion src/transports/smart.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int git_smart__download_pack(
git_transport *transport,
git_repository *repo,
git_transfer_progress *stats,
git_transfer_progress_callback progress_cb,
git_transfer_progress_cb progress_cb,
void *progress_payload);

/* smart.c */
Expand Down
4 changes: 2 additions & 2 deletions src/transports/smart_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int data_pkt(git_pkt **out, const char *line, size_t len)
return 0;
}

static int progress_pkt(git_pkt **out, const char *line, size_t len)
static int sideband_progress_pkt(git_pkt **out, const char *line, size_t len)
{
git_pkt_progress *pkt;

Expand Down Expand Up @@ -403,7 +403,7 @@ int git_pkt_parse_line(
if (*line == GIT_SIDE_BAND_DATA)
ret = data_pkt(head, line, len);
else if (*line == GIT_SIDE_BAND_PROGRESS)
ret = progress_pkt(head, line, len);
ret = sideband_progress_pkt(head, line, len);
else if (*line == GIT_SIDE_BAND_ERROR)
ret = sideband_error_pkt(head, line, len);
else if (!git__prefixcmp(line, "ACK"))
Expand Down
Loading

0 comments on commit bf1e7dc

Please sign in to comment.