Commit 9effa2fb by Jacques Germishuys

Fire progress callbacks also for pushes.

It's not very useful to only know that a pre-receive hook has declined
a push, you probably want to know why.
parent bfc50f83
...@@ -455,7 +455,8 @@ struct git_remote_callbacks { ...@@ -455,7 +455,8 @@ struct git_remote_callbacks {
/** /**
* Textual progress from the remote. Text send over the * Textual progress from the remote. Text send over the
* progress side-band will be passed to this function (this is * progress side-band will be passed to this function (this is
* the 'counting objects' output. * the 'counting objects' output. This callback should return a value less
* than zero to cancel the operation.
*/ */
int (*progress)(const char *str, int len, void *data); int (*progress)(const char *str, int len, void *data);
......
...@@ -478,7 +478,7 @@ int git_smart__download_pack( ...@@ -478,7 +478,7 @@ int git_smart__download_pack(
git_transport *transport, git_transport *transport,
git_repository *repo, git_repository *repo,
git_transfer_progress *stats, git_transfer_progress *stats,
git_transfer_progress_callback progress_cb, git_transfer_progress_callback transfer_progress_cb,
void *progress_payload) void *progress_payload)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = (transport_smart *)transport;
...@@ -490,8 +490,8 @@ int git_smart__download_pack( ...@@ -490,8 +490,8 @@ int git_smart__download_pack(
memset(stats, 0, sizeof(git_transfer_progress)); memset(stats, 0, sizeof(git_transfer_progress));
if (progress_cb) { if (transfer_progress_cb) {
npp.callback = progress_cb; npp.callback = transfer_progress_cb;
npp.payload = progress_payload; npp.payload = progress_payload;
npp.stats = stats; npp.stats = stats;
t->packetsize_cb = &network_packetsize; t->packetsize_cb = &network_packetsize;
...@@ -504,7 +504,7 @@ int git_smart__download_pack( ...@@ -504,7 +504,7 @@ int git_smart__download_pack(
} }
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 || if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
((error = git_odb_write_pack(&writepack, odb, progress_cb, progress_payload)) != 0)) ((error = git_odb_write_pack(&writepack, odb, transfer_progress_cb, progress_payload)) != 0))
goto done; goto done;
/* /*
...@@ -518,7 +518,7 @@ int git_smart__download_pack( ...@@ -518,7 +518,7 @@ int git_smart__download_pack(
} }
do { do {
git_pkt *pkt; git_pkt *pkt = NULL;
/* Check cancellation before network call */ /* Check cancellation before network call */
if (t->cancelled.val) { if (t->cancelled.val) {
...@@ -527,40 +527,34 @@ int git_smart__download_pack( ...@@ -527,40 +527,34 @@ int git_smart__download_pack(
goto done; goto done;
} }
if ((error = recv_pkt(&pkt, buf)) < 0) if ((error = recv_pkt(&pkt, buf)) >= 0) {
goto done; /* Check cancellation after network call */
if (t->cancelled.val) {
/* Check cancellation after network call */ giterr_clear();
if (t->cancelled.val) { error = GIT_EUSER;
giterr_clear(); } else if (pkt->type == GIT_PKT_PROGRESS) {
error = GIT_EUSER; if (t->progress_cb) {
goto done; git_pkt_progress *p = (git_pkt_progress *) pkt;
error = t->progress_cb(p->data, p->len, t->message_cb_payload);
}
} else if (pkt->type == GIT_PKT_DATA) {
git_pkt_data *p = (git_pkt_data *) pkt;
error = writepack->append(writepack, p->data, p->len, stats);
} else if (pkt->type == GIT_PKT_FLUSH) {
/* A flush indicates the end of the packfile */
git__free(pkt);
break;
}
} }
if (pkt->type == GIT_PKT_PROGRESS) { git__free(pkt);
if (t->progress_cb) { if (error < 0)
git_pkt_progress *p = (git_pkt_progress *) pkt; goto done;
error = t->progress_cb(p->data, p->len, t->message_cb_payload);
if (error)
goto done;
}
git__free(pkt);
} else if (pkt->type == GIT_PKT_DATA) {
git_pkt_data *p = (git_pkt_data *) pkt;
error = writepack->append(writepack, p->data, p->len, stats);
git__free(pkt);
if (error != 0)
goto done;
} else if (pkt->type == GIT_PKT_FLUSH) {
/* A flush indicates the end of the packfile */
git__free(pkt);
break;
}
} while (1); } while (1);
/* /*
* Trailing execution of progress_cb, if necessary... * Trailing execution of transfer_progress_cb, if necessary...
* Only the callback through the npp datastructure currently * Only the callback through the npp datastructure currently
* updates the last_fired_bytes value. It is possible that * updates the last_fired_bytes value. It is possible that
* progress has already been reported with the correct * progress has already been reported with the correct
...@@ -579,7 +573,7 @@ int git_smart__download_pack( ...@@ -579,7 +573,7 @@ int git_smart__download_pack(
done: done:
if (writepack) if (writepack)
writepack->free(writepack); writepack->free(writepack);
if (progress_cb) { if (transfer_progress_cb) {
t->packetsize_cb = NULL; t->packetsize_cb = NULL;
t->packetsize_payload = NULL; t->packetsize_payload = NULL;
} }
...@@ -696,10 +690,11 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt) ...@@ -696,10 +690,11 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt)
return 0; return 0;
} }
static int parse_report(gitno_buffer *buf, git_push *push) static int parse_report(transport_smart *transport, git_push *push)
{ {
git_pkt *pkt = NULL; git_pkt *pkt = NULL;
const char *line_end = NULL; const char *line_end = NULL;
gitno_buffer *buf = &transport->buffer;
int error, recvd; int error, recvd;
for (;;) { for (;;) {
...@@ -738,6 +733,10 @@ static int parse_report(gitno_buffer *buf, git_push *push) ...@@ -738,6 +733,10 @@ static int parse_report(gitno_buffer *buf, git_push *push)
error = -1; error = -1;
break; break;
case GIT_PKT_PROGRESS: case GIT_PKT_PROGRESS:
if (transport->progress_cb) {
git_pkt_progress *p = (git_pkt_progress *) pkt;
error = transport->progress_cb(p->data, p->len, transport->message_cb_payload);
}
break; break;
default: default:
error = add_push_report_pkt(push, pkt); error = add_push_report_pkt(push, pkt);
...@@ -953,7 +952,7 @@ int git_smart__push(git_transport *transport, git_push *push) ...@@ -953,7 +952,7 @@ int git_smart__push(git_transport *transport, git_push *push)
* we consider the pack to have been unpacked successfully */ * we consider the pack to have been unpacked successfully */
if (!push->specs.length || !push->report_status) if (!push->specs.length || !push->report_status)
push->unpack_ok = 1; push->unpack_ok = 1;
else if ((error = parse_report(&t->buffer, push)) < 0) else if ((error = parse_report(t, push)) < 0)
goto done; goto done;
/* If progress is being reported write the final report */ /* If progress is being reported write the final report */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment