fix push --quiet: add 'quiet' capability to receive-pack

Currently, git push --quiet produces some non-error output, e.g.: $ git push --quiet Unpacking objects: 100% (3/3), done. This fixes a bug reported for the fedora git package: https://bugzilla.redhat.com/show_bug.cgi?id=725593 Reported-by: Jesse Keating <jkeating@redhat.com> Cc: Todd Zullinger <tmz@pobox.com> Commit 90a6c7d4 (propagate --quiet to send-pack/receive-pack) introduced the --quiet option to receive-pack and made send-pack pass that option. Older versions of receive-pack do not recognize the option, however, and terminate immediately. The commit was therefore reverted. This change instead adds a 'quiet' capability to receive-pack, which is a backwards compatible. In addition, this fixes push --quiet via http: A verbosity of 0 means quiet for remote helpers. Reported-by: Tobias Ulmer <tobiasu@tmux.org> Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Jan 8, 2012 at 22:06 UTC c207e34f7733df04342e1c0f449f6d3cae501e33
5 files changed +40 -6
builtin/receive-pack.c
+12 -2
@@ -33,6 +33,7 @@ static int transfer_unpack_limit = -1;
33 static int unpack_limit = 100;
34 static int report_status;
35 static int use_sideband;
36 +static int quiet;
37 static int prefer_ofs_delta = 1;
38 static int auto_update_server_info;
39 static int auto_gc = 1;
@@ -122,7 +123,7 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void
123 else
124 packet_write(1, "%s %s%c%s%s\n",
125 sha1_to_hex(sha1), path, 0,
125 - " report-status delete-refs side-band-64k",
126 + " report-status delete-refs side-band-64k quiet",
127 prefer_ofs_delta ? " ofs-delta" : "");
128 sent_capabilities = 1;
129 return 0;
@@ -736,6 +737,8 @@ static struct command *read_head_info(void)
737 report_status = 1;
738 if (parse_feature_request(feature_list, "side-band-64k"))
739 use_sideband = LARGE_PACKET_MAX;
740 + if (parse_feature_request(feature_list, "quiet"))
741 + quiet = 1;
742 }
743 cmd = xcalloc(1, sizeof(struct command) + len - 80);
744 hashcpy(cmd->old_sha1, old_sha1);
@@ -789,8 +792,10 @@ static const char *unpack(void)
792
793 if (ntohl(hdr.hdr_entries) < unpack_limit) {
794 int code, i = 0;
792 - const char *unpacker[4];
795 + const char *unpacker[5];
796 unpacker[i++] = "unpack-objects";
797 + if (quiet)
798 + unpacker[i++] = "-q";
799 if (fsck_objects)
800 unpacker[i++] = "--strict";
801 unpacker[i++] = hdr_arg;
@@ -904,6 +909,11 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
909 const char *arg = *argv++;
910
911 if (*arg == '-') {
912 + if (!strcmp(arg, "--quiet")) {
913 + quiet = 1;
914 + continue;
915 + }
916 +
917 if (!strcmp(arg, "--advertise-refs")) {
918 advertise_refs = 1;
919 continue;
builtin/send-pack.c
+10 -3
@@ -263,6 +263,8 @@ int send_pack(struct send_pack_args *args,
263 args->use_ofs_delta = 1;
264 if (server_supports("side-band-64k"))
265 use_sideband = 1;
266 + if (!server_supports("quiet"))
267 + args->quiet = 0;
268
269 if (!remote_refs) {
270 fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
@@ -301,11 +303,12 @@ int send_pack(struct send_pack_args *args,
303 char *old_hex = sha1_to_hex(ref->old_sha1);
304 char *new_hex = sha1_to_hex(ref->new_sha1);
305
304 - if (!cmds_sent && (status_report || use_sideband)) {
305 - packet_buf_write(&req_buf, "%s %s %s%c%s%s",
306 + if (!cmds_sent && (status_report || use_sideband || args->quiet)) {
307 + packet_buf_write(&req_buf, "%s %s %s%c%s%s%s",
308 old_hex, new_hex, ref->name, 0,
309 status_report ? " report-status" : "",
308 - use_sideband ? " side-band-64k" : "");
310 + use_sideband ? " side-band-64k" : "",
311 + args->quiet ? " quiet" : "");
312 }
313 else
314 packet_buf_write(&req_buf, "%s %s %s",
@@ -439,6 +442,10 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
442 args.force_update = 1;
443 continue;
444 }
445 + if (!strcmp(arg, "--quiet")) {
446 + args.quiet = 1;
447 + continue;
448 + }
449 if (!strcmp(arg, "--verbose")) {
450 args.verbose = 1;
451 continue;
remote-curl.c
+3 -1
@@ -770,7 +770,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
770 argv[argc++] = "--thin";
771 if (options.dry_run)
772 argv[argc++] = "--dry-run";
773 - if (options.verbosity > 1)
773 + if (options.verbosity == 0)
774 + argv[argc++] = "--quiet";
775 + else if (options.verbosity > 1)
776 argv[argc++] = "--verbose";
777 argv[argc++] = url;
778 for (i = 0; i < nr_spec; i++)
t/t5523-push-upstream.sh
+7
@@ -108,4 +108,11 @@ test_expect_failure TTY 'push --no-progress suppresses progress' '
108 ! grep "Writing objects" err
109 '
110
111 +test_expect_success TTY 'quiet push' '
112 + ensure_fresh_upstream &&
113 +
114 + test_terminal git push --quiet --no-progress upstream master 2>&1 | tee output &&
115 + test_cmp /dev/null output
116 +'
117 +
118 test_done
t/t5541-http-push.sh
+8
@@ -5,6 +5,7 @@
5
6 test_description='test smart pushing over http via http-backend'
7 . ./test-lib.sh
8 +. "$TEST_DIRECTORY"/lib-terminal.sh
9
10 if test -n "$NO_CURL"; then
11 skip_all='skipping test, git built without http support'
@@ -186,5 +187,12 @@ test_expect_success 'push --mirror to repo with alternates' '
187 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
188 '
189
190 +test_expect_success TTY 'quiet push' '
191 + cd "$ROOT_PATH"/test_repo_clone &&
192 + test_commit quiet &&
193 + test_terminal git push --quiet --no-progress 2>&1 | tee output &&
194 + test_cmp /dev/null output
195 +'
196 +
197 stop_httpd
198 test_done