Skip to content

Commit d50c387

Browse files
peffgitster
authored andcommitted
do not send client agent unless server does first
Commit ff5effd 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca8e127 commit d50c387

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

builtin/fetch-pack.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static int prefer_ofs_delta = 1;
1919
static int no_done;
2020
static int fetch_fsck_objects = -1;
2121
static int transfer_fsck_objects = -1;
22+
static int agent_supported;
2223
static struct fetch_pack_args args = {
2324
/* .uploadpack = */ "git-upload-pack",
2425
};
@@ -328,7 +329,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,
328329
if (args.no_progress) strbuf_addstr(&c, " no-progress");
329330
if (args.include_tag) strbuf_addstr(&c, " include-tag");
330331
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());
332334
packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
333335
strbuf_release(&c);
334336
} else
@@ -821,6 +823,9 @@ static struct ref *do_fetch_pack(int fd[2],
821823
fprintf(stderr, "Server supports ofs-delta\n");
822824
} else
823825
prefer_ofs_delta = 0;
826+
if (server_supports("agent"))
827+
agent_supported = 1;
828+
824829
if (everything_local(&ref, nr_match, match)) {
825830
packet_flush(fd[1]);
826831
goto all_done;

builtin/send-pack.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ int send_pack(struct send_pack_args *args,
252252
int status_report = 0;
253253
int use_sideband = 0;
254254
int quiet_supported = 0;
255+
int agent_supported = 0;
255256
unsigned cmds_sent = 0;
256257
int ret;
257258
struct async demux;
@@ -267,6 +268,8 @@ int send_pack(struct send_pack_args *args,
267268
use_sideband = 1;
268269
if (server_supports("quiet"))
269270
quiet_supported = 1;
271+
if (server_supports("agent"))
272+
agent_supported = 1;
270273

271274
if (!remote_refs) {
272275
fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
@@ -306,14 +309,17 @@ int send_pack(struct send_pack_args *args,
306309
char *new_hex = sha1_to_hex(ref->new_sha1);
307310
int quiet = quiet_supported && (args->quiet || !args->progress);
308311

309-
if (!cmds_sent && (status_report || use_sideband || quiet)) {
312+
if (!cmds_sent && (status_report || use_sideband ||
313+
quiet || agent_supported)) {
310314
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",
312316
old_hex, new_hex, ref->name, 0,
313317
status_report ? " report-status" : "",
314318
use_sideband ? " side-band-64k" : "",
315319
quiet ? " quiet" : "",
316-
git_user_agent_sanitized());
320+
agent_supported ? " agent=" : "",
321+
agent_supported ? git_user_agent_sanitized() : ""
322+
);
317323
}
318324
else
319325
packet_buf_write(&req_buf, "%s %s %s",

0 commit comments

Comments
 (0)