From 8d32e60dbe5185ffdb20bd805b3936ebbcde463a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 1 May 2012 04:41:42 -0400 Subject: [PATCH 1/3] send-pack: show progress when isatty(2) The send_pack_args struct has two verbosity flags: "quiet" and "progress". Originally, if "quiet" was set, we would tell pack-objects explicitly to be quiet, and if "progress" was set, we would tell it to show progress. Otherwise, we told it neither, and it relied on isatty(2) to make the decision itself. However, commit 01fdc21 changed the meaning of these variables. Now both "quiet" and "!progress" instruct us to tell pack-objects to be quiet (and a non-zero "progress" means the same as before). This works well for transports which call send_pack directly, as the transport code copies transport->progress into send_pack_args->progress, and they both have the same meaning. However, the code path of calling "git send-pack" was left behind. It always sets "progress" to 0, and thus always tells pack-objects to be quiet. We can work around this by checking isatty(2) ourselves in the cmd_send_pack code path, restoring the original behavior of the send-pack command. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/send-pack.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 9df341c793..7d22715630 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -492,6 +492,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) } } + if (!args.quiet) + args.progress = isatty(2); + if (args.stateless_rpc) { conn = NULL; fd[0] = 0; From 391b1f2003c425773c01799969368a517375b1a4 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 1 May 2012 04:42:24 -0400 Subject: [PATCH 2/3] teach send-pack about --[no-]progress The send_pack function gets a "progress" flag saying "yes, definitely show progress" or "no, definitely do not show progress". This gets set properly by transport_push when send_pack is called directly. However, when the send-pack command is executed separately (as it is for the remote-curl helper), there is no way to tell it "definitely do this". As a result, we do not properly respect "git push --no-progress" for smart-http remotes; you will still get progress if stderr is a tty. This patch teaches send-pack --progress and --no-progress, and teaches remote-curl to pass the appropriate option to override send-pack's isatty check. This fixes the --no-progress case above, and as a bonus, also makes "git push --progress" work when stderr is not a tty. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/send-pack.c | 14 ++++++++++++-- remote-curl.c | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 7d22715630..d5d7105ba2 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -410,6 +410,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) const char *receivepack = "git-receive-pack"; int flags; int nonfastforward = 0; + int progress = -1; argv++; for (i = 1; i < argc; i++, argv++) { @@ -452,6 +453,14 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) args.verbose = 1; continue; } + if (!strcmp(arg, "--progress")) { + progress = 1; + continue; + } + if (!strcmp(arg, "--no-progress")) { + progress = 0; + continue; + } if (!strcmp(arg, "--thin")) { args.use_thin_pack = 1; continue; @@ -492,8 +501,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) } } - if (!args.quiet) - args.progress = isatty(2); + if (progress == -1) + progress = !args.quiet && isatty(2); + args.progress = progress; if (args.stateless_rpc) { conn = NULL; diff --git a/remote-curl.c b/remote-curl.c index d159fe7f34..e5e9490be7 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -774,6 +774,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs) argv[argc++] = "--quiet"; else if (options.verbosity > 1) argv[argc++] = "--verbose"; + argv[argc++] = options.progress ? "--progress" : "--no-progress"; argv[argc++] = url; for (i = 0; i < nr_spec; i++) argv[argc++] = specs[i]; From e304aeba20d6f26cb95c022704440a36ef309075 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 1 May 2012 04:43:08 -0400 Subject: [PATCH 3/3] t5541: test more combinations of --progress Previously, we tested only that "push --quiet --no-progress" was silent. However, there are many other combinations that were not tested: 1. no options at all (but stderr as a tty) 2. --no-progress by itself 3. --quiet by itself 4. --progress (when stderr not a tty) These are tested elsewhere for general "push", but it is important to test them separately for http. It follows a very different code path than git://, and options must be relayed across a remote helper to a separate send-pack process (and in fact cases (1), (2), and (4) have all been broken just for http at some point in the past). We can drop the "--quiet --no-progress" test, as it is not really interesting (it is already handled by testing them separately in (2) and (3) above). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5541-http-push.sh | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index d66ed24508..363beaf5dd 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -215,12 +215,35 @@ test_expect_success 'push --mirror to repo with alternates' ' git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git ' -test_expect_success TTY 'quiet push' ' +test_expect_success TTY 'push shows progress when stderr is a tty' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit noisy && + test_terminal git push >output 2>&1 && + grep "^Writing objects" output +' + +test_expect_success TTY 'push --quiet silences status and progress' ' cd "$ROOT_PATH"/test_repo_clone && test_commit quiet && - test_terminal git push --quiet --no-progress 2>&1 | tee output && + test_terminal git push --quiet >output 2>&1 && test_cmp /dev/null output ' +test_expect_success TTY 'push --no-progress silences progress but not status' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit no-progress && + test_terminal git push --no-progress >output 2>&1 && + grep "^To http" output && + ! grep "^Writing objects" +' + +test_expect_success 'push --progress shows progress to non-tty' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit progress && + git push --progress >output 2>&1 && + grep "^To http" output && + grep "^Writing objects" output +' + stop_httpd test_done