do not send client agent unless server does first

Commit ff5effdf taught both clients and servers of the git protocol to send an "agent" capability that just advertises their version for statistics and debugging purposes. The protocol-capabilities.txt document however indicates that the client's advertisement is actually a response, and should never include capabilities not mentioned in the server's advertisement. Adding the unconditional advertisement in the server programs was OK, then, but the clients broke the protocol. The server implementation of git-core itself does not care, but at least one does: the Google Code git server (or any server using Dulwich), will hang up with an internal error upon seeing an unknown capability. Instead, each client must record whether we saw an agent string from the server, and respond with its agent only if the server mentioned it first. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 10, 2012 at 03:57 UTC d50c3871632451b0cac066eea178198ac8a9dff1
2 files changed +15 -4
builtin/fetch-pack.c
+6 -1
@@ -19,6 +19,7 @@ static int prefer_ofs_delta = 1;
19 static int no_done;
20 static int fetch_fsck_objects = -1;
21 static int transfer_fsck_objects = -1;
22 +static int agent_supported;
23 static struct fetch_pack_args args = {
24 /* .uploadpack = */ "git-upload-pack",
25 };
@@ -328,7 +329,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
329 if (args.no_progress) strbuf_addstr(&c, " no-progress");
330 if (args.include_tag) strbuf_addstr(&c, " include-tag");
331 if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta");
331 - strbuf_addf(&c, " agent=%s", git_user_agent_sanitized());
332 + if (agent_supported) strbuf_addf(&c, " agent=%s",
333 + git_user_agent_sanitized());
334 packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
335 strbuf_release(&c);
336 } else
@@ -821,6 +823,9 @@ static struct ref *do_fetch_pack(int fd[2],
823 fprintf(stderr, "Server supports ofs-delta\n");
824 } else
825 prefer_ofs_delta = 0;
826 + if (server_supports("agent"))
827 + agent_supported = 1;
828 +
829 if (everything_local(&ref, nr_match, match)) {
830 packet_flush(fd[1]);
831 goto all_done;
builtin/send-pack.c
+9 -3
@@ -252,6 +252,7 @@ int send_pack(struct send_pack_args *args,
252 int status_report = 0;
253 int use_sideband = 0;
254 int quiet_supported = 0;
255 + int agent_supported = 0;
256 unsigned cmds_sent = 0;
257 int ret;
258 struct async demux;
@@ -267,6 +268,8 @@ int send_pack(struct send_pack_args *args,
268 use_sideband = 1;
269 if (server_supports("quiet"))
270 quiet_supported = 1;
271 + if (server_supports("agent"))
272 + agent_supported = 1;
273
274 if (!remote_refs) {
275 fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
@@ -306,14 +309,17 @@ int send_pack(struct send_pack_args *args,
309 char *new_hex = sha1_to_hex(ref->new_sha1);
310 int quiet = quiet_supported && (args->quiet || !args->progress);
311
309 - if (!cmds_sent && (status_report || use_sideband || quiet)) {
312 + if (!cmds_sent && (status_report || use_sideband ||
313 + quiet || agent_supported)) {
314 packet_buf_write(&req_buf,
311 - "%s %s %s%c%s%s%s agent=%s",
315 + "%s %s %s%c%s%s%s%s%s",
316 old_hex, new_hex, ref->name, 0,
317 status_report ? " report-status" : "",
318 use_sideband ? " side-band-64k" : "",
319 quiet ? " quiet" : "",
316 - git_user_agent_sanitized());
320 + agent_supported ? " agent=" : "",
321 + agent_supported ? git_user_agent_sanitized() : ""
322 + );
323 }
324 else
325 packet_buf_write(&req_buf, "%s %s %s",