Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2012-10-20 06:23:32 +0400
committerBen Straub <bs@github.com>2012-10-20 06:36:23 +0400
commit7bcd9e23e8f64c8622e9213ee0fa3d75d058053b (patch)
tree42d73408bb7e3df8d487d38ecfaf0efb9c0531c6 /src/fetch.c
parent25e8b20169a6f6919ad49cf32220975ab96b35c8 (diff)
gitno_buffer: callback on each packet
The fetch code takes advantage of this to implement a progress callback every 100kb of transfer.
Diffstat (limited to 'src/fetch.c')
-rw-r--r--src/fetch.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/fetch.c b/src/fetch.c
index 583c79a34..3f69c2cbf 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -19,6 +19,8 @@
#include "netops.h"
#include "pkt.h"
+#define NETWORK_XFER_THRESHOLD (100*1024)
+
struct filter_payload {
git_remote *remote;
const git_refspec *spec, *tagspec;
@@ -348,6 +350,28 @@ static int no_sideband(git_transport *t, git_indexer_stream *idx, gitno_buffer *
return 0;
}
+struct network_packetsize_payload
+{
+ git_indexer_progress_callback callback;
+ void *payload;
+ git_indexer_stats *stats;
+ git_off_t last_fired_bytes;
+};
+
+static void network_packetsize(int received, void *payload)
+{
+ struct network_packetsize_payload *npp = (struct network_packetsize_payload*)payload;
+
+ /* Accumulate bytes */
+ npp->stats->bytes += received;
+
+ /* Fire notification if the threshold is reached */
+ if ((npp->stats->bytes - npp->last_fired_bytes) > NETWORK_XFER_THRESHOLD) {
+ npp->last_fired_bytes = npp->stats->bytes;
+ npp->callback(npp->stats, npp->payload);
+ }
+}
+
/* Receiving data from a socket and storing it is pretty much the same for git and HTTP */
int git_fetch__download_pack(
git_transport *t,
@@ -361,6 +385,15 @@ int git_fetch__download_pack(
gitno_buffer *buf = &t->buffer;
git_indexer_stream *idx = NULL;
int error = -1;
+ struct network_packetsize_payload npp = {0};
+
+ if (progress_cb) {
+ npp.callback = progress_cb;
+ npp.payload = progress_payload;
+ npp.stats = stats;
+ buf->packetsize_cb = &network_packetsize;
+ buf->packetsize_payload = &npp;
+ }
if (git_buf_joinpath(&path, git_repository_path(repo), "objects/pack") < 0)
return -1;