mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-09 10:56:20 +00:00
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.
This commit is contained in:
parent
cf66c4748c
commit
8cec2b8ae9
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user