diff mbox series

[v2,5/7] remote-curl: optionally show progress for HTTP get

Message ID 20250219-toon-bundleuri-progress-v2-5-a84e7ffa921a@iotcl.com (mailing list archive)
State New
Headers show
Series Show progress when downloading from bundle URIs | expand

Commit Message

Toon Claes Feb. 19, 2025, 2:30 p.m. UTC
git-remote-curl supports the `option progress` basically since it's
inception. But this option had no effect for regular HTTP(S) downloads.

Add progress indicator when downloading files through curl HTTP GET.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 remote-curl.c       |  8 +++++++-
 t/t5557-http-get.sh | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/remote-curl.c b/remote-curl.c
index 1273507a96..f710d6b3cb 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -1317,6 +1317,7 @@  static void parse_get(const char *arg)
 {
 	struct strbuf url = STRBUF_INIT;
 	struct strbuf path = STRBUF_INIT;
+	struct http_get_options http_options = {0};
 	const char *space;
 
 	space = strchr(arg, ' ');
@@ -1327,7 +1328,12 @@  static void parse_get(const char *arg)
 	strbuf_add(&url, arg, space - arg);
 	strbuf_addstr(&path, space + 1);
 
-	if (http_get_file(url.buf, path.buf, NULL))
+	http_options.initial_request = 1;
+
+	if (options.progress)
+		http_options.progress = 1;
+
+	if (http_get_file(url.buf, path.buf, &http_options))
 		die(_("failed to download file at URL '%s'"), url.buf);
 
 	strbuf_release(&url);
diff --git a/t/t5557-http-get.sh b/t/t5557-http-get.sh
index 67fcc23f11..41f3d16ef9 100755
--- a/t/t5557-http-get.sh
+++ b/t/t5557-http-get.sh
@@ -35,4 +35,19 @@  test_expect_success 'get by URL: 200' '
 	test_cmp "$HTTPD_DOCUMENT_ROOT_PATH/exists.txt" file2
 '
 
+test_expect_success 'get by URL with progress' '
+	echo hello >"$HTTPD_DOCUMENT_ROOT_PATH/hello.txt" &&
+
+	url="$HTTPD_URL/hello.txt" &&
+	cat >input <<-EOF &&
+	capabilities
+	option progress true
+	get $url file3
+
+	EOF
+
+	git remote-http $url <input 2>err &&
+	test_grep "^Downloading via HTTP: 100%" err
+'
+
 test_done