Merge pull request #1042 from pwkelley/progress_cb Fix bytes_received in fetch tests - we weren't calling the callback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index a2e9c88..4fdd72d 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -371,7 +371,7 @@ struct network_packetsize_payload
git_transfer_progress_callback callback;
void *payload;
git_transfer_progress *stats;
- git_off_t last_fired_bytes;
+ size_t last_fired_bytes;
};
static void network_packetsize(int received, void *payload)
@@ -402,12 +402,18 @@ int git_smart__download_pack(
int error = -1;
struct network_packetsize_payload npp = {0};
+ memset(stats, 0, sizeof(git_transfer_progress));
+
if (progress_cb) {
npp.callback = progress_cb;
npp.payload = progress_payload;
npp.stats = stats;
t->packetsize_cb = &network_packetsize;
t->packetsize_payload = &npp;
+
+ /* We might have something in the buffer already from negotiate_fetch */
+ if (t->buffer.offset > 0)
+ t->packetsize_cb(t->buffer.offset, t->packetsize_payload);
}
if (git_buf_joinpath(&path, git_repository_path(repo), "objects/pack") < 0)
@@ -416,9 +422,6 @@ int git_smart__download_pack(
if (git_indexer_stream_new(&idx, git_buf_cstr(&path), progress_cb, progress_payload) < 0)
goto on_error;
- git_buf_free(&path);
- memset(stats, 0, sizeof(git_transfer_progress));
-
/*
* If the remote doesn't support the side-band, we can feed
* the data directly to the indexer. Otherwise, we need to
@@ -428,8 +431,7 @@ int git_smart__download_pack(
if (no_sideband(t, idx, buf, stats) < 0)
goto on_error;
- git_indexer_stream_free(idx);
- return 0;
+ goto on_success;
}
do {
@@ -466,11 +468,16 @@ int git_smart__download_pack(
if (git_indexer_stream_finalize(idx, stats) < 0)
goto on_error;
- git_indexer_stream_free(idx);
- return 0;
+on_success:
+ error = 0;
on_error:
git_buf_free(&path);
git_indexer_stream_free(idx);
+
+ /* Trailing execution of progress_cb, if necessary */
+ if (npp.callback && npp.stats->received_bytes > npp.last_fired_bytes)
+ npp.callback(npp.stats, npp.payload);
+
return error;
}