Skip to content

Commit 7b718fb

Browse files
committed
Merge branch 'cb/push-quiet'
* cb/push-quiet: t5541: avoid TAP test miscounting fix push --quiet: add 'quiet' capability to receive-pack server_supports(): parse feature list more carefully
2 parents 7859f53 + d336572 commit 7b718fb

8 files changed

+78
-19
lines changed

builtin/receive-pack.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int transfer_unpack_limit = -1;
3333
static int unpack_limit = 100;
3434
static int report_status;
3535
static int use_sideband;
36+
static int quiet;
3637
static int prefer_ofs_delta = 1;
3738
static int auto_update_server_info;
3839
static int auto_gc = 1;
@@ -122,7 +123,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
122123
else
123124
packet_write(1, "%s %s%c%s%s\n",
124125
sha1_to_hex(sha1), path, 0,
125-
" report-status delete-refs side-band-64k",
126+
" report-status delete-refs side-band-64k quiet",
126127
prefer_ofs_delta ? " ofs-delta" : "");
127128
sent_capabilities = 1;
128129
}
@@ -748,10 +749,13 @@ static struct command *read_head_info(void)
748749
refname = line + 82;
749750
reflen = strlen(refname);
750751
if (reflen + 82 < len) {
751-
if (strstr(refname + reflen + 1, "report-status"))
752+
const char *feature_list = refname + reflen + 1;
753+
if (parse_feature_request(feature_list, "report-status"))
752754
report_status = 1;
753-
if (strstr(refname + reflen + 1, "side-band-64k"))
755+
if (parse_feature_request(feature_list, "side-band-64k"))
754756
use_sideband = LARGE_PACKET_MAX;
757+
if (parse_feature_request(feature_list, "quiet"))
758+
quiet = 1;
755759
}
756760
cmd = xcalloc(1, sizeof(struct command) + len - 80);
757761
hashcpy(cmd->old_sha1, old_sha1);
@@ -805,8 +809,10 @@ static const char *unpack(void)
805809

