From f47182c852601c045f62bd7f669360a920516311 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 8 Jan 2012 22:06:19 +0100 Subject: [PATCH 1/3] server_supports(): parse feature list more carefully We have been carefully choosing feature names used in the protocol extensions so that the vocabulary does not contain a word that is a substring of another word, so it is not a real problem, but we have recently added "quiet" feature word, which would mean we cannot later add some other word with "quiet" (e.g. "quiet-push"), which is awkward. Let's make sure that we can eventually be able to do so by teaching the clients and servers that feature words consist of non whitespace letters. This parser also allows us to later add features with parameters e.g. "feature=1.5" (parameter values need to be quoted for whitespaces, but we will worry about the detauls when we do introduce them). Signed-off-by: Junio C Hamano Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- builtin/receive-pack.c | 5 +++-- cache.h | 1 + connect.c | 23 +++++++++++++++++++++-- upload-pack.c | 22 +++++++++++++--------- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d2dcb7e4af..d8ddcaa0c9 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -731,9 +731,10 @@ static struct command *read_head_info(void) refname = line + 82; reflen = strlen(refname); if (reflen + 82 < len) { - if (strstr(refname + reflen + 1, "report-status")) + const char *feature_list = refname + reflen + 1; + if (parse_feature_request(feature_list, "report-status")) report_status = 1; - if (strstr(refname + reflen + 1, "side-band-64k")) + if (parse_feature_request(feature_list, "side-band-64k")) use_sideband = LARGE_PACKET_MAX; } cmd = xcalloc(1, sizeof(struct command) + len - 80); diff --git a/cache.h b/cache.h index 10afd71d43..9bd8c2d06c 100644 --- a/cache.h +++ b/cache.h @@ -1037,6 +1037,7 @@ struct extra_have_objects { }; extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *); extern int server_supports(const char *feature); +extern const char *parse_feature_request(const char *features, const char *feature); extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path); diff --git a/connect.c b/connect.c index 2ea5c3c0fb..912cddeea8 100644 --- a/connect.c +++ b/connect.c @@ -101,8 +101,27 @@ struct ref **get_remote_heads(int in, struct ref **list, int server_supports(const char *feature) { - return server_capabilities && - strstr(server_capabilities, feature) != NULL; + return !!parse_feature_request(server_capabilities, feature); +} + +const char *parse_feature_request(const char *feature_list, const char *feature) +{ + int len; + + if (!feature_list) + return NULL; + + len = strlen(feature); + while (*feature_list) { + const char *found = strstr(feature_list, feature); + if (!found) + return NULL; + if ((feature_list == found || isspace(found[-1])) && + (!found[len] || isspace(found[len]) || found[len] == '=')) + return found; + feature_list = found + 1; + } + return NULL; } enum protocol { diff --git a/upload-pack.c b/upload-pack.c index 6f36f6255c..0d11e21a68 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -585,6 +585,7 @@ static void receive_needs(void) write_str_in_full(debug_fd, "#S\n"); for (;;) { struct object *o; + const char *features; unsigned char sha1_buf[20]; len = packet_read_line(0, line, sizeof(line)); reset_timeout(); @@ -616,23 +617,26 @@ static void receive_needs(void) get_sha1_hex(line+5, sha1_buf)) die("git upload-pack: protocol error, " "expected to get sha, not '%s'", line); - if (strstr(line+45, "multi_ack_detailed")) + + features = line + 45; + + if (parse_feature_request(features, "multi_ack_detailed")) multi_ack = 2; - else if (strstr(line+45, "multi_ack")) + else if (parse_feature_request(features, "multi_ack")) multi_ack = 1; - if (strstr(line+45, "no-done")) + if (parse_feature_request(features, "no-done")) no_done = 1; - if (strstr(line+45, "thin-pack")) + if (parse_feature_request(features, "thin-pack")) use_thin_pack = 1; - if (strstr(line+45, "ofs-delta")) + if (parse_feature_request(features, "ofs-delta")) use_ofs_delta = 1; - if (strstr(line+45, "side-band-64k")) + if (parse_feature_request(features, "side-band-64k")) use_sideband = LARGE_PACKET_MAX; - else if (strstr(line+45, "side-band")) + else if (parse_feature_request(features, "side-band")) use_sideband = DEFAULT_PACKET_MAX; - if (strstr(line+45, "no-progress")) + if (parse_feature_request(features, "no-progress")) no_progress = 1; - if (strstr(line+45, "include-tag")) + if (parse_feature_request(features, "include-tag")) use_include_tag = 1; o = lookup_object(sha1_buf); From c207e34f7733df04342e1c0f449f6d3cae501e33 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Sun, 8 Jan 2012 22:06:20 +0100 Subject: [PATCH 2/3] 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 Cc: Todd Zullinger 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 Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- builtin/receive-pack.c | 14 ++++++++++++-- builtin/send-pack.c | 13 ++++++++++--- remote-curl.c | 4 +++- t/t5523-push-upstream.sh | 7 +++++++ t/t5541-http-push.sh | 8 ++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d8ddcaa0c9..31d17cf198 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -33,6 +33,7 @@ static int transfer_unpack_limit = -1; static int unpack_limit = 100; static int report_status; static int use_sideband; +static int quiet; static int prefer_ofs_delta = 1; static int auto_update_server_info; static int auto_gc = 1; @@ -122,7 +123,7 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void else packet_write(1, "%s %s%c%s%s\n", sha1_to_hex(sha1), path, 0, - " report-status delete-refs side-band-64k", + " report-status delete-refs side-band-64k quiet", prefer_ofs_delta ? " ofs-delta" : ""); sent_capabilities = 1; return 0; @@ -736,6 +737,8 @@ static struct command *read_head_info(void) report_status = 1; if (parse_feature_request(feature_list, "side-band-64k")) use_sideband = LARGE_PACKET_MAX; + if (parse_feature_request(feature_list, "quiet")) + quiet = 1; } cmd = xcalloc(1, sizeof(struct command) + len - 80); hashcpy(cmd->old_sha1, old_sha1); @@ -789,8 +792,10 @@ static const char *unpack(void) if (ntohl(hdr.hdr_entries) < unpack_limit) { int code, i = 0; - const char *unpacker[4]; + const char *unpacker[5]; unpacker[i++] = "unpack-objects"; + if (quiet) + unpacker[i++] = "-q"; if (fsck_objects) unpacker[i++] = "--strict"; unpacker[i++] = hdr_arg; @@ -904,6 +909,11 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) const char *arg = *argv++; if (*arg == '-') { + if (!strcmp(arg, "--quiet")) { + quiet = 1; + continue; + } + if (!strcmp(arg, "--advertise-refs")) { advertise_refs = 1; continue; diff --git a/builtin/send-pack.c b/builtin/send-pack.c index cd1115ffc6..71f258ef6e 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -263,6 +263,8 @@ int send_pack(struct send_pack_args *args, args->use_ofs_delta = 1; if (server_supports("side-band-64k")) use_sideband = 1; + if (!server_supports("quiet")) + args->quiet = 0; if (!remote_refs) { fprintf(stderr, "No refs in common and none specified; doing nothing.\n" @@ -301,11 +303,12 @@ int send_pack(struct send_pack_args *args, char *old_hex = sha1_to_hex(ref->old_sha1); char *new_hex = sha1_to_hex(ref->new_sha1); - if (!cmds_sent && (status_report || use_sideband)) { - packet_buf_write(&req_buf, "%s %s %s%c%s%s", + if (!cmds_sent && (status_report || use_sideband || args->quiet)) { + packet_buf_write(&req_buf, "%s %s %s%c%s%s%s", old_hex, new_hex, ref->name, 0, status_report ? " report-status" : "", - use_sideband ? " side-band-64k" : ""); + use_sideband ? " side-band-64k" : "", + args->quiet ? " quiet" : ""); } else packet_buf_write(&req_buf, "%s %s %s", @@ -439,6 +442,10 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) args.force_update = 1; continue; } + if (!strcmp(arg, "--quiet")) { + args.quiet = 1; + continue; + } if (!strcmp(arg, "--verbose")) { args.verbose = 1; continue; diff --git a/remote-curl.c b/remote-curl.c index 48c20b86f3..bcbc7fba4e 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -770,7 +770,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs) argv[argc++] = "--thin"; if (options.dry_run) argv[argc++] = "--dry-run"; - if (options.verbosity > 1) + if (options.verbosity == 0) + argv[argc++] = "--quiet"; + else if (options.verbosity > 1) argv[argc++] = "--verbose"; argv[argc++] = url; for (i = 0; i < nr_spec; i++) diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh index c229fe68f1..9ee52cfc45 100755 --- a/t/t5523-push-upstream.sh +++ b/t/t5523-push-upstream.sh @@ -108,4 +108,11 @@ test_expect_failure TTY 'push --no-progress suppresses progress' ' ! grep "Writing objects" err ' +test_expect_success TTY 'quiet push' ' + ensure_fresh_upstream && + + test_terminal git push --quiet --no-progress upstream master 2>&1 | tee output && + test_cmp /dev/null output +' + test_done diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 9b85d420c3..0c3cd3b4dd 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -5,6 +5,7 @@ test_description='test smart pushing over http via http-backend' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh if test -n "$NO_CURL"; then skip_all='skipping test, git built without http support' @@ -186,5 +187,12 @@ test_expect_success 'push --mirror to repo with alternates' ' git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git ' +test_expect_success TTY 'quiet push' ' + cd "$ROOT_PATH"/test_repo_clone && + test_commit quiet && + test_terminal git push --quiet --no-progress 2>&1 | tee output && + test_cmp /dev/null output +' + stop_httpd test_done From d336572f57e398318a0f6c51cc760d5be9872cc2 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sun, 8 Jan 2012 22:06:21 +0100 Subject: [PATCH 3/3] t5541: avoid TAP test miscounting lib-terminal.sh runs a test and thus increases the test count, but the output is lost so that TAP produces a "no plan found error". Move the lib-terminal call after the lib-httpd and make TAP happy (though still leave me clueless). Signed-off-by: Michael J Gruber Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- t/t5541-http-push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index 0c3cd3b4dd..6c9ec6f117 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -5,7 +5,6 @@ test_description='test smart pushing over http via http-backend' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-terminal.sh if test -n "$NO_CURL"; then skip_all='skipping test, git built without http support' @@ -15,6 +14,7 @@ fi ROOT_PATH="$PWD" LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'} . "$TEST_DIRECTORY"/lib-httpd.sh +. "$TEST_DIRECTORY"/lib-terminal.sh start_httpd test_expect_success 'setup remote repository' '