summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-05-06 12:28:01 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-05-13 15:52:13 +0200
commit8cec2b8ae9b1fdf4638cb405cbd8c17454c1c076 (patch)
tree5dfbe8ae145011ff7c48d598a857a4ddb69099c1
parentcf66c4748c30249ac26b961a4d719b83ea42fd60 (diff)
downloadlibgit2-8cec2b8ae9b1fdf4638cb405cbd8c17454c1c076.tar.gz
local: send the packbuilder progress via the sideband
Set a callback for the packbuilder so we can send the sideband messages to the caller, formatting them as git would.
-rw-r--r--src/transports/local.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/transports/local.c b/src/transports/local.c
index 305c71bf0..9dd448681 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -502,6 +502,33 @@ static int foreach_cb(void *buf, size_t len, void *payload)
}
static const char *counting_objects_fmt = "Counting objects %d\r";
+static const char *compressing_objects_fmt = "Compressing objects: %.0f%% (%d/%d)";
+
+static int local_counting(int stage, unsigned int current, unsigned int total, void *payload)
+{
+ git_buf progress_info = GIT_BUF_INIT;
+ transport_local *t = payload;
+
+ if (!t->progress_cb)
+ return 0;
+
+ if (stage == GIT_PACKBUILDER_ADDING_OBJECTS) {
+ git_buf_printf(&progress_info, counting_objects_fmt, current);
+ } else if (stage == GIT_PACKBUILDER_DELTAFICATION) {
+ float perc = (((float) current) / total) * 100;
+ git_buf_printf(&progress_info, compressing_objects_fmt, perc, current, total);
+ if (current == total)
+ git_buf_printf(&progress_info, ", done\n");
+ else
+ git_buf_putc(&progress_info, '\r');
+
+ }
+
+ if (git_buf_oom(&progress_info))
+ return -1;
+
+ return t->progress_cb(git_buf_cstr(&progress_info), git_buf_len(&progress_info), t->message_cb_payload);
+}
static int local_download_pack(
git_transport *transport,
@@ -527,6 +554,8 @@ static int local_download_pack(
if ((error = git_packbuilder_new(&pack, t->repo)) < 0)
goto cleanup;
+ git_packbuilder_set_callbacks(pack, local_counting, t);
+
stats->total_objects = 0;
stats->indexed_objects = 0;
stats->received_objects = 0;