806810
if (ntohl(hdr.hdr_entries) < unpack_limit) {
807811
int code, i = 0;
808-
const char *unpacker[4];
812+
const char *unpacker[5];
809813
unpacker[i++] = "unpack-objects";
814+
if (quiet)
815+
unpacker[i++] = "-q";
810816
if (fsck_objects)
811817
unpacker[i++] = "--strict";
812818
unpacker[i++] = hdr_arg;
@@ -901,6 +907,11 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
901907
const char *arg = *argv++;
902908

903909
if (*arg == '-') {
910+
if (!strcmp(arg, "--quiet")) {
911+
quiet = 1;
912+
continue;
913+
}
914+
904915
if (!strcmp(arg, "--advertise-refs")) {
905916
advertise_refs = 1;
906917
continue;

builtin/send-pack.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ int send_pack(struct send_pack_args *args,
263263
args->use_ofs_delta = 1;
264264
if (server_supports("side-band-64k"))
265265
use_sideband = 1;
266+
if (!server_supports("quiet"))
267+
args->quiet = 0;
266268

267269
if (!remote_refs) {
268270
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
@@ -301,11 +303,12 @@ int send_pack(struct send_pack_args *args,
301303
char *old_hex = sha1_to_hex(ref->old_sha1);
302304
char *new_hex = sha1_to_hex(ref->new_sha1);
303305

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",
306308
old_hex, new_hex, ref->name, 0,
307309
status_report ? " report-status" : "",
308-
use_sideband ? " side-band-64k" : "");
310+
use_sideband ? " side-band-64k" : "",
311+
args->quiet ? " quiet" : "");
309312
}
310313
else
311314
packet_buf_write(&req_buf, "%s %s %s",
@@ -439,6 +442,10 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
439442
args.force_update = 1;
440443
continue;
441444
}
445+
if (!strcmp(arg, "--quiet")) {
446+
args.quiet = 1;
447+
continue;
448+
}
442449
if (!strcmp(arg, "--verbose")) {
443450
args.verbose = 1;
444451
continue;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ struct extra_have_objects {
10371037
};
10381038
extern struct ref **get_remote_heads(int in, struct ref **list, unsigned int flags, struct extra_have_objects *);
10391039
extern int server_supports(const char *feature);
1040+
extern const char *parse_feature_request(const char *features, const char *feature);
10401041

10411042
extern struct packed_git *parse_pack_index(unsigned char *sha1, const char *idx_path);
10421043

connect.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,27 @@ struct ref **get_remote_heads(int in, struct ref **list,
101101

102102
int server_supports(const char *feature)
103103
{
104-
return server_capabilities &&
105-
strstr(server_capabilities, feature) != NULL;
104+
return !!parse_feature_request(server_capabilities, feature);
105+
}
106+
107+
const char *parse_feature_request(const char *feature_list, const char *feature)
108+
{
109+
int len;
110+
111+
if (!feature_list)
112+
return NULL;
113+
114+
len = strlen(feature);
115+
while (*feature_list) {
116+
const char *found = strstr(feature_list, feature);
117+
if (!found)
118+
return NULL;
119+
if ((feature_list == found || isspace(found[-1])) &&
120+
(!found[len] || isspace(found[len]) || found[len] == '='))
121+
return found;
122+
feature_list = found + 1;
123+
}
124+
return NULL;
106125
}
107126

108127
enum protocol {

remote-curl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
770770
argv[argc++] = "--thin";
771771
if (options.dry_run)
772772
argv[argc++] = "--dry-run";
773-
if (options.verbosity > 1)
773+
if (options.verbosity == 0)
774+
argv[argc++] = "--quiet";
775+
else if (options.verbosity > 1)
774776
argv[argc++] = "--verbose";
775777
argv[argc++] = url;
776778
for (i = 0; i < nr_spec; i++)

t/t5523-push-upstream.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,11 @@ test_expect_failure TTY 'push --no-progress suppresses progress' '
108108
! grep "Writing objects" err
109109
'
110110

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+
111118
test_done

t/t5541-http-push.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fi
1414
ROOT_PATH="$PWD"
1515
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
1616
. "$TEST_DIRECTORY"/lib-httpd.sh
17+
. "$TEST_DIRECTORY"/lib-terminal.sh
1718
start_httpd
1819

1920
test_expect_success 'setup remote repository' '
@@ -186,5 +187,12 @@ test_expect_success 'push --mirror to repo with alternates' '
186187
git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
187188
'
188189

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+
189197
stop_httpd
190198
test_done

upload-pack.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ static void receive_needs(void)
585585
write_str_in_full(debug_fd, "#S\n");
586586
for (;;) {
587587
struct object *o;
588+
const char *features;
588589
unsigned char sha1_buf[20];
589590
len = packet_read_line(0, line, sizeof(line));
590591
reset_timeout();
@@ -616,23 +617,26 @@ static void receive_needs(void)
616617
get_sha1_hex(line+5, sha1_buf))
617618
die("git upload-pack: protocol error, "
618619
"expected to get sha, not '%s'", line);
619-
if (strstr(line+45, "multi_ack_detailed"))
620+
621+
features = line + 45;
622+
623+
if (parse_feature_request(features, "multi_ack_detailed"))
620624
multi_ack = 2;
621-
else if (strstr(line+45, "multi_ack"))
625+
else if (parse_feature_request(features, "multi_ack"))
622626
multi_ack = 1;
623-
if (strstr(line+45, "no-done"))
627+
if (parse_feature_request(features, "no-done"))
624628
no_done = 1;
625-
if (strstr(line+45, "thin-pack"))
629+
if (parse_feature_request(features, "thin-pack"))
626630
use_thin_pack = 1;
627-
if (strstr(line+45, "ofs-delta"))
631+
if (parse_feature_request(features, "ofs-delta"))
628632
use_ofs_delta = 1;
629-
if (strstr(line+45, "side-band-64k"))
633+
if (parse_feature_request(features, "side-band-64k"))
630634
use_sideband = LARGE_PACKET_MAX;
631-
else if (strstr(line+45, "side-band"))
635+
else if (parse_feature_request(features, "side-band"))
632636
use_sideband = DEFAULT_PACKET_MAX;
633-
if (strstr(line+45, "no-progress"))
637+
if (parse_feature_request(features, "no-progress"))
634638
no_progress = 1;
635-
if (strstr(line+45, "include-tag"))
639+
if (parse_feature_request(features, "include-tag"))
636640
use_include_tag = 1;
637641

638642
o = lookup_object(sha1_buf);

0 commit comments

Comments
 (0)