{"thread":{"id":"12088","subject":"[PATCH 4/6] Refactor send-pack/receive-pack capability handshake for extension","startedAt":"2008-02-14T06:22:49Z","lastAt":"2008-02-14T06:22:49Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"68710","messageId":"20080214062249.GD30516@spearce.org","threadId":"12088","inReplyTo":null,"subject":"[PATCH 4/6] Refactor send-pack/receive-pack capability handshake for extension","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-02-14T06:22:49Z","receivedAt":"2008-02-14T06:22:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This refactors the capability selection in send-pack to be more\nlike how fetch-pack handles the transmission to the remote peer,\nso we can easily add additional capability strings to the push\nprotocol as needed.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-send-pack.c |   17 ++++++++---------\n receive-pack.c      |    3 ++-\n 2 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin-send-pack.c b/builtin-send-pack.c\nindex 8afb1d0..63fbcd2 100644\n--- a/builtin-send-pack.c\n+++ b/builtin-send-pack.c\n@@ -378,10 +378,10 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest\n {\n \tstruct ref *ref;\n \tint new_refs;\n-\tint ask_for_status_report = 0;\n \tint allow_deleting_refs = 0;\n \tint expect_status_report = 0;\n \tint flags = MATCH_REFS_NONE;\n+\tint pushing = 0;\n \tint ret;\n \n \tif (args.send_all)\n@@ -395,7 +395,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest\n \n \t/* Does the other end support the reporting? */\n \tif (server_supports(\"report-status\"))\n-\t\task_for_status_report = 1;\n+\t\texpect_status_report = 1;\n \tif (server_supports(\"delete-refs\"))\n \t\tallow_deleting_refs = 1;\n \n@@ -477,18 +477,17 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest\n \t\t\tchar *old_hex = sha1_to_hex(ref->old_sha1);\n \t\t\tchar *new_hex = sha1_to_hex(ref->new_sha1);\n \n-\t\t\tif (ask_for_status_report) {\n+\t\t\tif (!pushing)\n \t\t\t\tpacket_write(out, \"%s %s %s%c%s\",\n \t\t\t\t\told_hex, new_hex, ref->name, 0,\n-\t\t\t\t\t\"report-status\");\n-\t\t\t\task_for_status_report = 0;\n-\t\t\t\texpect_status_report = 1;\n-\t\t\t}\n+\t\t\t\t\t(expect_status_report ? \" report-status\" : \"\")\n+\t\t\t\t);\n \t\t\telse\n \t\t\t\tpacket_write(out, \"%s %s %s\",\n \t\t\t\t\told_hex, new_hex, ref->name);\n+\t\t\tpushing++;\n \t\t}\n-\t\tref->status = expect_status_report ?\n+\t\tref->status = pushing && expect_status_report ?\n \t\t\tREF_STATUS_EXPECTING_REPORT :\n \t\t\tREF_STATUS_OK;\n \t}\n@@ -502,7 +501,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest\n \t}\n \tclose(out);\n \n-\tif (expect_status_report)\n+\tif (pushing && expect_status_report)\n \t\tret = receive_status(in, remote_refs);\n \telse\n \t\tret = 0;\ndiff --git a/receive-pack.c b/receive-pack.c\nindex 3267495..7380395 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -318,7 +318,8 @@ static void read_head_info(void)\n \t\trefname = line + 82;\n \t\treflen = strlen(refname);\n \t\tif (reflen + 82 < len) {\n-\t\t\tif (strstr(refname + reflen + 1, \"report-status\"))\n+\t\t\tconst char *reqcap = refname + reflen + 1;\n+\t\t\tif (strstr(reqcap, \"report-status\"))\n \t\t\t\treport_status = 1;\n \t\t}\n \t\tcmd = xmalloc(sizeof(struct command) + len - 80);\n-- \n1.5.4.1.1309.g833c2\n"}]}