summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-06-11 16:14:11 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2022-06-11 16:14:11 -0400
commit3a7371694ce3319a3d9e64a4cf960dc14536bed6 (patch)
tree3b3118516b999a8d234f6d401447f6d45f0916d5
parent286e7f0ad0ba0d9831c30e2634df1ecf2ea68516 (diff)
downloadlibgit2-3a7371694ce3319a3d9e64a4cf960dc14536bed6.tar.gz
progress: fewer updates about throughput
Avoid too much flashing on the console with updates about throughput. Only update throughput once a second.
-rw-r--r--src/cli/progress.c23
-rw-r--r--src/cli/progress.h4
2 files changed, 23 insertions, 4 deletions
diff --git a/src/cli/progress.c b/src/cli/progress.c
index b17f0e11b..ba52655e7 100644
--- a/src/cli/progress.c
+++ b/src/cli/progress.c
@@ -12,7 +12,13 @@
#include "progress.h"
#include "error.h"
-#define PROGRESS_UPDATE_TIME 0.05
+/*
+ * Show updates to the percentage and number of objects received
+ * separately from the throughput to give an accurate progress while
+ * avoiding too much noise on the screen.
+ */
+#define PROGRESS_UPDATE_TIME 0.10
+#define THROUGHPUT_UPDATE_TIME 1.00
#define is_nl(c) ((c) == '\r' || (c) == '\n')
@@ -200,11 +206,20 @@ static int fetch_receiving(
else
now = git__timer();
- recv_len = (double)stats->received_bytes;
+ if (progress->throughput_update &&
+ now - progress->throughput_update < THROUGHPUT_UPDATE_TIME) {
+ elapsed = progress->throughput_update -
+ progress->action_start;
+ recv_len = progress->throughput_bytes;
+ } else {
+ elapsed = now - progress->action_start;
+ recv_len = (double)stats->received_bytes;
+
+ progress->throughput_update = now;
+ progress->throughput_bytes = recv_len;
+ }
- elapsed = now - progress->action_start;
rate = elapsed ? recv_len / elapsed : 0;
- done = (stats->received_objects == stats->total_objects);
while (recv_len > 1024 && recv_units[recv_unit_idx+1]) {
recv_len /= 1024;
diff --git a/src/cli/progress.h b/src/cli/progress.h
index fab2e97a2..7a445ec29 100644
--- a/src/cli/progress.h
+++ b/src/cli/progress.h
@@ -40,6 +40,10 @@ typedef struct {
git_str sideband;
git_str onscreen;
git_str deferred;
+
+ /* Last update about throughput */
+ double throughput_update;
+ double throughput_bytes;
} cli_progress;
#define CLI_PROGRESS_INIT { 0 }