Commit 2ec73fa9 by Edward Thomson

Merge pull request #3102 from libgit2/cmn/pack-objects-report

Show progress during packing for the local transport
parents a6f2ceaf 3c337a5d
...@@ -46,6 +46,13 @@ static void print_progress(const progress_data *pd) ...@@ -46,6 +46,13 @@ static void print_progress(const progress_data *pd)
} }
} }
static int sideband_progress(const char *str, int len, void *payload)
{
printf("remote: %*s", len, str);
fflush(stdout);
return 0;
}
static int fetch_progress(const git_transfer_progress *stats, void *payload) static int fetch_progress(const git_transfer_progress *stats, void *payload)
{ {
progress_data *pd = (progress_data*)payload; progress_data *pd = (progress_data*)payload;
...@@ -86,6 +93,7 @@ int do_clone(git_repository *repo, int argc, char **argv) ...@@ -86,6 +93,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
checkout_opts.progress_cb = checkout_progress; checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd; checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts; clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress; clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb; clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
clone_opts.fetch_opts.callbacks.payload = &pd; clone_opts.fetch_opts.callbacks.payload = &pd;
......
...@@ -893,6 +893,29 @@ static unsigned long free_unpacked(struct unpacked *n) ...@@ -893,6 +893,29 @@ static unsigned long free_unpacked(struct unpacked *n)
return freed_mem; return freed_mem;
} }
static int report_delta_progress(git_packbuilder *pb, uint32_t count, bool force)
{
int ret;
if (pb->progress_cb) {
double current_time = git__timer();
double elapsed = current_time - pb->last_progress_report_time;
if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
pb->last_progress_report_time = current_time;
ret = pb->progress_cb(
GIT_PACKBUILDER_DELTAFICATION,
count, pb->nr_objects, pb->progress_cb_payload);
if (ret)
return giterr_set_after_callback(ret);
}
}
return 0;
}
static int find_deltas(git_packbuilder *pb, git_pobject **list, static int find_deltas(git_packbuilder *pb, git_pobject **list,
unsigned int *list_size, unsigned int window, unsigned int *list_size, unsigned int window,
int depth) int depth)
...@@ -918,6 +941,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list, ...@@ -918,6 +941,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
break; break;
} }
pb->nr_deltified += 1;
report_delta_progress(pb, pb->nr_deltified, false);
po = *list++; po = *list++;
(*list_size)--; (*list_size)--;
git_packbuilder__progress_unlock(pb); git_packbuilder__progress_unlock(pb);
...@@ -1290,6 +1316,8 @@ static int prepare_pack(git_packbuilder *pb) ...@@ -1290,6 +1316,8 @@ static int prepare_pack(git_packbuilder *pb)
} }
} }
report_delta_progress(pb, pb->nr_objects, true);
pb->done = true; pb->done = true;
git__free(delta_list); git__free(delta_list);
return 0; return 0;
......
...@@ -65,6 +65,7 @@ struct git_packbuilder { ...@@ -65,6 +65,7 @@ struct git_packbuilder {
git_zstream zstream; git_zstream zstream;
uint32_t nr_objects, uint32_t nr_objects,
nr_deltified,
nr_alloc, nr_alloc,
nr_written, nr_written,
nr_remaining; nr_remaining;
......
...@@ -502,6 +502,33 @@ static int foreach_cb(void *buf, size_t len, void *payload) ...@@ -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 *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( static int local_download_pack(
git_transport *transport, git_transport *transport,
...@@ -527,6 +554,8 @@ static int local_download_pack( ...@@ -527,6 +554,8 @@ static int local_download_pack(
if ((error = git_packbuilder_new(&pack, t->repo)) < 0) if ((error = git_packbuilder_new(&pack, t->repo)) < 0)
goto cleanup; goto cleanup;
git_packbuilder_set_callbacks(pack, local_counting, t);
stats->total_objects = 0; stats->total_objects = 0;
stats->indexed_objects = 0; stats->indexed_objects = 0;
stats->received_objects = 0; stats->received_objects = 0;
......
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