From: Toon Claes <toon@iotcl.com>
To: git@vger.kernel.org
Cc: Toon Claes <toon@iotcl.com>
Subject: [PATCH 1/4] progress: add function to set total
Date: Wed, 8 May 2024 14:44:50 +0200 [thread overview]
Message-ID: <20240508124453.600871-2-toon@iotcl.com> (raw)
In-Reply-To: <20240508124453.600871-1-toon@iotcl.com>
We're about to add the use of progress through curl. Although, curl
doesn't know the total at the start of the download, but might receive
this information in the Content-Length header when the download starts.
To allow users set the total size after calling start_progress(), add a
function progress_set_total().
Signed-off-by: Toon Claes <toon@iotcl.com>
---
progress.c | 6 ++++++
progress.h | 1 +
t/helper/test-progress.c | 5 +++++
t/t0500-progress-display.sh | 24 ++++++++++++++++++++++++
4 files changed, 36 insertions(+)
diff --git a/progress.c b/progress.c
index c83cb60bf1..494b26eb20 100644
--- a/progress.c
+++ b/progress.c
@@ -271,6 +271,12 @@ static struct progress *start_progress_delay(const char *title, uint64_t total,
return progress;
}
+void progress_set_total(struct progress *progress, uint64_t total)
+{
+ if (progress)
+ progress->total = total;
+}
+
static int get_default_delay(void)
{
static int delay_in_secs = -1;
diff --git a/progress.h b/progress.h
index 3a945637c8..52f75ab1bf 100644
--- a/progress.h
+++ b/progress.h
@@ -14,6 +14,7 @@ void progress_test_force_update(void);
void display_throughput(struct progress *progress, uint64_t total);
void display_progress(struct progress *progress, uint64_t n);
+void progress_set_total(struct progress *progress, uint64_t total);
struct progress *start_progress(const char *title, uint64_t total);
struct progress *start_sparse_progress(const char *title, uint64_t total);
struct progress *start_delayed_progress(const char *title, uint64_t total);
diff --git a/t/helper/test-progress.c b/t/helper/test-progress.c
index 66acb6a06c..622b1f738d 100644
--- a/t/helper/test-progress.c
+++ b/t/helper/test-progress.c
@@ -70,6 +70,11 @@ int cmd__progress(int argc, const char **argv)
if (*end != '\0')
die("invalid input: '%s'\n", line.buf);
display_progress(progress, item_count);
+ } else if (skip_prefix(line.buf, "total ", (const char **) &end)) {
+ uint64_t total = strtoull(end, &end, 10);
+ if (*end != '\0')
+ die("invalid input: '%s'\n", line.buf);
+ progress_set_total(progress, total);
} else if (skip_prefix(line.buf, "throughput ",
(const char **) &end)) {
uint64_t byte_count, test_ms;
diff --git a/t/t0500-progress-display.sh b/t/t0500-progress-display.sh
index 1eb3a8306b..82a3b834a6 100755
--- a/t/t0500-progress-display.sh
+++ b/t/t0500-progress-display.sh
@@ -56,6 +56,30 @@ test_expect_success 'progress display with total' '
test_cmp expect out
'
+test_expect_success 'progress display modify total' '
+ cat >expect <<-\EOF &&
+ Working hard: 1<CR>
+ Working hard: 66% (2/3)<CR>
+ Working hard: 100% (3/3)<CR>
+ Working hard: 100% (3/3), done.
+ EOF
+
+ cat >in <<-\EOF &&
+ start 0
+ update
+ progress 1
+ update
+ total 3
+ progress 2
+ progress 3
+ stop
+ EOF
+ test-tool progress <in 2>stderr &&
+
+ show_cr <stderr >out &&
+ test_cmp expect out
+'
+
test_expect_success 'progress display breaks long lines #1' '
sed -e "s/Z$//" >expect <<\EOF &&
Working hard.......2.........3.........4.........5.........6: 0% (100/100000)<CR>
--
2.44.0.651.g21306a098c
next prev parent reply other threads:[~2024-05-08 12:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 12:44 [PATCH 0/4] bundle-uri: show progress when downloading from bundle URIs Toon Claes
2024-05-08 12:44 ` Toon Claes [this message]
2024-05-08 12:44 ` [PATCH 2/4] http: add the ability to log progress Toon Claes
2024-05-08 16:52 ` Eric Sunshine
2024-05-09 16:34 ` Jeff King
2024-05-09 16:51 ` Junio C Hamano
2024-05-09 17:04 ` Jeff King
2024-05-09 16:52 ` Jeff King
2024-05-08 12:44 ` [PATCH 3/4] remote-curl: optionally show progress for HTTP get Toon Claes
2024-05-08 22:29 ` Junio C Hamano
2024-05-08 12:44 ` [PATCH 4/4] bundle-uri: enable git-remote-https progress Toon Claes
2024-05-09 16:46 ` Jeff King
2025-02-14 11:26 ` Toon Claes
2025-02-21 7:36 ` Jeff King
2024-05-08 23:49 ` [PATCH 0/4] bundle-uri: show progress when downloading from bundle URIs Junio C Hamano
2025-02-19 14:30 ` [PATCH v2 0/7] Show " Toon Claes
2025-02-19 14:30 ` [PATCH v2 1/7] progress: add function to set total Toon Claes
2025-02-21 7:43 ` Jeff King
2025-02-19 14:30 ` [PATCH v2 2/7] progress: allow pure-throughput progress meters Toon Claes
2025-02-19 14:30 ` [PATCH v2 3/7] http: turn off curl signals Toon Claes
2025-02-19 14:30 ` [PATCH v2 4/7] http: add the ability to log progress Toon Claes
2025-02-19 14:30 ` [PATCH v2 5/7] remote-curl: optionally show progress for HTTP get Toon Claes
2025-02-19 14:30 ` [PATCH v2 6/7] bundle-uri: enable git-remote-https progress Toon Claes
2025-02-19 14:30 ` [PATCH v2 7/7] http: silence stderr when progress is enabled Toon Claes
2025-02-21 7:48 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240508124453.600871-2-toon@iotcl.com \
--to=toon@iotcl.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.