{"thread":{"id":"21244","subject":"[RFC PATCH v3 00/17] Return of smart HTTP","startedAt":"2009-10-15T03:36:37Z","lastAt":"2009-10-28T11:01:42Z","messageCount":52,"participants":["Shawn O. Pearce","Junio C Hamano","Nanako Shiraishi","Johan Herland","Mark Lodato","Tay Ray Chuan","Daniel Barkalow","Marcus Camen","Clemens Buchacher","Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":3,"patchTotal":17},"messages":[{"id":"125040","messageId":"1255577814-14745-1-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":null,"subject":"[RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:37Z","receivedAt":"2009-10-15T03:36:37Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This v3 series is a respin, and includes fixes to address reviewer\ncomments from v2.  The protocol specification is still omitted\nfrom the series as I have not yet had a chance to merge reviewer\ncomments into the draft.\n\nMajor changes from v2:\n\n  upload-pack:\n  * multi_ack_2 renamed multi_ack_detailed\n\n  helper:\n  * options are now global\n  * fetch is now a batch command (instead of fetch-multiple)\n  * ftp:// no longer tries info/refs?service=git-upload-pack\n\n  http-backend:\n  * manual page\n  * alternates files are now served as-is\n  * uses proper QUERY_STRING parsing\n  * GIT_COMMITTER_EMAIL set to REMOTE_USER, for receive-pack reflog\n  * receive-pack defaults to *ON* if REMOTE_USER is set\n\nThis series is still lacking:\n\n  * The HTTP protocol documentation\n  * Tests for the smart http transport code (existing tests pass)\n\nI don't want to rush reviews, but I'm fast running of time to work on\nthis series right now.  Next week I am offline for vacation... and\nthen its time for GitTogether '09.  I plan to work on tests for\nthis series and the HTTP spec document draft, but that's it until\nafter GitTogether '09.\n\n\nThese commits are also available at:\n\n  git://repo.or.cz/git/fastimport.git v3-smart-http\n\n\nShawn O. Pearce (17):\n  pkt-line: Add strbuf based functions\n  pkt-line: Make packet_read_line easier to debug\n  fetch-pack: Use a strbuf to compose the want list\n  Move \"get_ack()\" back to fetch-pack\n  Add multi_ack_detailed capability to fetch-pack/upload-pack\n  remote-curl: Refactor walker initialization\n  fetch: Allow transport -v -v -v to set verbosity to 3\n  remote-helpers: Fetch more than one ref in a batch\n  remote-helpers: Support custom transport options\n  Move WebDAV HTTP push under remote-curl\n  Git-aware CGI to provide dumb HTTP transport\n  Add stateless RPC options to upload-pack, receive-pack\n  Smart fetch and push over HTTP: server side\n  Discover refs via smart HTTP server when available\n  Smart push over HTTP: client side\n  Smart fetch over HTTP: client side\n  Smart HTTP fetch: gzip requests\n\n .gitignore                           |    1 +\n Documentation/config.txt             |    8 +\n Documentation/git-http-backend.txt   |  142 +++++++\n Documentation/git-remote-helpers.txt |   85 ++++-\n Makefile                             |    1 +\n builtin-fetch-pack.c                 |  210 ++++++++--\n builtin-fetch.c                      |    2 +-\n builtin-receive-pack.c               |   26 +-\n builtin-send-pack.c                  |  116 +++++-\n cache.h                              |    1 -\n commit.c                             |   10 +-\n commit.h                             |    2 +-\n connect.c                            |   21 -\n fetch-pack.h                         |    3 +-\n http-backend.c                       |  603 +++++++++++++++++++++++++++\n http-push.c                          |   43 ++-\n http.c                               |    9 +\n http.h                               |    1 +\n pkt-line.c                           |   86 ++++-\n pkt-line.h                           |    4 +\n remote-curl.c                        |  758 ++++++++++++++++++++++++++++++++--\n send-pack.h                          |    3 +-\n sideband.c                           |   11 +-\n transport-helper.c                   |  262 +++++++++++-\n transport.c                          |   32 +--\n transport.h                          |    2 +-\n upload-pack.c                        |   71 +++-\n 27 files changed, 2296 insertions(+), 217 deletions(-)\n create mode 100644 Documentation/git-http-backend.txt\n create mode 100644 http-backend.c\n"},{"id":"125042","messageId":"1255577814-14745-2-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 01/17] pkt-line: Add strbuf based functions","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:38Z","receivedAt":"2009-10-15T03:36:38Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"These routines help to work with pkt-line values inside of a strbuf,\npermitting simple formatting of buffered network messages.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n pkt-line.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++--------\n pkt-line.h |    4 +++\n 2 files changed, 76 insertions(+), 12 deletions(-)\n\ndiff --git a/pkt-line.c b/pkt-line.c\nindex b691abe..bd603f8 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -42,17 +42,19 @@ void packet_flush(int fd)\n \tsafe_write(fd, \"0000\", 4);\n }\n \n+void packet_buf_flush(struct strbuf *buf)\n+{\n+\tstrbuf_add(buf, \"0000\", 4);\n+}\n+\n #define hex(a) (hexchar[(a) & 15])\n-void packet_write(int fd, const char *fmt, ...)\n+static char buffer[1000];\n+static unsigned format_packet(const char *fmt, va_list args)\n {\n-\tstatic char buffer[1000];\n \tstatic char hexchar[] = \"0123456789abcdef\";\n-\tva_list args;\n \tunsigned n;\n \n-\tva_start(args, fmt);\n \tn = vsnprintf(buffer + 4, sizeof(buffer) - 4, fmt, args);\n-\tva_end(args);\n \tif (n >= sizeof(buffer)-4)\n \t\tdie(\"protocol error: impossibly long line\");\n \tn += 4;\n@@ -60,9 +62,31 @@ void packet_write(int fd, const char *fmt, ...)\n \tbuffer[1] = hex(n >> 8);\n \tbuffer[2] = hex(n >> 4);\n \tbuffer[3] = hex(n);\n+\treturn n;\n+}\n+\n+void packet_write(int fd, const char *fmt, ...)\n+{\n+\tva_list args;\n+\tunsigned n;\n+\n+\tva_start(args, fmt);\n+\tn = format_packet(fmt, args);\n+\tva_end(args);\n \tsafe_write(fd, buffer, n);\n }\n \n+void packet_buf_write(struct strbuf *buf, const char *fmt, ...)\n+{\n+\tva_list args;\n+\tunsigned n;\n+\n+\tva_start(args, fmt);\n+\tn = format_packet(fmt, args);\n+\tva_end(args);\n+\tstrbuf_add(buf, buffer, n);\n+}\n+\n static void safe_read(int fd, void *buffer, unsigned size)\n {\n \tssize_t ret = read_in_full(fd, buffer, size);\n@@ -72,15 +96,11 @@ static void safe_read(int fd, void *buffer, unsigned size)\n \t\tdie(\"The remote end hung up unexpectedly\");\n }\n \n-int packet_read_line(int fd, char *buffer, unsigned size)\n+static int packet_length(const char *linelen)\n {\n \tint n;\n-\tunsigned len;\n-\tchar linelen[4];\n-\n-\tsafe_read(fd, linelen, 4);\n+\tint len = 0;\n \n-\tlen = 0;\n \tfor (n = 0; n < 4; n++) {\n \t\tunsigned char c = linelen[n];\n \t\tlen <<= 4;\n@@ -96,8 +116,20 @@ int packet_read_line(int fd, char *buffer, unsigned size)\n \t\t\tlen += c - 'A' + 10;\n \t\t\tcontinue;\n \t\t}\n-\t\tdie(\"protocol error: bad line length character\");\n+\t\treturn -1;\n \t}\n+\treturn len;\n+}\n+\n+int packet_read_line(int fd, char *buffer, unsigned size)\n+{\n+\tint len;\n+\tchar linelen[4];\n+\n+\tsafe_read(fd, linelen, 4);\n+\tlen = packet_length(linelen);\n+\tif (len < 0)\n+\t\tdie(\"protocol error: bad line length character\");\n \tif (!len)\n \t\treturn 0;\n \tlen -= 4;\n@@ -107,3 +139,31 @@ int packet_read_line(int fd, char *buffer, unsigned size)\n \tbuffer[len] = 0;\n \treturn len;\n }\n+\n+int packet_get_line(struct strbuf *out,\n+\tchar **src_buf, size_t *src_len)\n+{\n+\tint len;\n+\n+\tif (*src_len < 4)\n+\t\treturn -1;\n+\tlen = packet_length(*src_buf);\n+\tif (len < 0)\n+\t\treturn -1;\n+\tif (!len) {\n+\t\t*src_buf += 4;\n+\t\t*src_len -= 4;\n+\t\treturn 0;\n+\t}\n+\tif (*src_len < len)\n+\t\treturn -2;\n+\n+\t*src_buf += 4;\n+\t*src_len -= 4;\n+\tlen -= 4;\n+\n+\tstrbuf_add(out, *src_buf, len);\n+\t*src_buf += len;\n+\t*src_len -= len;\n+\treturn len;\n+}\ndiff --git a/pkt-line.h b/pkt-line.h\nindex 9df653f..1e5dcfe 100644\n--- a/pkt-line.h\n+++ b/pkt-line.h\n@@ -2,14 +2,18 @@\n #define PKTLINE_H\n \n #include \"git-compat-util.h\"\n+#include \"strbuf.h\"\n \n /*\n  * Silly packetized line writing interface\n  */\n void packet_flush(int fd);\n void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));\n+void packet_buf_flush(struct strbuf *buf);\n+void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));\n \n int packet_read_line(int fd, char *buffer, unsigned size);\n+int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);\n ssize_t safe_write(int, const void *, ssize_t);\n \n #endif\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125041","messageId":"1255577814-14745-3-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 02/17] pkt-line: Make packet_read_line easier to debug","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:39Z","receivedAt":"2009-10-15T03:36:39Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"When there is an error parsing the 4 byte length component we now\nNUL terminate the string and display it as part of the die message,\nthis may hint as to what data was misunderstood by the application.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n pkt-line.c |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/pkt-line.c b/pkt-line.c\nindex bd603f8..893dd3c 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -124,12 +124,14 @@ static int packet_length(const char *linelen)\n int packet_read_line(int fd, char *buffer, unsigned size)\n {\n \tint len;\n-\tchar linelen[4];\n+\tchar linelen[5];\n \n \tsafe_read(fd, linelen, 4);\n \tlen = packet_length(linelen);\n-\tif (len < 0)\n-\t\tdie(\"protocol error: bad line length character\");\n+\tif (len < 0) {\n+\t\tlinelen[4] = '\\0';\n+\t\tdie(\"protocol error: bad line length character: %s\", linelen);\n+\t}\n \tif (!len)\n \t\treturn 0;\n \tlen -= 4;\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125044","messageId":"1255577814-14745-4-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 03/17] fetch-pack: Use a strbuf to compose the want list","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:40Z","receivedAt":"2009-10-15T03:36:40Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This change is being offered as a refactoring to make later\ncommits in the smart HTTP series easier.\n\nBy changing the enabled capabilities to be formatted in a strbuf\nit is easier to add a new capability to the set of supported\ncapabilities.\n\nBy formatting the want portion of the request into a strbuf and\nwriting it as a whole block we can later decide to hold onto\nthe req_buf (instead of releasing it) to recycle in stateless\ncommunications.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fetch-pack.c |   52 ++++++++++++++++++++++++++++++++-----------------\n commit.c             |   10 +++-----\n commit.h             |    2 +-\n 3 files changed, 39 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 629735f..783c2b0 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -165,6 +165,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \tconst unsigned char *sha1;\n \tunsigned in_vain = 0;\n \tint got_continue = 0;\n+\tstruct strbuf req_buf = STRBUF_INIT;\n \n \tif (marked)\n \t\tfor_each_ref(clear_marks, NULL);\n@@ -175,6 +176,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \tfetching = 0;\n \tfor ( ; refs ; refs = refs->next) {\n \t\tunsigned char *remote = refs->old_sha1;\n+\t\tconst char *remote_hex;\n \t\tstruct object *o;\n \n \t\t/*\n@@ -192,27 +194,36 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (!fetching)\n-\t\t\tpacket_write(fd[1], \"want %s%s%s%s%s%s%s%s\\n\",\n-\t\t\t\t     sha1_to_hex(remote),\n-\t\t\t\t     (multi_ack ? \" multi_ack\" : \"\"),\n-\t\t\t\t     (use_sideband == 2 ? \" side-band-64k\" : \"\"),\n-\t\t\t\t     (use_sideband == 1 ? \" side-band\" : \"\"),\n-\t\t\t\t     (args.use_thin_pack ? \" thin-pack\" : \"\"),\n-\t\t\t\t     (args.no_progress ? \" no-progress\" : \"\"),\n-\t\t\t\t     (args.include_tag ? \" include-tag\" : \"\"),\n-\t\t\t\t     (prefer_ofs_delta ? \" ofs-delta\" : \"\"));\n-\t\telse\n-\t\t\tpacket_write(fd[1], \"want %s\\n\", sha1_to_hex(remote));\n+\t\tremote_hex = sha1_to_hex(remote);\n+\t\tif (!fetching) {\n+\t\t\tstruct strbuf c = STRBUF_INIT;\n+\t\t\tif (multi_ack)          strbuf_addstr(&c, \" multi_ack\");\n+\t\t\tif (use_sideband == 2)  strbuf_addstr(&c, \" side-band-64k\");\n+\t\t\tif (use_sideband == 1)  strbuf_addstr(&c, \" side-band\");\n+\t\t\tif (args.use_thin_pack) strbuf_addstr(&c, \" thin-pack\");\n+\t\t\tif (args.no_progress)   strbuf_addstr(&c, \" no-progress\");\n+\t\t\tif (args.include_tag)   strbuf_addstr(&c, \" include-tag\");\n+\t\t\tif (prefer_ofs_delta)   strbuf_addstr(&c, \" ofs-delta\");\n+\t\t\tpacket_buf_write(&req_buf, \"want %s%s\\n\", remote_hex, c.buf);\n+\t\t\tstrbuf_release(&c);\n+\t\t} else\n+\t\t\tpacket_buf_write(&req_buf, \"want %s\\n\", remote_hex);\n \t\tfetching++;\n \t}\n+\n+\tif (!fetching) {\n+\t\tstrbuf_release(&req_buf);\n+\t\tpacket_flush(fd[1]);\n+\t\treturn 1;\n+\t}\n+\n \tif (is_repository_shallow())\n-\t\twrite_shallow_commits(fd[1], 1);\n+\t\twrite_shallow_commits(&req_buf, 1);\n \tif (args.depth > 0)\n-\t\tpacket_write(fd[1], \"deepen %d\", args.depth);\n-\tpacket_flush(fd[1]);\n-\tif (!fetching)\n-\t\treturn 1;\n+\t\tpacket_buf_write(&req_buf, \"deepen %d\", args.depth);\n+\tpacket_buf_flush(&req_buf);\n+\n+\tsafe_write(fd[1], req_buf.buf, req_buf.len);\n \n \tif (args.depth > 0) {\n \t\tchar line[1024];\n@@ -296,6 +307,8 @@ done:\n \t\tmulti_ack = 0;\n \t\tflushes++;\n \t}\n+\tstrbuf_release(&req_buf);\n+\n \twhile (flushes || multi_ack) {\n \t\tint ack = get_ack(fd[0], result_sha1);\n \t\tif (ack) {\n@@ -809,6 +822,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,\n \n \tif (args.depth > 0) {\n \t\tstruct cache_time mtime;\n+\t\tstruct strbuf sb = STRBUF_INIT;\n \t\tchar *shallow = git_path(\"shallow\");\n \t\tint fd;\n \n@@ -826,12 +840,14 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,\n \n \t\tfd = hold_lock_file_for_update(&lock, shallow,\n \t\t\t\t\t       LOCK_DIE_ON_ERROR);\n-\t\tif (!write_shallow_commits(fd, 0)) {\n+\t\tif (!write_shallow_commits(&sb, 0)\n+\t\t || write_in_full(fd, sb.buf, sb.len) != sb.len) {\n \t\t\tunlink_or_warn(shallow);\n \t\t\trollback_lock_file(&lock);\n \t\t} else {\n \t\t\tcommit_lock_file(&lock);\n \t\t}\n+\t\tstrbuf_release(&sb);\n \t}\n \n \treprepare_packed_git();\ndiff --git a/commit.c b/commit.c\nindex fedbd5e..471efb0 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -199,7 +199,7 @@ struct commit_graft *lookup_commit_graft(const unsigned char *sha1)\n \treturn commit_graft[pos];\n }\n \n-int write_shallow_commits(int fd, int use_pack_protocol)\n+int write_shallow_commits(struct strbuf *out, int use_pack_protocol)\n {\n \tint i, count = 0;\n \tfor (i = 0; i < commit_graft_nr; i++)\n@@ -208,12 +208,10 @@ int write_shallow_commits(int fd, int use_pack_protocol)\n \t\t\t\tsha1_to_hex(commit_graft[i]->sha1);\n \t\t\tcount++;\n \t\t\tif (use_pack_protocol)\n-\t\t\t\tpacket_write(fd, \"shallow %s\", hex);\n+\t\t\t\tpacket_buf_write(out, \"shallow %s\", hex);\n \t\t\telse {\n-\t\t\t\tif (write_in_full(fd, hex,  40) != 40)\n-\t\t\t\t\tbreak;\n-\t\t\t\tif (write_str_in_full(fd, \"\\n\") != 1)\n-\t\t\t\t\tbreak;\n+\t\t\t\tstrbuf_addstr(out, hex);\n+\t\t\t\tstrbuf_addch(out, '\\n');\n \t\t\t}\n \t\t}\n \treturn count;\ndiff --git a/commit.h b/commit.h\nindex f4fc5c5..817c75c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -131,7 +131,7 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);\n \n extern int register_shallow(const unsigned char *sha1);\n extern int unregister_shallow(const unsigned char *sha1);\n-extern int write_shallow_commits(int fd, int use_pack_protocol);\n+extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);\n extern int is_repository_shallow(void);\n extern struct commit_list *get_shallow_commits(struct object_array *heads,\n \t\tint depth, int shallow_flag, int not_shallow_flag);\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125043","messageId":"1255577814-14745-5-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 04/17] Move \"get_ack()\" back to fetch-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:41Z","receivedAt":"2009-10-15T03:36:41Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"In 41cb7488 Linus moved this function to connect.c for reuse inside\nof the git-clone-pack command.  That was 2005, but in 2006 Junio\nretired git-clone-pack in commit efc7fa53.  Since then the only\ncaller has been fetch-pack.  Since this ACK/NAK exchange is only\nused by the fetch-pack/upload-pack protocol we should keep move\nit back to a private detail of fetch-pack.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fetch-pack.c |   21 +++++++++++++++++++++\n cache.h              |    1 -\n connect.c            |   21 ---------------------\n 3 files changed, 21 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 783c2b0..7c09d46 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -157,6 +157,27 @@ static const unsigned char *get_rev(void)\n \treturn commit->object.sha1;\n }\n \n+static int get_ack(int fd, unsigned char *result_sha1)\n+{\n+\tstatic char line[1000];\n+\tint len = packet_read_line(fd, line, sizeof(line));\n+\n+\tif (!len)\n+\t\tdie(\"git fetch-pack: expected ACK/NAK, got EOF\");\n+\tif (line[len-1] == '\\n')\n+\t\tline[--len] = 0;\n+\tif (!strcmp(line, \"NAK\"))\n+\t\treturn 0;\n+\tif (!prefixcmp(line, \"ACK \")) {\n+\t\tif (!get_sha1_hex(line+4, result_sha1)) {\n+\t\t\tif (strstr(line+45, \"continue\"))\n+\t\t\t\treturn 2;\n+\t\t\treturn 1;\n+\t\t}\n+\t}\n+\tdie(\"git fetch_pack: expected ACK/NAK, got '%s'\", line);\n+}\n+\n static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t       struct ref *refs)\n {\ndiff --git a/cache.h b/cache.h\nindex a5eeead..4e283be 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -856,7 +856,6 @@ extern struct ref *find_ref_by_name(const struct ref *list, const char *name);\n extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);\n extern int finish_connect(struct child_process *conn);\n extern int path_match(const char *path, int nr, char **match);\n-extern int get_ack(int fd, unsigned char *result_sha1);\n struct extra_have_objects {\n \tint nr, alloc;\n \tunsigned char (*array)[20];\ndiff --git a/connect.c b/connect.c\nindex 7945e38..839a103 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -107,27 +107,6 @@ int server_supports(const char *feature)\n \t\tstrstr(server_capabilities, feature) != NULL;\n }\n \n-int get_ack(int fd, unsigned char *result_sha1)\n-{\n-\tstatic char line[1000];\n-\tint len = packet_read_line(fd, line, sizeof(line));\n-\n-\tif (!len)\n-\t\tdie(\"git fetch-pack: expected ACK/NAK, got EOF\");\n-\tif (line[len-1] == '\\n')\n-\t\tline[--len] = 0;\n-\tif (!strcmp(line, \"NAK\"))\n-\t\treturn 0;\n-\tif (!prefixcmp(line, \"ACK \")) {\n-\t\tif (!get_sha1_hex(line+4, result_sha1)) {\n-\t\t\tif (strstr(line+45, \"continue\"))\n-\t\t\t\treturn 2;\n-\t\t\treturn 1;\n-\t\t}\n-\t}\n-\tdie(\"git fetch_pack: expected ACK/NAK, got '%s'\", line);\n-}\n-\n int path_match(const char *path, int nr, char **match)\n {\n \tint i;\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125046","messageId":"1255577814-14745-6-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 05/17] Add multi_ack_detailed capability to fetch-pack/upload-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:42Z","receivedAt":"2009-10-15T03:36:42Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"When multi_ack_detailed is enabled the ACK continue messages returned\nby the remote upload-pack are broken out to describe the different\nstates within the peer.  This permits the client to better understand\nthe server's in-memory state.\n\nThe fetch-pack/upload-pack protocol now looks like:\n\nNAK\n---------------------------------\n  Always sent in response to \"done\" if there was no common base\n  selected from the \"have\" lines (or no have lines were sent).\n\n  * no multi_ack or multi_ack_detailed:\n\n    Sent when the client has sent a pkt-line flush (\"0000\") and\n    the server has not yet found a common base object.\n\n  * either multi_ack or multi_ack_detailed:\n\n    Always sent in response to a pkt-line flush.\n\nACK %s\n-----------------------------------\n  * no multi_ack or multi_ack_detailed:\n\n    Sent in response to \"have\" when the object exists on the remote\n    side and is therefore an object in common between the peers.\n    The argument is the SHA-1 of the common object.\n\n  * either multi_ack or multi_ack_detailed:\n\n    Sent in response to \"done\" if there are common objects.\n    The argument is the last SHA-1 determined to be common.\n\nACK %s continue\n-----------------------------------\n  * multi_ack only:\n\n    Sent in response to \"have\".\n\n    The remote side wants the client to consider this object as\n    common, and immediately stop transmitting additional \"have\"\n    lines for objects that are reachable from it.  The reason\n    the client should stop is not given, but is one of the two\n    cases below available under multi_ack_detailed.\n\nACK %s common\n-----------------------------------\n  * multi_ack_detailed only:\n\n    Sent in response to \"have\".  Both sides have this object.\n    Like with \"ACK %s continue\" above the client should stop\n    sending have lines reachable for objects from the argument.\n\nACK %s ready\n-----------------------------------\n  * multi_ack_detailed only:\n\n    Sent in response to \"have\".\n\n    The client should stop transmitting objects which are reachable\n    from the argument, and send \"done\" soon to get the objects.\n\n    If the remote side has the specified object, it should\n    first send an \"ACK %s common\" message prior to sending\n    \"ACK %s ready\".\n\n    Clients may still submit additional \"have\" lines if there are\n    more side branches for the client to explore that might be added\n    to the common set and reduce the number of objects to transfer.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fetch-pack.c |   41 ++++++++++++++++++++++++++++++++---------\n upload-pack.c        |   31 ++++++++++++++++++-------------\n 2 files changed, 50 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 7c09d46..615f549 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -157,7 +157,15 @@ static const unsigned char *get_rev(void)\n \treturn commit->object.sha1;\n }\n \n-static int get_ack(int fd, unsigned char *result_sha1)\n+enum ack_type {\n+\tNAK = 0,\n+\tACK,\n+\tACK_continue,\n+\tACK_common,\n+\tACK_ready\n+};\n+\n+static enum ack_type get_ack(int fd, unsigned char *result_sha1)\n {\n \tstatic char line[1000];\n \tint len = packet_read_line(fd, line, sizeof(line));\n@@ -167,12 +175,16 @@ static int get_ack(int fd, unsigned char *result_sha1)\n \tif (line[len-1] == '\\n')\n \t\tline[--len] = 0;\n \tif (!strcmp(line, \"NAK\"))\n-\t\treturn 0;\n+\t\treturn NAK;\n \tif (!prefixcmp(line, \"ACK \")) {\n \t\tif (!get_sha1_hex(line+4, result_sha1)) {\n \t\t\tif (strstr(line+45, \"continue\"))\n-\t\t\t\treturn 2;\n-\t\t\treturn 1;\n+\t\t\t\treturn ACK_continue;\n+\t\t\tif (strstr(line+45, \"common\"))\n+\t\t\t\treturn ACK_common;\n+\t\t\tif (strstr(line+45, \"ready\"))\n+\t\t\t\treturn ACK_ready;\n+\t\t\treturn ACK;\n \t\t}\n \t}\n \tdie(\"git fetch_pack: expected ACK/NAK, got '%s'\", line);\n@@ -218,7 +230,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\tremote_hex = sha1_to_hex(remote);\n \t\tif (!fetching) {\n \t\t\tstruct strbuf c = STRBUF_INIT;\n-\t\t\tif (multi_ack)          strbuf_addstr(&c, \" multi_ack\");\n+\t\t\tif (multi_ack == 2)     strbuf_addstr(&c, \" multi_ack_detailed\");\n+\t\t\tif (multi_ack == 1)     strbuf_addstr(&c, \" multi_ack\");\n \t\t\tif (use_sideband == 2)  strbuf_addstr(&c, \" side-band-64k\");\n \t\t\tif (use_sideband == 1)  strbuf_addstr(&c, \" side-band\");\n \t\t\tif (args.use_thin_pack) strbuf_addstr(&c, \" thin-pack\");\n@@ -298,18 +311,23 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t\t\tif (args.verbose && ack)\n \t\t\t\t\tfprintf(stderr, \"got ack %d %s\\n\", ack,\n \t\t\t\t\t\t\tsha1_to_hex(result_sha1));\n-\t\t\t\tif (ack == 1) {\n+\t\t\t\tswitch (ack) {\n+\t\t\t\tcase ACK:\n \t\t\t\t\tflushes = 0;\n \t\t\t\t\tmulti_ack = 0;\n \t\t\t\t\tretval = 0;\n \t\t\t\t\tgoto done;\n-\t\t\t\t} else if (ack == 2) {\n+\t\t\t\tcase ACK_common:\n+\t\t\t\tcase ACK_ready:\n+\t\t\t\tcase ACK_continue: {\n \t\t\t\t\tstruct commit *commit =\n \t\t\t\t\t\tlookup_commit(result_sha1);\n \t\t\t\t\tmark_common(commit, 0, 1);\n \t\t\t\t\tretval = 0;\n \t\t\t\t\tin_vain = 0;\n \t\t\t\t\tgot_continue = 1;\n+\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n \t\t\t\t}\n \t\t\t} while (ack);\n \t\t\tflushes--;\n@@ -336,7 +354,7 @@ done:\n \t\t\tif (args.verbose)\n \t\t\t\tfprintf(stderr, \"got ack (%d) %s\\n\", ack,\n \t\t\t\t\tsha1_to_hex(result_sha1));\n-\t\t\tif (ack == 1)\n+\t\t\tif (ack == ACK)\n \t\t\t\treturn 0;\n \t\t\tmulti_ack = 1;\n \t\t\tcontinue;\n@@ -618,7 +636,12 @@ static struct ref *do_fetch_pack(int fd[2],\n \n \tif (is_repository_shallow() && !server_supports(\"shallow\"))\n \t\tdie(\"Server does not support shallow clients\");\n-\tif (server_supports(\"multi_ack\")) {\n+\tif (server_supports(\"multi_ack_detailed\")) {\n+\t\tif (args.verbose)\n+\t\t\tfprintf(stderr, \"Server supports multi_ack_detailed\\n\");\n+\t\tmulti_ack = 2;\n+\t}\n+\telse if (server_supports(\"multi_ack\")) {\n \t\tif (args.verbose)\n \t\t\tfprintf(stderr, \"Server supports multi_ack\\n\");\n \t\tmulti_ack = 1;\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 38ddac2..f1dc3a3 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -498,7 +498,7 @@ static int get_common_commits(void)\n {\n \tstatic char line[1000];\n \tunsigned char sha1[20];\n-\tchar hex[41], last_hex[41];\n+\tchar last_hex[41];\n \n \tsave_commit_buffer = 0;\n \n@@ -515,19 +515,22 @@ static int get_common_commits(void)\n \t\tif (!prefixcmp(line, \"have \")) {\n \t\t\tswitch (got_sha1(line+5, sha1)) {\n \t\t\tcase -1: /* they have what we do not */\n-\t\t\t\tif (multi_ack && ok_to_give_up())\n-\t\t\t\t\tpacket_write(1, \"ACK %s continue\\n\",\n-\t\t\t\t\t\t     sha1_to_hex(sha1));\n+\t\t\t\tif (multi_ack && ok_to_give_up()) {\n+\t\t\t\t\tconst char *hex = sha1_to_hex(sha1);\n+\t\t\t\t\tif (multi_ack == 2)\n+\t\t\t\t\t\tpacket_write(1, \"ACK %s ready\\n\", hex);\n+\t\t\t\t\telse\n+\t\t\t\t\t\tpacket_write(1, \"ACK %s continue\\n\", hex);\n+\t\t\t\t}\n \t\t\t\tbreak;\n \t\t\tdefault:\n-\t\t\t\tmemcpy(hex, sha1_to_hex(sha1), 41);\n-\t\t\t\tif (multi_ack) {\n-\t\t\t\t\tconst char *msg = \"ACK %s continue\\n\";\n-\t\t\t\t\tpacket_write(1, msg, hex);\n-\t\t\t\t\tmemcpy(last_hex, hex, 41);\n-\t\t\t\t}\n+\t\t\t\tmemcpy(last_hex, sha1_to_hex(sha1), 41);\n+\t\t\t\tif (multi_ack == 2)\n+\t\t\t\t\tpacket_write(1, \"ACK %s common\\n\", last_hex);\n+\t\t\t\telse if (multi_ack)\n+\t\t\t\t\tpacket_write(1, \"ACK %s continue\\n\", last_hex);\n \t\t\t\telse if (have_obj.nr == 1)\n-\t\t\t\t\tpacket_write(1, \"ACK %s\\n\", hex);\n+\t\t\t\t\tpacket_write(1, \"ACK %s\\n\", last_hex);\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tcontinue;\n@@ -587,7 +590,9 @@ static void receive_needs(void)\n \t\t    get_sha1_hex(line+5, sha1_buf))\n \t\t\tdie(\"git upload-pack: protocol error, \"\n \t\t\t    \"expected to get sha, not '%s'\", line);\n-\t\tif (strstr(line+45, \"multi_ack\"))\n+\t\tif (strstr(line+45, \"multi_ack_detailed\"))\n+\t\t\tmulti_ack = 2;\n+\t\telse if (strstr(line+45, \"multi_ack\"))\n \t\t\tmulti_ack = 1;\n \t\tif (strstr(line+45, \"thin-pack\"))\n \t\t\tuse_thin_pack = 1;\n@@ -681,7 +686,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n {\n \tstatic const char *capabilities = \"multi_ack thin-pack side-band\"\n \t\t\" side-band-64k ofs-delta shallow no-progress\"\n-\t\t\" include-tag\";\n+\t\t\" include-tag multi_ack_detailed\";\n \tstruct object *o = parse_object(sha1);\n \n \tif (!o)\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125045","messageId":"1255577814-14745-7-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 06/17] remote-curl: Refactor walker initialization","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:43Z","receivedAt":"2009-10-15T03:36:43Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We will need the walker, url and remote in other functions as the\ncode grows larger to support smart HTTP.  Extract this out into a\nset of globals we can easily reference once configured.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n remote-curl.c |   24 ++++++++++++++----------\n 1 files changed, 14 insertions(+), 10 deletions(-)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 2faf1c6..478f3ea 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -5,7 +5,17 @@\n #include \"http.h\"\n #include \"exec_cmd.h\"\n \n-static struct ref *get_refs(struct walker *walker, const char *url)\n+static struct remote *remote;\n+static const char *url;\n+static struct walker *walker;\n+\n+static void init_walker(void)\n+{\n+\tif (!walker)\n+\t\twalker = get_http_walker(url, remote);\n+}\n+\n+static struct ref *get_refs(void)\n {\n \tstruct strbuf buffer = STRBUF_INIT;\n \tchar *data, *start, *mid;\n@@ -21,6 +31,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)\n \trefs_url = xmalloc(strlen(url) + 11);\n \tsprintf(refs_url, \"%s/info/refs\", url);\n \n+\tinit_walker();\n \thttp_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);\n \tswitch (http_ret) {\n \tcase HTTP_OK:\n@@ -78,10 +89,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)\n \n int main(int argc, const char **argv)\n {\n-\tstruct remote *remote;\n \tstruct strbuf buf = STRBUF_INIT;\n-\tconst char *url;\n-\tstruct walker *walker = NULL;\n \n \tgit_extract_argv0_path(argv[0]);\n \tsetup_git_directory();\n@@ -103,8 +111,7 @@ int main(int argc, const char **argv)\n \t\t\tbreak;\n \t\tif (!prefixcmp(buf.buf, \"fetch \")) {\n \t\t\tchar *obj = buf.buf + strlen(\"fetch \");\n-\t\t\tif (!walker)\n-\t\t\t\twalker = get_http_walker(url, remote);\n+\t\t\tinit_walker();\n \t\t\twalker->get_all = 1;\n \t\t\twalker->get_tree = 1;\n \t\t\twalker->get_history = 1;\n@@ -115,11 +122,8 @@ int main(int argc, const char **argv)\n \t\t\tprintf(\"\\n\");\n \t\t\tfflush(stdout);\n \t\t} else if (!strcmp(buf.buf, \"list\")) {\n-\t\t\tstruct ref *refs;\n+\t\t\tstruct ref *refs = get_refs();\n \t\t\tstruct ref *posn;\n-\t\t\tif (!walker)\n-\t\t\t\twalker = get_http_walker(url, remote);\n-\t\t\trefs = get_refs(walker, url);\n \t\t\tfor (posn = refs; posn; posn = posn->next) {\n \t\t\t\tif (posn->symref)\n \t\t\t\t\tprintf(\"@%s %s\\n\", posn->symref, posn->name);\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125057","messageId":"1255577814-14745-8-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 07/17] fetch: Allow transport -v -v -v to set verbosity to 3","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:44Z","receivedAt":"2009-10-15T03:36:44Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Helpers might want a higher level of verbosity than just +1 (the\nporcelain default setting) and +2 (-v -v).  Expand the field to\nallow verbosity in the range -1..3.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n builtin-fetch.c |    2 +-\n transport.h     |    2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex cb48c57..52a9a42 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -665,7 +665,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \n \ttransport = transport_get(remote, remote->url[0]);\n \tif (verbosity >= 2)\n-\t\ttransport->verbose = 1;\n+\t\ttransport->verbose = verbosity <= 3 ? verbosity : 3;\n \tif (verbosity < 0)\n \t\ttransport->verbose = -1;\n \tif (upload_pack)\ndiff --git a/transport.h b/transport.h\nindex c14da6f..e4e6177 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -25,7 +25,7 @@ struct transport {\n \n \tint (*disconnect)(struct transport *connection);\n \tchar *pack_lockfile;\n-\tsigned verbose : 2;\n+\tsigned verbose : 3;\n \t/* Force progress even if the output is not a tty */\n \tunsigned progress : 1;\n };\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125052","messageId":"1255577814-14745-9-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 08/17] remote-helpers: Fetch more than one ref in a batch","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:45Z","receivedAt":"2009-10-15T03:36:45Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Some network protocols (e.g. native git://) are able to fetch more\nthan one ref at a time and reduce the overall transfer cost by\ncombining the requests into a single exchange.  Instead of feeding\neach fetch request one at a time to the helper, feed all of them\nat once so the helper can decide whether or not it should batch them.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n Documentation/git-remote-helpers.txt |   14 ++++--\n remote-curl.c                        |   88 +++++++++++++++++++++++++++++----\n transport-helper.c                   |   39 +++++++++++----\n 3 files changed, 115 insertions(+), 26 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex 173ee23..e44d821 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -36,10 +36,16 @@ Commands are given by the caller on the helper's standard input, one per line.\n \tcomplete list, outputs a blank line.\n \n 'fetch' <sha1> <name>::\n-\tFetches the given object, writing the necessary objects to the\n-\tdatabase. Outputs a blank line when the fetch is\n-\tcomplete. Only objects which were reported in the ref list\n-\twith a sha1 may be fetched this way.\n+\tFetches the given object, writing the necessary objects\n+\tto the database.  Fetch commands are sent in a batch, one\n+\tper line, and the batch is terminated with a blank line.\n+\tOutputs a single blank line when all fetch commands in the\n+\tsame batch are complete. Only objects which were reported\n+\tin the ref list with a sha1 may be fetched this way.\n++\n+Optionally may output a 'lock <file>' line indicating a file under\n+GIT_DIR/objects/pack which is keeping a pack until refs can be\n+suitably updated.\n +\n Supported if the helper has the \"fetch\" capability.\n \ndiff --git a/remote-curl.c b/remote-curl.c\nindex 478f3ea..22cd5c5 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -87,6 +87,81 @@ static struct ref *get_refs(void)\n \treturn refs;\n }\n \n+static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n+{\n+\tchar **targets = xmalloc(nr_heads * sizeof(char*));\n+\tint ret, i;\n+\n+\tfor (i = 0; i < nr_heads; i++)\n+\t\ttargets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));\n+\n+\tinit_walker();\n+\twalker->get_all = 1;\n+\twalker->get_tree = 1;\n+\twalker->get_history = 1;\n+\twalker->get_verbosely = 0;\n+\twalker->get_recover = 0;\n+\tret = walker_fetch(walker, nr_heads, targets, NULL, NULL);\n+\n+\tfor (i = 0; i < nr_heads; i++)\n+\t\tfree(targets[i]);\n+\tfree(targets);\n+\n+\treturn ret ? error(\"Fetch failed.\") : 0;\n+}\n+\n+static void parse_fetch(struct strbuf *buf)\n+{\n+\tstruct ref **to_fetch = NULL;\n+\tstruct ref *list_head = NULL;\n+\tstruct ref **list = &list_head;\n+\tint alloc_heads = 0, nr_heads = 0;\n+\n+\tdo {\n+\t\tif (!prefixcmp(buf->buf, \"fetch \")) {\n+\t\t\tchar *p = buf->buf + strlen(\"fetch \");\n+\t\t\tchar *name;\n+\t\t\tstruct ref *ref;\n+\t\t\tunsigned char old_sha1[20];\n+\n+\t\t\tif (strlen(p) < 40 || get_sha1_hex(p, old_sha1))\n+\t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n+\t\t\tif (p[40] == ' ')\n+\t\t\t\tname = p + 41;\n+\t\t\telse if (!p[40])\n+\t\t\t\tname = \"\";\n+\t\t\telse\n+\t\t\t\tdie(\"protocol error: expected sha/ref, got %s'\", p);\n+\n+\t\t\tref = alloc_ref(name);\n+\t\t\thashcpy(ref->old_sha1, old_sha1);\n+\n+\t\t\t*list = ref;\n+\t\t\tlist = &ref->next;\n+\n+\t\t\tALLOC_GROW(to_fetch, nr_heads + 1, alloc_heads);\n+\t\t\tto_fetch[nr_heads++] = ref;\n+\t\t}\n+\t\telse\n+\t\t\tdie(\"http transport does not support %s\", buf->buf);\n+\n+\t\tstrbuf_reset(buf);\n+\t\tif (strbuf_getline(buf, stdin, '\\n') == EOF)\n+\t\t\treturn;\n+\t\tif (!*buf->buf)\n+\t\t\tbreak;\n+\t} while (1);\n+\n+\tif (fetch_dumb(nr_heads, to_fetch))\n+\t\texit(128); /* error already reported */\n+\tfree_refs(list_head);\n+\tfree(to_fetch);\n+\n+\tprintf(\"\\n\");\n+\tfflush(stdout);\n+\tstrbuf_reset(buf);\n+}\n+\n int main(int argc, const char **argv)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -110,17 +185,8 @@ int main(int argc, const char **argv)\n \t\tif (strbuf_getline(&buf, stdin, '\\n') == EOF)\n \t\t\tbreak;\n \t\tif (!prefixcmp(buf.buf, \"fetch \")) {\n-\t\t\tchar *obj = buf.buf + strlen(\"fetch \");\n-\t\t\tinit_walker();\n-\t\t\twalker->get_all = 1;\n-\t\t\twalker->get_tree = 1;\n-\t\t\twalker->get_history = 1;\n-\t\t\twalker->get_verbosely = 0;\n-\t\t\twalker->get_recover = 0;\n-\t\t\tif (walker_fetch(walker, 1, &obj, NULL, NULL))\n-\t\t\t\tdie(\"Fetch failed.\");\n-\t\t\tprintf(\"\\n\");\n-\t\t\tfflush(stdout);\n+\t\t\tparse_fetch(&buf);\n+\n \t\t} else if (!strcmp(buf.buf, \"list\")) {\n \t\t\tstruct ref *refs = get_refs();\n \t\t\tstruct ref *posn;\ndiff --git a/transport-helper.c b/transport-helper.c\nindex f57e84c..9de3408 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -10,6 +10,7 @@ struct helper_data\n {\n \tconst char *name;\n \tstruct child_process *helper;\n+\tFILE *out;\n \tunsigned fetch : 1;\n };\n \n@@ -18,7 +19,6 @@ static struct child_process *get_helper(struct transport *transport)\n \tstruct helper_data *data = transport->data;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct child_process *helper;\n-\tFILE *file;\n \n \tif (data->helper)\n \t\treturn data->helper;\n@@ -39,9 +39,9 @@ static struct child_process *get_helper(struct transport *transport)\n \n \twrite_str_in_full(helper->in, \"capabilities\\n\");\n \n-\tfile = xfdopen(helper->out, \"r\");\n+\tdata->out = xfdopen(helper->out, \"r\");\n \twhile (1) {\n-\t\tif (strbuf_getline(&buf, file, '\\n') == EOF)\n+\t\tif (strbuf_getline(&buf, data->out, '\\n') == EOF)\n \t\t\texit(128); /* child died, message supplied already */\n \n \t\tif (!*buf.buf)\n@@ -58,6 +58,7 @@ static int disconnect_helper(struct transport *transport)\n \tif (data->helper) {\n \t\twrite_str_in_full(data->helper->in, \"\\n\");\n \t\tclose(data->helper->in);\n+\t\tfclose(data->out);\n \t\tfinish_command(data->helper);\n \t\tfree((char *)data->helper->argv[0]);\n \t\tfree(data->helper->argv);\n@@ -70,8 +71,7 @@ static int disconnect_helper(struct transport *transport)\n static int fetch_with_fetch(struct transport *transport,\n \t\t\t    int nr_heads, const struct ref **to_fetch)\n {\n-\tstruct child_process *helper = get_helper(transport);\n-\tFILE *file = xfdopen(helper->out, \"r\");\n+\tstruct helper_data *data = transport->data;\n \tint i;\n \tstruct strbuf buf = STRBUF_INIT;\n \n@@ -82,12 +82,30 @@ static int fetch_with_fetch(struct transport *transport,\n \n \t\tstrbuf_addf(&buf, \"fetch %s %s\\n\",\n \t\t\t    sha1_to_hex(posn->old_sha1), posn->name);\n-\t\twrite_in_full(helper->in, buf.buf, buf.len);\n-\t\tstrbuf_reset(&buf);\n+\t}\n \n-\t\tif (strbuf_getline(&buf, file, '\\n') == EOF)\n+\tstrbuf_addch(&buf, '\\n');\n+\tif (write_in_full(data->helper->in, buf.buf, buf.len) != buf.len)\n+\t\tdie_errno(\"cannot send fetch to %s\", data->name);\n+\n+\twhile (1) {\n+\t\tstrbuf_reset(&buf);\n+\t\tif (strbuf_getline(&buf, data->out, '\\n') == EOF)\n \t\t\texit(128); /* child died, message supplied already */\n+\n+\t\tif (!prefixcmp(buf.buf, \"lock \")) {\n+\t\t\tconst char *name = buf.buf + 5;\n+\t\t\tif (transport->pack_lockfile)\n+\t\t\t\twarning(\"%s also locked %s\", data->name, name);\n+\t\t\telse\n+\t\t\t\ttransport->pack_lockfile = xstrdup(name);\n+\t\t}\n+\t\telse if (!buf.len)\n+\t\t\tbreak;\n+\t\telse\n+\t\t\twarning(\"%s unexpectedly said: '%s'\", data->name, buf.buf);\n \t}\n+\tstrbuf_release(&buf);\n \treturn 0;\n }\n \n@@ -113,21 +131,20 @@ static int fetch(struct transport *transport,\n \n static struct ref *get_refs_list(struct transport *transport, int for_push)\n {\n+\tstruct helper_data *data = transport->data;\n \tstruct child_process *helper;\n \tstruct ref *ret = NULL;\n \tstruct ref **tail = &ret;\n \tstruct ref *posn;\n \tstruct strbuf buf = STRBUF_INIT;\n-\tFILE *file;\n \n \thelper = get_helper(transport);\n \n \twrite_str_in_full(helper->in, \"list\\n\");\n \n-\tfile = xfdopen(helper->out, \"r\");\n \twhile (1) {\n \t\tchar *eov, *eon;\n-\t\tif (strbuf_getline(&buf, file, '\\n') == EOF)\n+\t\tif (strbuf_getline(&buf, data->out, '\\n') == EOF)\n \t\t\texit(128); /* child died, message supplied already */\n \n \t\tif (!*buf.buf)\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125056","messageId":"1255577814-14745-10-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 09/17] remote-helpers: Support custom transport options","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:46Z","receivedAt":"2009-10-15T03:36:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Some transports, like the native pack transport implemented by\nfetch-pack, support useful features like depth or include tags.\nThese should be exposed if the underlying helper knows how to\nuse them.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n Documentation/git-remote-helpers.txt |   38 +++++++++++++++\n remote-curl.c                        |   74 ++++++++++++++++++++++++++++-\n transport-helper.c                   |   88 +++++++++++++++++++++++++++++++++-\n 3 files changed, 198 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex e44d821..1133f04 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -35,6 +35,16 @@ Commands are given by the caller on the helper's standard input, one per line.\n \tthe name; unrecognized attributes are ignored. After the\n \tcomplete list, outputs a blank line.\n \n+'option' <name> <value>::\n+\tSet the transport helper option <name> to <value>.  Outputs a\n+\tsingle line containing one of 'ok' (option successfully set),\n+\t'unsupported' (option not recognized) or 'error <msg>'\n+\t(option <name> is supported but <value> is not correct\n+\tfor it).  Options should be set before other commands,\n+\tand may how those commands behave.\n++\n+Supported if the helper has the \"option\" capability.\n+\n 'fetch' <sha1> <name>::\n \tFetches the given object, writing the necessary objects\n \tto the database.  Fetch commands are sent in a batch, one\n@@ -63,11 +73,39 @@ CAPABILITIES\n 'fetch'::\n \tThis helper supports the 'fetch' command.\n \n+'option'::\n+\tThis helper supports the option command.\n+\n REF LIST ATTRIBUTES\n -------------------\n \n None are defined yet, but the caller must accept any which are supplied.\n \n+OPTIONS\n+-------\n+'option verbosity' <N>::\n+\tChange the level of messages displayed by the helper.\n+\tWhen N is 0 the end-user has asked the process to be\n+\tquiet, and the helper should produce only error output.\n+\tN of 1 is the default level of verbosity, higher values\n+\tof N correspond to the number of -v flags passed on the\n+\tcommand line.\n+\n+'option progress' \\{'true'|'false'\\}::\n+\tEnable (or disable) progress messages displayed by the\n+\ttransport helper during a command.\n+\n+'option depth' <depth>::\n+\tDeepen the history of a shallow repository.\n+\n+'option followtags' \\{'true'|'false'\\}::\n+\tIf enabled the helper should automatically fetch annotated\n+\ttag objects if the object the tag points at was transferred\n+\tduring the fetch command.  If the tag is not fetched by\n+\tthe helper a second fetch command will usually be sent to\n+\task for the tag specifically.  Some helpers may be able to\n+\tuse this option to avoid a second network connection.\n+\n Documentation\n -------------\n Documentation by Daniel Barkalow.\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 22cd5c5..0951f11 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -9,12 +9,61 @@ static struct remote *remote;\n static const char *url;\n static struct walker *walker;\n \n+struct options {\n+\tint verbosity;\n+\tunsigned long depth;\n+\tunsigned progress : 1,\n+\t\tfollowtags : 1;\n+};\n+static struct options options;\n+\n static void init_walker(void)\n {\n \tif (!walker)\n \t\twalker = get_http_walker(url, remote);\n }\n \n+static int set_option(const char *name, const char *value)\n+{\n+\tif (!strcmp(name, \"verbosity\")) {\n+\t\tchar *end;\n+\t\tint v = strtol(value, &end, 10);\n+\t\tif (value == end || *end)\n+\t\t\treturn -1;\n+\t\toptions.verbosity = v;\n+\t\treturn 0;\n+\t}\n+\telse if (!strcmp(name, \"progress\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.progress = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.progress = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 1 /* TODO implement later */;\n+\t}\n+\telse if (!strcmp(name, \"depth\")) {\n+\t\tchar *end;\n+\t\tunsigned long v = strtoul(value, &end, 10);\n+\t\tif (value == end || *end)\n+\t\t\treturn -1;\n+\t\toptions.depth = v;\n+\t\treturn 1 /* TODO implement later */;\n+\t}\n+\telse if (!strcmp(name, \"followtags\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.followtags = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.followtags = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 1 /* TODO implement later */;\n+\t}\n+\telse {\n+\t\treturn 1 /* unsupported */;\n+\t}\n+}\n+\n static struct ref *get_refs(void)\n {\n \tstruct strbuf buffer = STRBUF_INIT;\n@@ -99,7 +148,7 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n \twalker->get_all = 1;\n \twalker->get_tree = 1;\n \twalker->get_history = 1;\n-\twalker->get_verbosely = 0;\n+\twalker->get_verbosely = options.verbosity >= 3;\n \twalker->get_recover = 0;\n \tret = walker_fetch(walker, nr_heads, targets, NULL, NULL);\n \n@@ -173,6 +222,9 @@ int main(int argc, const char **argv)\n \t\treturn 1;\n \t}\n \n+\toptions.verbosity = 1;\n+\toptions.progress = !!isatty(2);\n+\n \tremote = remote_get(argv[1]);\n \n \tif (argc > 2) {\n@@ -198,8 +250,28 @@ int main(int argc, const char **argv)\n \t\t\t}\n \t\t\tprintf(\"\\n\");\n \t\t\tfflush(stdout);\n+\t\t} else if (!prefixcmp(buf.buf, \"option \")) {\n+\t\t\tchar *name = buf.buf + strlen(\"option \");\n+\t\t\tchar *value = strchr(name, ' ');\n+\t\t\tint result;\n+\n+\t\t\tif (value)\n+\t\t\t\t*value++ = '\\0';\n+\t\t\telse\n+\t\t\t\tvalue = \"true\";\n+\n+\t\t\tresult = set_option(name, value);\n+\t\t\tif (!result)\n+\t\t\t\tprintf(\"ok\\n\");\n+\t\t\telse if (result < 0)\n+\t\t\t\tprintf(\"error invalid value\\n\");\n+\t\t\telse\n+\t\t\t\tprintf(\"unsupported\\n\");\n+\t\t\tfflush(stdout);\n+\n \t\t} else if (!strcmp(buf.buf, \"capabilities\")) {\n \t\t\tprintf(\"fetch\\n\");\n+\t\t\tprintf(\"option\\n\");\n \t\t\tprintf(\"\\n\");\n \t\t\tfflush(stdout);\n \t\t} else {\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 9de3408..577abc6 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -5,13 +5,15 @@\n #include \"commit.h\"\n #include \"diff.h\"\n #include \"revision.h\"\n+#include \"quote.h\"\n \n struct helper_data\n {\n \tconst char *name;\n \tstruct child_process *helper;\n \tFILE *out;\n-\tunsigned fetch : 1;\n+\tunsigned fetch : 1,\n+\t\toption : 1;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -48,6 +50,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tbreak;\n \t\tif (!strcmp(buf.buf, \"fetch\"))\n \t\t\tdata->fetch = 1;\n+\t\tif (!strcmp(buf.buf, \"option\"))\n+\t\t\tdata->option = 1;\n \t}\n \treturn data->helper;\n }\n@@ -65,9 +69,88 @@ static int disconnect_helper(struct transport *transport)\n \t\tfree(data->helper);\n \t\tdata->helper = NULL;\n \t}\n+\tfree(data);\n \treturn 0;\n }\n \n+static const char *unsupported_options[] = {\n+\tTRANS_OPT_UPLOADPACK,\n+\tTRANS_OPT_RECEIVEPACK,\n+\tTRANS_OPT_THIN,\n+\tTRANS_OPT_KEEP\n+\t};\n+static const char *boolean_options[] = {\n+\tTRANS_OPT_THIN,\n+\tTRANS_OPT_KEEP,\n+\tTRANS_OPT_FOLLOWTAGS\n+\t};\n+\n+static int set_helper_option(struct transport *transport,\n+\t\t\t  const char *name, const char *value)\n+{\n+\tstruct helper_data *data = transport->data;\n+\tstruct child_process *helper = get_helper(transport);\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint i, ret, is_bool = 0;\n+\n+\tif (!data->option)\n+\t\treturn 1;\n+\n+\tfor (i = 0; i < ARRAY_SIZE(unsupported_options); i++) {\n+\t\tif (!strcmp(name, unsupported_options[i]))\n+\t\t\treturn 1;\n+\t}\n+\n+\tfor (i = 0; i < ARRAY_SIZE(boolean_options); i++) {\n+\t\tif (!strcmp(name, boolean_options[i])) {\n+\t\t\tis_bool = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tstrbuf_addf(&buf, \"option %s \", name);\n+\tif (is_bool)\n+\t\tstrbuf_addstr(&buf, value ? \"true\" : \"false\");\n+\telse\n+\t\tquote_c_style(value, &buf, NULL, 0);\n+\tstrbuf_addch(&buf, '\\n');\n+\n+\tif (write_in_full(helper->in, buf.buf, buf.len) != buf.len)\n+\t\tdie_errno(\"cannot send option to %s\", data->name);\n+\n+\tstrbuf_reset(&buf);\n+\tif (strbuf_getline(&buf, data->out, '\\n') == EOF)\n+\t\texit(128); /* child died, message supplied already */\n+\n+\tif (!strcmp(buf.buf, \"ok\"))\n+\t\tret = 0;\n+\telse if (!prefixcmp(buf.buf, \"error\")) {\n+\t\tret = -1;\n+\t} else if (!strcmp(buf.buf, \"unsupported\"))\n+\t\tret = 1;\n+\telse {\n+\t\twarning(\"%s unexpectedly said: '%s'\", data->name, buf.buf);\n+\t\tret = 1;\n+\t}\n+\tstrbuf_release(&buf);\n+\treturn ret;\n+}\n+\n+static void standard_options(struct transport *t)\n+{\n+\tchar buf[16];\n+\tint n;\n+\tint v = t->verbose;\n+\tint no_progress = v < 0 || (!t->progress && !isatty(1));\n+\n+\tset_helper_option(t, \"progress\", !no_progress ? \"true\" : \"false\");\n+\n+\tn = snprintf(buf, sizeof(buf), \"%d\", v + 1);\n+\tif (n >= sizeof(buf))\n+\t\tdie(\"impossibly large verbosity value\");\n+\tset_helper_option(t, \"verbosity\", buf);\n+}\n+\n static int fetch_with_fetch(struct transport *transport,\n \t\t\t    int nr_heads, const struct ref **to_fetch)\n {\n@@ -75,6 +158,8 @@ static int fetch_with_fetch(struct transport *transport,\n \tint i;\n \tstruct strbuf buf = STRBUF_INIT;\n \n+\tstandard_options(transport);\n+\n \tfor (i = 0; i < nr_heads; i++) {\n \t\tconst struct ref *posn = to_fetch[i];\n \t\tif (posn->status & REF_STATUS_UPTODATE)\n@@ -178,6 +263,7 @@ int transport_helper_init(struct transport *transport, const char *name)\n \tdata->name = name;\n \n \ttransport->data = data;\n+\ttransport->set_option = set_helper_option;\n \ttransport->get_refs_list = get_refs_list;\n \ttransport->fetch = fetch;\n \ttransport->disconnect = disconnect_helper;\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125050","messageId":"1255577814-14745-11-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 10/17] Move WebDAV HTTP push under remote-curl","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:47Z","receivedAt":"2009-10-15T03:36:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The remote helper interface now supports the push capability,\nwhich can be used to ask the implementation to push one or more\nspecs to the remote repository.  For remote-curl we implement this\nby calling the existing WebDAV based git-http-push executable.\n\nInternally the helper interface uses the push_refs transport hook\nso that the complexity of the refspec parsing and matching can be\nreused between remote implementations.  When possible however the\nhelper protocol uses source ref name rather than the source SHA-1,\nthereby allowing the helper to access this name if it is useful.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\nCC: Tay Ray Chuan <rctay89@gmail.com>\nCC: Mike Hommey <mh@glandium.org>\n---\n Documentation/git-remote-helpers.txt |   33 ++++++++-\n http-push.c                          |   43 ++++++++---\n remote-curl.c                        |   98 +++++++++++++++++++++---\n transport-helper.c                   |  137 +++++++++++++++++++++++++++++++++-\n transport.c                          |   31 --------\n 5 files changed, 286 insertions(+), 56 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex 1133f04..3751b12 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -34,6 +34,10 @@ Commands are given by the caller on the helper's standard input, one per line.\n \tvalue of the ref. A space-separated list of attributes follows\n \tthe name; unrecognized attributes are ignored. After the\n \tcomplete list, outputs a blank line.\n++\n+If 'push' is supported this may be called as 'list for-push'\n+to obtain the current refs prior to sending one or more 'push'\n+commands to the helper.\n \n 'option' <name> <value>::\n \tSet the transport helper option <name> to <value>.  Outputs a\n@@ -59,6 +63,22 @@ suitably updated.\n +\n Supported if the helper has the \"fetch\" capability.\n \n+'push' +<src>:<dst>::\n+\tPushes the given <src> commit or branch locally to the\n+\tremote branch described by <dst>.  A batch sequence of\n+\tone or more push commands is terminated with a blank line.\n++\n+Zero or more protocol options may be entered after the last 'push'\n+command, before the batch's terminating blank line.\n++\n+When the push is complete, outputs one or more 'ok <dst>' or\n+'error <dst> <why>?' lines to indicate success or failure of\n+each pushed ref.  The status report output is terminated by\n+a blank line.  The option field <why> may be quoted in a C\n+style string if it contains an LF.\n++\n+Supported if the helper has the \"push\" capability.\n+\n If a fatal error occurs, the program writes the error message to\n stderr and exits. The caller should expect that a suitable error\n message has been printed if the child closes the connection without\n@@ -76,10 +96,16 @@ CAPABILITIES\n 'option'::\n \tThis helper supports the option command.\n \n+'push'::\n+\tThis helper supports the 'push' command.\n+\n REF LIST ATTRIBUTES\n -------------------\n \n-None are defined yet, but the caller must accept any which are supplied.\n+'for-push'::\n+\tThe caller wants to use the ref list to prepare push\n+\tcommands.  A helper might chose to acquire the ref list by\n+\topening a different type of connection to the destination.\n \n OPTIONS\n -------\n@@ -106,6 +132,11 @@ OPTIONS\n \task for the tag specifically.  Some helpers may be able to\n \tuse this option to avoid a second network connection.\n \n+'option dry-run' \\{'true'|'false'\\}:\n+\tIf true, pretend like the operation completed successfully,\n+\tbut don't actually change any repository data.\tFor most\n+\thelpers this only applies to the 'push', if supported.\n+\n Documentation\n -------------\n Documentation by Daniel Barkalow.\ndiff --git a/http-push.c b/http-push.c\nindex 00e83dc..9010ccc 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -78,6 +78,7 @@ static int push_verbosely;\n static int push_all = MATCH_REFS_NONE;\n static int force_all;\n static int dry_run;\n+static int helper_status;\n \n static struct object_list *objects;\n \n@@ -1813,6 +1814,10 @@ int main(int argc, char **argv)\n \t\t\t\tdry_run = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--helper-status\")) {\n+\t\t\t\thelper_status = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--verbose\")) {\n \t\t\t\tpush_verbosely = 1;\n \t\t\t\thttp_is_verbose = 1;\n@@ -1941,9 +1946,14 @@ int main(int argc, char **argv)\n \n \t\tif (is_null_sha1(ref->peer_ref->new_sha1)) {\n \t\t\tif (delete_remote_branch(ref->name, 1) == -1) {\n-\t\t\t\terror(\"Could not remove %s\", ref->name);\n+\t\t\t\tif (helper_status)\n+\t\t\t\t\tprintf(\"error %s cannot remove\\n\", ref->name);\n+\t\t\t\telse\n+\t\t\t\t\terror(\"Could not remove %s\", ref->name);\n \t\t\t\trc = -4;\n \t\t\t}\n+\t\t\telse if (helper_status)\n+\t\t\t\tprintf(\"ok %s\\n\", ref->name);\n \t\t\tnew_refs++;\n \t\t\tcontinue;\n \t\t}\n@@ -1951,6 +1961,8 @@ int main(int argc, char **argv)\n \t\tif (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {\n \t\t\tif (push_verbosely || 1)\n \t\t\t\tfprintf(stderr, \"'%s': up-to-date\\n\", ref->name);\n+\t\t\tif (helper_status)\n+\t\t\t\tprintf(\"ok %s up to date\\n\", ref->name);\n \t\t\tcontinue;\n \t\t}\n \n@@ -1968,12 +1980,15 @@ int main(int argc, char **argv)\n \t\t\t\t * commits at the remote end and likely\n \t\t\t\t * we were not up to date to begin with.\n \t\t\t\t */\n-\t\t\t\terror(\"remote '%s' is not an ancestor of\\n\"\n-\t\t\t\t      \"local '%s'.\\n\"\n-\t\t\t\t      \"Maybe you are not up-to-date and \"\n-\t\t\t\t      \"need to pull first?\",\n-\t\t\t\t      ref->name,\n-\t\t\t\t      ref->peer_ref->name);\n+\t\t\t\tif (helper_status)\n+\t\t\t\t\tprintf(\"error %s non-fast forward\\n\", ref->name);\n+\t\t\t\telse\n+\t\t\t\t\terror(\"remote '%s' is not an ancestor of\\n\"\n+\t\t\t\t\t\t  \"local '%s'.\\n\"\n+\t\t\t\t\t\t  \"Maybe you are not up-to-date and \"\n+\t\t\t\t\t\t  \"need to pull first?\",\n+\t\t\t\t\t\t  ref->name,\n+\t\t\t\t\t\t  ref->peer_ref->name);\n \t\t\t\trc = -2;\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -1987,14 +2002,20 @@ int main(int argc, char **argv)\n \t\tif (strcmp(ref->name, ref->peer_ref->name))\n \t\t\tfprintf(stderr, \" using '%s'\", ref->peer_ref->name);\n \t\tfprintf(stderr, \"\\n  from %s\\n  to   %s\\n\", old_hex, new_hex);\n-\t\tif (dry_run)\n+\t\tif (dry_run) {\n+\t\t\tif (helper_status)\n+\t\t\t\tprintf(\"ok %s\\n\", ref->name);\n \t\t\tcontinue;\n+\t\t}\n \n \t\t/* Lock remote branch ref */\n \t\tref_lock = lock_remote(ref->name, LOCK_TIME);\n \t\tif (ref_lock == NULL) {\n-\t\t\tfprintf(stderr, \"Unable to lock remote branch %s\\n\",\n-\t\t\t\tref->name);\n+\t\t\tif (helper_status)\n+\t\t\t\tprintf(\"error %s lock error\\n\", ref->name);\n+\t\t\telse\n+\t\t\t\tfprintf(stderr, \"Unable to lock remote branch %s\\n\",\n+\t\t\t\t\tref->name);\n \t\t\trc = 1;\n \t\t\tcontinue;\n \t\t}\n@@ -2045,6 +2066,8 @@ int main(int argc, char **argv)\n \n \t\tif (!rc)\n \t\t\tfprintf(stderr, \"    done\\n\");\n+\t\tif (helper_status)\n+\t\t\tprintf(\"%s %s\\n\", !rc ? \"ok\" : \"error\", ref->name);\n \t\tunlock_remote(ref_lock);\n \t\tcheck_locks();\n \t}\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 0951f11..af2fddf 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -4,6 +4,7 @@\n #include \"walker.h\"\n #include \"http.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n \n static struct remote *remote;\n static const char *url;\n@@ -13,7 +14,8 @@ struct options {\n \tint verbosity;\n \tunsigned long depth;\n \tunsigned progress : 1,\n-\t\tfollowtags : 1;\n+\t\tfollowtags : 1,\n+\t\tdry_run : 1;\n };\n static struct options options;\n \n@@ -59,6 +61,15 @@ static int set_option(const char *name, const char *value)\n \t\t\treturn -1;\n \t\treturn 1 /* TODO implement later */;\n \t}\n+\telse if (!strcmp(name, \"dry-run\")) {\n+\t\tif (!strcmp(value, \"true\"))\n+\t\t\toptions.dry_run = 1;\n+\t\telse if (!strcmp(value, \"false\"))\n+\t\t\toptions.dry_run = 0;\n+\t\telse\n+\t\t\treturn -1;\n+\t\treturn 0;\n+\t}\n \telse {\n \t\treturn 1 /* unsupported */;\n \t}\n@@ -136,6 +147,20 @@ static struct ref *get_refs(void)\n \treturn refs;\n }\n \n+static void output_refs(struct ref *refs)\n+{\n+\tstruct ref *posn;\n+\tfor (posn = refs; posn; posn = posn->next) {\n+\t\tif (posn->symref)\n+\t\t\tprintf(\"@%s %s\\n\", posn->symref, posn->name);\n+\t\telse\n+\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(posn->old_sha1), posn->name);\n+\t}\n+\tprintf(\"\\n\");\n+\tfflush(stdout);\n+\tfree_refs(refs);\n+}\n+\n static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n {\n \tchar **targets = xmalloc(nr_heads * sizeof(char*));\n@@ -211,6 +236,58 @@ static void parse_fetch(struct strbuf *buf)\n \tstrbuf_reset(buf);\n }\n \n+static int push_dav(int nr_spec, char **specs)\n+{\n+\tconst char **argv = xmalloc((10 + nr_spec) * sizeof(char*));\n+\tint argc = 0, i;\n+\n+\targv[argc++] = \"http-push\";\n+\targv[argc++] = \"--helper-status\";\n+\tif (options.dry_run)\n+\t\targv[argc++] = \"--dry-run\";\n+\tif (options.verbosity > 1)\n+\t\targv[argc++] = \"--verbose\";\n+\targv[argc++] = url;\n+\tfor (i = 0; i < nr_spec; i++)\n+\t\targv[argc++] = specs[i];\n+\targv[argc++] = NULL;\n+\n+\tif (run_command_v_opt(argv, RUN_GIT_CMD))\n+\t\tdie(\"git-%s failed\", argv[0]);\n+\tfree(argv);\n+\treturn 0;\n+}\n+\n+static void parse_push(struct strbuf *buf)\n+{\n+\tchar **specs = NULL;\n+\tint alloc_spec = 0, nr_spec = 0, i;\n+\n+\tdo {\n+\t\tif (!prefixcmp(buf->buf, \"push \")) {\n+\t\t\tALLOC_GROW(specs, nr_spec + 1, alloc_spec);\n+\t\t\tspecs[nr_spec++] = xstrdup(buf->buf + 5);\n+\t\t}\n+\t\telse\n+\t\t\tdie(\"http transport does not support %s\", buf->buf);\n+\n+\t\tstrbuf_reset(buf);\n+\t\tif (strbuf_getline(buf, stdin, '\\n') == EOF)\n+\t\t\treturn;\n+\t\tif (!*buf->buf)\n+\t\t\tbreak;\n+\t} while (1);\n+\n+\tif (push_dav(nr_spec, specs))\n+\t\texit(128); /* error already reported */\n+\tfor (i = 0; i < nr_spec; i++)\n+\t\tfree(specs[i]);\n+\tfree(specs);\n+\n+\tprintf(\"\\n\");\n+\tfflush(stdout);\n+}\n+\n int main(int argc, const char **argv)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -240,16 +317,14 @@ int main(int argc, const char **argv)\n \t\t\tparse_fetch(&buf);\n \n \t\t} else if (!strcmp(buf.buf, \"list\")) {\n-\t\t\tstruct ref *refs = get_refs();\n-\t\t\tstruct ref *posn;\n-\t\t\tfor (posn = refs; posn; posn = posn->next) {\n-\t\t\t\tif (posn->symref)\n-\t\t\t\t\tprintf(\"@%s %s\\n\", posn->symref, posn->name);\n-\t\t\t\telse\n-\t\t\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(posn->old_sha1), posn->name);\n-\t\t\t}\n-\t\t\tprintf(\"\\n\");\n-\t\t\tfflush(stdout);\n+\t\t\toutput_refs(get_refs());\n+\n+\t\t} else if (!strcmp(buf.buf, \"list for-push\")) {\n+\t\t\toutput_refs(get_refs());\n+\n+\t\t} else if (!prefixcmp(buf.buf, \"push \")) {\n+\t\t\tparse_push(&buf);\n+\n \t\t} else if (!prefixcmp(buf.buf, \"option \")) {\n \t\t\tchar *name = buf.buf + strlen(\"option \");\n \t\t\tchar *value = strchr(name, ' ');\n@@ -272,6 +347,7 @@ int main(int argc, const char **argv)\n \t\t} else if (!strcmp(buf.buf, \"capabilities\")) {\n \t\t\tprintf(\"fetch\\n\");\n \t\t\tprintf(\"option\\n\");\n+\t\t\tprintf(\"push\\n\");\n \t\t\tprintf(\"\\n\");\n \t\t\tfflush(stdout);\n \t\t} else {\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 577abc6..16c6641 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -1,6 +1,6 @@\n #include \"cache.h\"\n #include \"transport.h\"\n-\n+#include \"quote.h\"\n #include \"run-command.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n@@ -13,7 +13,8 @@ struct helper_data\n \tstruct child_process *helper;\n \tFILE *out;\n \tunsigned fetch : 1,\n-\t\toption : 1;\n+\t\toption : 1,\n+\t\tpush : 1;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -52,6 +53,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->fetch = 1;\n \t\tif (!strcmp(buf.buf, \"option\"))\n \t\t\tdata->option = 1;\n+\t\tif (!strcmp(buf.buf, \"push\"))\n+\t\t\tdata->push = 1;\n \t}\n \treturn data->helper;\n }\n@@ -214,6 +217,130 @@ static int fetch(struct transport *transport,\n \treturn -1;\n }\n \n+static int push_refs(struct transport *transport,\n+\t\tstruct ref *remote_refs, int flags)\n+{\n+\tint force_all = flags & TRANSPORT_PUSH_FORCE;\n+\tint mirror = flags & TRANSPORT_PUSH_MIRROR;\n+\tstruct helper_data *data = transport->data;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct child_process *helper;\n+\tstruct ref *ref;\n+\n+\tif (!remote_refs)\n+\t\treturn 0;\n+\n+\thelper = get_helper(transport);\n+\tif (!data->push)\n+\t\treturn 1;\n+\n+\tfor (ref = remote_refs; ref; ref = ref->next) {\n+\t\tif (ref->peer_ref)\n+\t\t\thashcpy(ref->new_sha1, ref->peer_ref->new_sha1);\n+\t\telse if (!mirror)\n+\t\t\tcontinue;\n+\n+\t\tref->deletion = is_null_sha1(ref->new_sha1);\n+\t\tif (!ref->deletion &&\n+\t\t\t!hashcmp(ref->old_sha1, ref->new_sha1)) {\n+\t\t\tref->status = REF_STATUS_UPTODATE;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tif (force_all)\n+\t\t\tref->force = 1;\n+\n+\t\tstrbuf_addstr(&buf, \"push \");\n+\t\tif (!ref->deletion) {\n+\t\t\tif (ref->force)\n+\t\t\t\tstrbuf_addch(&buf, '+');\n+\t\t\tif (ref->peer_ref)\n+\t\t\t\tstrbuf_addstr(&buf, ref->peer_ref->name);\n+\t\t\telse\n+\t\t\t\tstrbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));\n+\t\t}\n+\t\tstrbuf_addch(&buf, ':');\n+\t\tstrbuf_addstr(&buf, ref->name);\n+\t\tstrbuf_addch(&buf, '\\n');\n+\t}\n+\n+\ttransport->verbose = flags & TRANSPORT_PUSH_VERBOSE ? 1 : 0;\n+\tstandard_options(transport);\n+\n+\tif (flags & TRANSPORT_PUSH_DRY_RUN) {\n+\t\tif (set_helper_option(transport, \"dry-run\", \"true\") != 0)\n+\t\t\tdie(\"helper %s does not support dry-run\", data->name);\n+\t}\n+\n+\tstrbuf_addch(&buf, '\\n');\n+\tif (write_in_full(helper->in, buf.buf, buf.len) != buf.len)\n+\t\texit(128);\n+\n+\tref = remote_refs;\n+\twhile (1) {\n+\t\tchar *refname, *msg;\n+\t\tint status;\n+\n+\t\tstrbuf_reset(&buf);\n+\t\tif (strbuf_getline(&buf, data->out, '\\n') == EOF)\n+\t\t\texit(128); /* child died, message supplied already */\n+\t\tif (!buf.len)\n+\t\t\tbreak;\n+\n+\t\tif (!prefixcmp(buf.buf, \"ok \")) {\n+\t\t\tstatus = REF_STATUS_OK;\n+\t\t\trefname = buf.buf + 3;\n+\t\t} else if (!prefixcmp(buf.buf, \"error \")) {\n+\t\t\tstatus = REF_STATUS_REMOTE_REJECT;\n+\t\t\trefname = buf.buf + 6;\n+\t\t} else\n+\t\t\tdie(\"expected ok/error, helper said '%s'\\n\", buf.buf);\n+\n+\t\tmsg = strchr(refname, ' ');\n+\t\tif (msg) {\n+\t\t\tstruct strbuf msg_buf = STRBUF_INIT;\n+\t\t\tconst char *end;\n+\n+\t\t\t*msg++ = '\\0';\n+\t\t\tif (!unquote_c_style(&msg_buf, msg, &end))\n+\t\t\t\tmsg = strbuf_detach(&msg_buf, NULL);\n+\t\t\telse\n+\t\t\t\tmsg = xstrdup(msg);\n+\t\t\tstrbuf_release(&msg_buf);\n+\n+\t\t\tif (!strcmp(msg, \"no match\")) {\n+\t\t\t\tstatus = REF_STATUS_NONE;\n+\t\t\t\tfree(msg);\n+\t\t\t\tmsg = NULL;\n+\t\t\t}\n+\t\t\telse if (!strcmp(msg, \"up to date\")) {\n+\t\t\t\tstatus = REF_STATUS_UPTODATE;\n+\t\t\t\tfree(msg);\n+\t\t\t\tmsg = NULL;\n+\t\t\t}\n+\t\t\telse if (!strcmp(msg, \"non-fast forward\")) {\n+\t\t\t\tstatus = REF_STATUS_REJECT_NONFASTFORWARD;\n+\t\t\t\tfree(msg);\n+\t\t\t\tmsg = NULL;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (ref)\n+\t\t\tref = find_ref_by_name(ref, refname);\n+\t\tif (!ref)\n+\t\t\tref = find_ref_by_name(remote_refs, refname);\n+\t\tif (!ref) {\n+\t\t\twarning(\"helper reported unexpected status of %s\", refname);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tref->status = status;\n+\t\tref->remote_status = msg;\n+\t}\n+\tstrbuf_release(&buf);\n+\treturn 0;\n+}\n+\n static struct ref *get_refs_list(struct transport *transport, int for_push)\n {\n \tstruct helper_data *data = transport->data;\n@@ -225,7 +352,10 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)\n \n \thelper = get_helper(transport);\n \n-\twrite_str_in_full(helper->in, \"list\\n\");\n+\tif (data->push && for_push)\n+\t\twrite_str_in_full(helper->in, \"list for-push\\n\");\n+\telse\n+\t\twrite_str_in_full(helper->in, \"list\\n\");\n \n \twhile (1) {\n \t\tchar *eov, *eon;\n@@ -266,6 +396,7 @@ int transport_helper_init(struct transport *transport, const char *name)\n \ttransport->set_option = set_helper_option;\n \ttransport->get_refs_list = get_refs_list;\n \ttransport->fetch = fetch;\n+\ttransport->push_refs = push_refs;\n \ttransport->disconnect = disconnect_helper;\n \treturn 0;\n }\ndiff --git a/transport.c b/transport.c\nindex 644a30a..6d9652d 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -349,35 +349,6 @@ static int rsync_transport_push(struct transport *transport,\n \treturn result;\n }\n \n-#ifndef NO_CURL\n-static int curl_transport_push(struct transport *transport, int refspec_nr, const char **refspec, int flags)\n-{\n-\tconst char **argv;\n-\tint argc;\n-\n-\tif (flags & TRANSPORT_PUSH_MIRROR)\n-\t\treturn error(\"http transport does not support mirror mode\");\n-\n-\targv = xmalloc((refspec_nr + 12) * sizeof(char *));\n-\targv[0] = \"http-push\";\n-\targc = 1;\n-\tif (flags & TRANSPORT_PUSH_ALL)\n-\t\targv[argc++] = \"--all\";\n-\tif (flags & TRANSPORT_PUSH_FORCE)\n-\t\targv[argc++] = \"--force\";\n-\tif (flags & TRANSPORT_PUSH_DRY_RUN)\n-\t\targv[argc++] = \"--dry-run\";\n-\tif (flags & TRANSPORT_PUSH_VERBOSE)\n-\t\targv[argc++] = \"--verbose\";\n-\targv[argc++] = transport->url;\n-\twhile (refspec_nr--)\n-\t\targv[argc++] = *refspec++;\n-\targv[argc] = NULL;\n-\treturn !!run_command_v_opt(argv, RUN_GIT_CMD);\n-}\n-\n-#endif\n-\n struct bundle_transport_data {\n \tint fd;\n \tstruct bundle_header header;\n@@ -826,8 +797,6 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\ttransport_helper_init(ret, \"curl\");\n #ifdef NO_CURL\n \t\terror(\"git was compiled without libcurl support.\");\n-#else\n-\t\tret->push = curl_transport_push;\n #endif\n \n \t} else if (is_local(url) && is_file(url)) {\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125049","messageId":"1255577814-14745-12-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 11/17] Git-aware CGI to provide dumb HTTP transport","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:48Z","receivedAt":"2009-10-15T03:36:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The git-http-backend CGI can be configured into any Apache server\nusing ScriptAlias, such as with the following configuration:\n\n  LoadModule cgi_module /usr/libexec/apache2/mod_cgi.so\n  LoadModule alias_module /usr/libexec/apache2/mod_alias.so\n  ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/\n\nRepositories are accessed via the translated PATH_INFO.\n\nThe CGI is backwards compatible with the dumb client, allowing all\nolder HTTP clients to continue to download repositories which are\nmanaged by the CGI.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .gitignore                         |    1 +\n Documentation/git-http-backend.txt |  105 +++++++++++++\n Makefile                           |    1 +\n http-backend.c                     |  290 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 397 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-http-backend.txt\n create mode 100644 http-backend.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 51a37b1..353d22f 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -55,6 +55,7 @@ git-get-tar-commit-id\n git-grep\n git-hash-object\n git-help\n+git-http-backend\n git-http-fetch\n git-http-push\n git-imap-send\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nnew file mode 100644\nindex 0000000..867675f\n--- /dev/null\n+++ b/Documentation/git-http-backend.txt\n@@ -0,0 +1,105 @@\n+git-http-backend(1)\n+===================\n+\n+NAME\n+----\n+git-http-backend - Server side implementation of Git over HTTP\n+\n+SYNOPSIS\n+--------\n+[verse]\n+'git-http-backend'\n+\n+DESCRIPTION\n+-----------\n+A simple CGI program to serve the contents of a Git repository to Git\n+clients accessing the repository over http:// and https:// protocols.\n+\n+By default, only the `upload-pack` service is enabled, which serves\n+'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from\n+'git-fetch', 'git-pull', and 'git-clone'.\n+\n+This is ideally suited for read-only updates, i.e., pulling from\n+git repositories.\n+\n+URL TRANSLATION\n+---------------\n+'git-http-backend' relies on the invoking web server to perform\n+URL to path translation, and store the repository path into the\n+PATH_TRANSLATED environment variable.  Most web servers will do\n+this translation automatically, resolving the suffix after the\n+CGI name relative to the server's document root.\n+\n+EXAMPLES\n+--------\n+\n+Apache 2.x::\n+\tTo serve all Git repositories contained within the '/git/'\n+\tsubdirectory of the DocumentRoot, ensure mod_cgi and\n+\tmod_alias are enabled, and create a ScriptAlias to the CGI:\n++\n+----------------------------------------------------------------\n+ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/\n+\n+<Directory /usr/libexec/git-core>\n+\tOptions None\n+</Directory>\n+<Files /usr/libexec/git-core/git-http-backend>\n+\tOptions ExecCGI\n+</Files>\n+----------------------------------------------------------------\n++\n+To require authentication for reads, use a Directory\n+directive around the repository, or one of its parent directories:\n++\n+----------------------------------------------------------------\n+<Directory /var/www/git/private>\n+\tAuthType Basic\n+\tAuthName \"Private Git Access\"\n+\tRequire group committers\n+\t...\n+</Directory>\n+----------------------------------------------------------------\n+\n+Accelerated static Apache 2.x::\n+\tSimilar to the above, but Apache can be used to return static\n+\tfiles that are stored on disk.\tOn many systems this may\n+\tbe more efficient as Apache can ask the kernel to copy the\n+\tfile contents from the file system directly to the network:\n++\n+----------------------------------------------------------------\n+DocumentRoot /var/www\n+\n+ScriptAlias /git/        /usr/libexec/git-core/git-http-backend/git/\n+Alias       /git_static/ /var/www/git/\n+\n+RewriteEngine on\n+RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$    /git_static/$1 [PT]\n+RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.pack)$ /git_static/$1 [PT]\n+RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.idx)$  /git_static/$1 [PT]\n+----------------------------------------------------------------\n+\n+\n+ENVIRONMENT\n+-----------\n+'git-http-backend' relies upon the CGI environment variables set\n+by the invoking web server, including:\n+\n+* PATH_TRANSLATED\n+* REMOTE_USER\n+* REMOTE_ADDR\n+* CONTENT_TYPE\n+* QUERY_STRING\n+* REQUEST_METHOD\n+\n+Author\n+------\n+Written by Shawn O. Pearce <spearce@spearce.org>.\n+\n+Documentation\n+--------------\n+Documentation by Shawn O. Pearce <spearce@spearce.org>.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex fea237b..271c290 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -365,6 +365,7 @@ PROGRAMS += git-show-index$X\n PROGRAMS += git-unpack-file$X\n PROGRAMS += git-upload-pack$X\n PROGRAMS += git-var$X\n+PROGRAMS += git-http-backend$X\n \n # List built-in command $C whose implementation cmd_$C() is not in\n # builtin-$C.o but is linked in as part of some other command.\ndiff --git a/http-backend.c b/http-backend.c\nnew file mode 100644\nindex 0000000..374f60d\n--- /dev/null\n+++ b/http-backend.c\n@@ -0,0 +1,290 @@\n+#include \"cache.h\"\n+#include \"refs.h\"\n+#include \"pkt-line.h\"\n+#include \"object.h\"\n+#include \"tag.h\"\n+#include \"exec_cmd.h\"\n+\n+static const char content_type[] = \"Content-Type\";\n+static const char content_length[] = \"Content-Length\";\n+static const char last_modified[] = \"Last-Modified\";\n+\n+static void format_write(int fd, const char *fmt, ...)\n+{\n+\tstatic char buffer[1024];\n+\n+\tva_list args;\n+\tunsigned n;\n+\n+\tva_start(args, fmt);\n+\tn = vsnprintf(buffer, sizeof(buffer), fmt, args);\n+\tva_end(args);\n+\tif (n >= sizeof(buffer))\n+\t\tdie(\"protocol error: impossibly long line\");\n+\n+\tsafe_write(fd, buffer, n);\n+}\n+\n+static void http_status(unsigned code, const char *msg)\n+{\n+\tformat_write(1, \"Status: %u %s\\r\\n\", code, msg);\n+}\n+\n+static void hdr_str(const char *name, const char *value)\n+{\n+\tformat_write(1, \"%s: %s\\r\\n\", name, value);\n+}\n+\n+static void hdr_int(const char *name, size_t value)\n+{\n+\tformat_write(1, \"%s: %\" PRIuMAX \"\\r\\n\", name, value);\n+}\n+\n+static void hdr_date(const char *name, unsigned long when)\n+{\n+\tconst char *value = show_date(when, 0, DATE_RFC2822);\n+\thdr_str(name, value);\n+}\n+\n+static void hdr_nocache(void)\n+{\n+\thdr_str(\"Expires\", \"Fri, 01 Jan 1980 00:00:00 GMT\");\n+\thdr_str(\"Pragma\", \"no-cache\");\n+\thdr_str(\"Cache-Control\", \"no-cache, max-age=0, must-revalidate\");\n+}\n+\n+static void hdr_cache_forever(void)\n+{\n+\tunsigned long now = time(NULL);\n+\thdr_date(\"Date\", now);\n+\thdr_date(\"Expires\", now + 31536000);\n+\thdr_str(\"Cache-Control\", \"public, max-age=31536000\");\n+}\n+\n+static void end_headers(void)\n+{\n+\tsafe_write(1, \"\\r\\n\", 2);\n+}\n+\n+static NORETURN void not_found(const char *err, ...)\n+{\n+\tva_list params;\n+\n+\thttp_status(404, \"Not Found\");\n+\thdr_nocache();\n+\tend_headers();\n+\n+\tva_start(params, err);\n+\tif (err && *err)\n+\t\tvfprintf(stderr, err, params);\n+\tva_end(params);\n+\texit(0);\n+}\n+\n+static void send_strbuf(const char *type, struct strbuf *buf)\n+{\n+\thdr_int(content_length, buf->len);\n+\thdr_str(content_type, type);\n+\tend_headers();\n+\tsafe_write(1, buf->buf, buf->len);\n+}\n+\n+static void send_file(const char *the_type, const char *name)\n+{\n+\tconst char *p = git_path(\"%s\", name);\n+\tsize_t buf_alloc = 8192;\n+\tchar *buf = xmalloc(buf_alloc);\n+\tint fd;\n+\tstruct stat sb;\n+\tsize_t size;\n+\n+\tfd = open(p, O_RDONLY);\n+\tif (fd < 0)\n+\t\tnot_found(\"Cannot open '%s': %s\", p, strerror(errno));\n+\tif (fstat(fd, &sb) < 0)\n+\t\tdie_errno(\"Cannot stat '%s'\", p);\n+\n+\tsize = xsize_t(sb.st_size);\n+\n+\thdr_int(content_length, size);\n+\thdr_str(content_type, the_type);\n+\thdr_date(last_modified, sb.st_mtime);\n+\tend_headers();\n+\n+\twhile (size) {\n+\t\tssize_t n = xread(fd, buf, buf_alloc);\n+\t\tif (n < 0)\n+\t\t\tdie_errno(\"Cannot read '%s'\", p);\n+\t\tif (!n)\n+\t\t\tbreak;\n+\t\tsafe_write(1, buf, n);\n+\t}\n+\tclose(fd);\n+\tfree(buf);\n+}\n+\n+static void get_text_file(char *name)\n+{\n+\thdr_nocache();\n+\tsend_file(\"text/plain\", name);\n+}\n+\n+static void get_loose_object(char *name)\n+{\n+\thdr_cache_forever();\n+\tsend_file(\"application/x-git-loose-object\", name);\n+}\n+\n+static void get_pack_file(char *name)\n+{\n+\thdr_cache_forever();\n+\tsend_file(\"application/x-git-packed-objects\", name);\n+}\n+\n+static void get_idx_file(char *name)\n+{\n+\thdr_cache_forever();\n+\tsend_file(\"application/x-git-packed-objects-toc\", name);\n+}\n+\n+static int show_text_ref(const char *name, const unsigned char *sha1,\n+\tint flag, void *cb_data)\n+{\n+\tstruct strbuf *buf = cb_data;\n+\tstruct object *o = parse_object(sha1);\n+\tif (!o)\n+\t\treturn 0;\n+\n+\tstrbuf_addf(buf, \"%s\\t%s\\n\", sha1_to_hex(sha1), name);\n+\tif (o->type == OBJ_TAG) {\n+\t\to = deref_tag(o, name, 0);\n+\t\tif (!o)\n+\t\t\treturn 0;\n+\t\tstrbuf_addf(buf, \"%s\\t%s^{}\\n\", sha1_to_hex(o->sha1), name);\n+\t}\n+\treturn 0;\n+}\n+\n+static void get_info_refs(char *arg)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\tfor_each_ref(show_text_ref, &buf);\n+\thdr_nocache();\n+\tsend_strbuf(\"text/plain\", &buf);\n+\tstrbuf_release(&buf);\n+}\n+\n+static void get_info_packs(char *arg)\n+{\n+\tsize_t objdirlen = strlen(get_object_directory());\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct packed_git *p;\n+\tsize_t cnt = 0;\n+\n+\tprepare_packed_git();\n+\tfor (p = packed_git; p; p = p->next) {\n+\t\tif (p->pack_local)\n+\t\t\tcnt++;\n+\t}\n+\n+\tstrbuf_grow(&buf, cnt * 53 + 2);\n+\tfor (p = packed_git; p; p = p->next) {\n+\t\tif (p->pack_local)\n+\t\t\tstrbuf_addf(&buf, \"P %s\\n\", p->pack_name + objdirlen + 6);\n+\t}\n+\tstrbuf_addch(&buf, '\\n');\n+\n+\thdr_nocache();\n+\tsend_strbuf(\"text/plain; charset=utf-8\", &buf);\n+\tstrbuf_release(&buf);\n+}\n+\n+static NORETURN void die_webcgi(const char *err, va_list params)\n+{\n+\tchar buffer[1000];\n+\n+\thttp_status(500, \"Internal Server Error\");\n+\thdr_nocache();\n+\tend_headers();\n+\n+\tvsnprintf(buffer, sizeof(buffer), err, params);\n+\tfprintf(stderr, \"fatal: %s\\n\", buffer);\n+\texit(0);\n+}\n+\n+static struct service_cmd {\n+\tconst char *method;\n+\tconst char *pattern;\n+\tvoid (*imp)(char *);\n+} services[] = {\n+\t{\"GET\", \"/HEAD$\", get_text_file},\n+\t{\"GET\", \"/info/refs$\", get_info_refs},\n+\t{\"GET\", \"/objects/info/alternates$\", get_text_file},\n+\t{\"GET\", \"/objects/info/http-alternates$\", get_text_file},\n+\t{\"GET\", \"/objects/info/packs$\", get_info_packs},\n+\t{\"GET\", \"/objects/info/[^/]*$\", get_text_file},\n+\t{\"GET\", \"/objects/[0-9a-f]{2}/[0-9a-f]{38}$\", get_loose_object},\n+\t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.pack$\", get_pack_file},\n+\t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.idx$\", get_idx_file}\n+};\n+\n+int main(int argc, char **argv)\n+{\n+\tchar *method = getenv(\"REQUEST_METHOD\");\n+\tchar *dir = getenv(\"PATH_TRANSLATED\");\n+\tstruct service_cmd *cmd = NULL;\n+\tchar *cmd_arg = NULL;\n+\tint i;\n+\n+\tgit_extract_argv0_path(argv[0]);\n+\tset_die_routine(die_webcgi);\n+\n+\tif (!method)\n+\t\tdie(\"No REQUEST_METHOD from server\");\n+\tif (!strcmp(method, \"HEAD\"))\n+\t\tmethod = \"GET\";\n+\tif (!dir)\n+\t\tdie(\"No PATH_TRANSLATED from server\");\n+\n+\tfor (i = 0; i < ARRAY_SIZE(services); i++) {\n+\t\tstruct service_cmd *c = &services[i];\n+\t\tregex_t re;\n+\t\tregmatch_t out[1];\n+\n+\t\tif (regcomp(&re, c->pattern, REG_EXTENDED))\n+\t\t\tdie(\"Bogus regex in service table: %s\", c->pattern);\n+\t\tif (!regexec(&re, dir, 1, out, 0)) {\n+\t\t\tsize_t n = out[0].rm_eo - out[0].rm_so;\n+\n+\t\t\tif (strcmp(method, c->method)) {\n+\t\t\t\tconst char *proto = getenv(\"SERVER_PROTOCOL\");\n+\t\t\t\tif (proto && !strcmp(proto, \"HTTP/1.1\"))\n+\t\t\t\t\thttp_status(405, \"Method Not Allowed\");\n+\t\t\t\telse\n+\t\t\t\t\thttp_status(400, \"Bad Request\");\n+\t\t\t\thdr_nocache();\n+\t\t\t\tend_headers();\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\n+\t\t\tcmd = c;\n+\t\t\tcmd_arg = xmalloc(n);\n+\t\t\tstrncpy(cmd_arg, dir + out[0].rm_so + 1, n);\n+\t\t\tcmd_arg[n] = '\\0';\n+\t\t\tdir[out[0].rm_so] = 0;\n+\t\t\tbreak;\n+\t\t}\n+\t\tregfree(&re);\n+\t}\n+\n+\tif (!cmd)\n+\t\tnot_found(\"Request not supported: '%s'\", dir);\n+\n+\tsetup_path();\n+\tif (!enter_repo(dir, 0))\n+\t\tnot_found(\"Not a git repository: '%s'\", dir);\n+\n+\tcmd->imp(cmd_arg);\n+\treturn 0;\n+}\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125047","messageId":"1255577814-14745-13-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 12/17] Add stateless RPC options to upload-pack, receive-pack","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:49Z","receivedAt":"2009-10-15T03:36:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"When --stateless-rpc is passed as a command line parameter to\nupload-pack or receive-pack the programs now assume they may\nperform only a single read-write cycle with stdin and stdout.\nThis fits with the HTTP POST request processing model where a\nprogram may read the request, write a response, and must exit.\n\nWhen --advertise-refs is passed as a command line parameter only\nthe initial ref advertisement is output, and the program exits\nimmediately.  This fits with the HTTP GET request model, where\nno request content is received but a response must be produced.\n\nHTTP headers and/or environment are not processed here, but\ninstead are assumed to be handled by the program invoking\neither service backend.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-receive-pack.c |   26 ++++++++++++++++++++------\n upload-pack.c          |   40 ++++++++++++++++++++++++++++++++++++----\n 2 files changed, 56 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin-receive-pack.c b/builtin-receive-pack.c\nindex b771fe9..70ff8c5 100644\n--- a/builtin-receive-pack.c\n+++ b/builtin-receive-pack.c\n@@ -615,6 +615,8 @@ static void add_alternate_refs(void)\n \n int cmd_receive_pack(int argc, const char **argv, const char *prefix)\n {\n+\tint advertise_refs = 0;\n+\tint stateless_rpc = 0;\n \tint i;\n \tchar *dir = NULL;\n \n@@ -623,7 +625,15 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)\n \t\tconst char *arg = *argv++;\n \n \t\tif (*arg == '-') {\n-\t\t\t/* Do flag handling here */\n+\t\t\tif (!strcmp(arg, \"--advertise-refs\")) {\n+\t\t\t\tadvertise_refs = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--stateless-rpc\")) {\n+\t\t\t\tstateless_rpc = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n \t\t\tusage(receive_pack_usage);\n \t\t}\n \t\tif (dir)\n@@ -652,12 +662,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)\n \t\t\" report-status delete-refs ofs-delta \" :\n \t\t\" report-status delete-refs \";\n \n-\tadd_alternate_refs();\n-\twrite_head_info();\n-\tclear_extra_refs();\n+\tif (advertise_refs || !stateless_rpc) {\n+\t\tadd_alternate_refs();\n+\t\twrite_head_info();\n+\t\tclear_extra_refs();\n \n-\t/* EOF */\n-\tpacket_flush(1);\n+\t\t/* EOF */\n+\t\tpacket_flush(1);\n+\t}\n+\tif (advertise_refs)\n+\t\treturn 0;\n \n \tread_head_info();\n \tif (commands) {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex f1dc3a3..70badcf 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -39,6 +39,8 @@ static unsigned int timeout;\n  */\n static int use_sideband;\n static int debug_fd;\n+static int advertise_refs;\n+static int stateless_rpc;\n \n static void reset_timeout(void)\n {\n@@ -509,6 +511,8 @@ static int get_common_commits(void)\n \t\tif (!len) {\n \t\t\tif (have_obj.nr == 0 || multi_ack)\n \t\t\t\tpacket_write(1, \"NAK\\n\");\n+\t\t\tif (stateless_rpc)\n+\t\t\t\texit(0);\n \t\t\tcontinue;\n \t\t}\n \t\tstrip(line, len);\n@@ -710,12 +714,32 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \treturn 0;\n }\n \n+static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+{\n+\tstruct object *o = parse_object(sha1);\n+\tif (!o)\n+\t\tdie(\"git upload-pack: cannot find object %s:\", sha1_to_hex(sha1));\n+\tif (!(o->flags & OUR_REF)) {\n+\t\to->flags |= OUR_REF;\n+\t\tnr_our_refs++;\n+\t}\n+\treturn 0;\n+}\n+\n static void upload_pack(void)\n {\n-\treset_timeout();\n-\thead_ref(send_ref, NULL);\n-\tfor_each_ref(send_ref, NULL);\n-\tpacket_flush(1);\n+\tif (advertise_refs || !stateless_rpc) {\n+\t\treset_timeout();\n+\t\thead_ref(send_ref, NULL);\n+\t\tfor_each_ref(send_ref, NULL);\n+\t\tpacket_flush(1);\n+\t} else {\n+\t\thead_ref(mark_our_ref, NULL);\n+\t\tfor_each_ref(mark_our_ref, NULL);\n+\t}\n+\tif (advertise_refs)\n+\t\treturn;\n+\n \treceive_needs();\n \tif (want_obj.nr) {\n \t\tget_common_commits();\n@@ -737,6 +761,14 @@ int main(int argc, char **argv)\n \n \t\tif (arg[0] != '-')\n \t\t\tbreak;\n+\t\tif (!strcmp(arg, \"--advertise-refs\")) {\n+\t\t\tadvertise_refs = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"--stateless-rpc\")) {\n+\t\t\tstateless_rpc = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (!strcmp(arg, \"--strict\")) {\n \t\t\tstrict = 1;\n \t\t\tcontinue;\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125055","messageId":"1255577814-14745-14-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 13/17] Smart fetch and push over HTTP: server side","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:50Z","receivedAt":"2009-10-15T03:36:50Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Requests for $GIT_URL/git-receive-pack and $GIT_URL/git-upload-pack\nare forwarded to the corresponding backend process by directly\nexecuting it and leaving stdin and stdout connected to the invoking\nweb server.  Prior to starting the backend process the HTTP response\nheaders are sent, thereby freeing the backend from needing to know\nabout the HTTP protocol.\n\nRequests that are encoded with Content-Encoding: gzip are\nautomatically inflated before being streamed into the backend.\nThis is primarily useful for the git-upload-pack backend, which\nreceives highly repetitive text data from clients that easily\ncompresses to 50% of its original size.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/git-http-backend.txt |   39 +++++-\n http-backend.c                     |  324 +++++++++++++++++++++++++++++++++++-\n 2 files changed, 359 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 867675f..022a243 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -22,6 +22,23 @@ By default, only the `upload-pack` service is enabled, which serves\n This is ideally suited for read-only updates, i.e., pulling from\n git repositories.\n \n+SERVICES\n+--------\n+These services can be enabled/disabled using the per-repository\n+configuration file:\n+\n+http.uploadpack::\n+\tThis serves 'git-fetch-pack' and 'git-ls-remote' clients.\n+\tIt is enabled by default, but a repository can disable it\n+\tby setting this configuration item to `false`.\n+\n+http.receivepack::\n+\tThis serves 'git-send-pack' clients, allowing push.  It is\n+\tdisabled by default for anonymous users, and enabled by\n+\tdefault for users authenticated by the web server.  It can be\n+\tdisabled by setting this item to `false`, or enabled for all\n+\tusers, including anonymous users, by setting it to `true`.\n+\n URL TRANSLATION\n ---------------\n 'git-http-backend' relies on the invoking web server to perform\n@@ -49,7 +66,19 @@ ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/\n </Files>\n ----------------------------------------------------------------\n +\n-To require authentication for reads, use a Directory\n+To enable anonymous read access but authenticated write access,\n+require authorization with a LocationMatch directive:\n++\n+----------------------------------------------------------------\n+<LocationMatch \".*/git-receive-pack$\">\n+\tAuthType Basic\n+\tAuthName \"Git Access\"\n+\tRequire group committers\n+\t...\n+</LocationMatch>\n+----------------------------------------------------------------\n++\n+To require authentication for both reads and writes, use a Directory\n directive around the repository, or one of its parent directories:\n +\n ----------------------------------------------------------------\n@@ -92,6 +121,14 @@ by the invoking web server, including:\n * QUERY_STRING\n * REQUEST_METHOD\n \n+The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and\n+GIT_COMMITTER_EMAIL to '$\\{REMOTE_USER}@http.$\\{REMOTE_ADDR\\}',\n+ensuring that any reflogs created by 'git-receive-pack' contain some\n+identifying information of the remote user who performed the push.\n+\n+All CGI environment variables are available to each of the hooks\n+invoked by the 'git-receive-pack'.\n+\n Author\n ------\n Written by Shawn O. Pearce <spearce@spearce.org>.\ndiff --git a/http-backend.c b/http-backend.c\nindex 374f60d..67030b5 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -4,11 +4,109 @@\n #include \"object.h\"\n #include \"tag.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n+#include \"string-list.h\"\n \n static const char content_type[] = \"Content-Type\";\n static const char content_length[] = \"Content-Length\";\n static const char last_modified[] = \"Last-Modified\";\n \n+static struct string_list *query_params;\n+\n+struct rpc_service {\n+\tconst char *name;\n+\tconst char *config_name;\n+\tsigned enabled : 2;\n+};\n+\n+static struct rpc_service rpc_service[] = {\n+\t{ \"upload-pack\", \"uploadpack\", 1 },\n+\t{ \"receive-pack\", \"receivepack\", -1 },\n+};\n+\n+static int decode_char(const char *q)\n+{\n+\tint i;\n+\tunsigned char val = 0;\n+\tfor (i = 0; i < 2; i++) {\n+\t\tunsigned char c = *q++;\n+\t\tval <<= 4;\n+\t\tif (c >= '0' && c <= '9')\n+\t\t\tval += c - '0';\n+\t\telse if (c >= 'a' && c <= 'f')\n+\t\t\tval += c - 'a' + 10;\n+\t\telse if (c >= 'A' && c <= 'F')\n+\t\t\tval += c - 'A' + 10;\n+\t\telse\n+\t\t\treturn -1;\n+\t}\n+\treturn val;\n+}\n+\n+static char *decode_parameter(const char **query, int is_name)\n+{\n+\tconst char *q = *query;\n+\tstruct strbuf out;\n+\n+\tstrbuf_init(&out, 16);\n+\tdo {\n+\t\tunsigned char c = *q;\n+\n+\t\tif (!c)\n+\t\t\tbreak;\n+\t\tif (c == '&' || (is_name && c == '=')) {\n+\t\t\tq++;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (c == '%') {\n+\t\t\tint val = decode_char(q + 1);\n+\t\t\tif (0 <= val) {\n+\t\t\t\tstrbuf_addch(&out, val);\n+\t\t\t\tq += 3;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (c == '+')\n+\t\t\tstrbuf_addch(&out, ' ');\n+\t\telse\n+\t\t\tstrbuf_addch(&out, c);\n+\t\tq++;\n+\t} while (1);\n+\t*query = q;\n+\treturn strbuf_detach(&out, NULL);\n+}\n+\n+static struct string_list *get_parameters(void)\n+{\n+\tif (!query_params) {\n+\t\tconst char *query = getenv(\"QUERY_STRING\");\n+\n+\t\tquery_params = xcalloc(1, sizeof(*query_params));\n+\t\twhile (query && *query) {\n+\t\t\tchar *name = decode_parameter(&query, 1);\n+\t\t\tchar *value = decode_parameter(&query, 0);\n+\t\t\tstruct string_list_item *i;\n+\n+\t\t\ti = string_list_lookup(name, query_params);\n+\t\t\tif (!i)\n+\t\t\t\ti = string_list_insert(name, query_params);\n+\t\t\telse\n+\t\t\t\tfree(i->util);\n+\t\t\ti->util = value;\n+\t\t}\n+\t}\n+\treturn query_params;\n+}\n+\n+static const char *get_parameter(const char *name)\n+{\n+\tstruct string_list_item *i;\n+\ti = string_list_lookup(name, get_parameters());\n+\treturn i ? i->util : NULL;\n+}\n+\n static void format_write(int fd, const char *fmt, ...)\n {\n \tstatic char buffer[1024];\n@@ -81,6 +179,21 @@ static NORETURN void not_found(const char *err, ...)\n \texit(0);\n }\n \n+static NORETURN void forbidden(const char *err, ...)\n+{\n+\tva_list params;\n+\n+\thttp_status(403, \"Forbidden\");\n+\thdr_nocache();\n+\tend_headers();\n+\n+\tva_start(params, err);\n+\tif (err && *err)\n+\t\tvfprintf(stderr, err, params);\n+\tva_end(params);\n+\texit(0);\n+}\n+\n static void send_strbuf(const char *type, struct strbuf *buf)\n {\n \thdr_int(content_length, buf->len);\n@@ -147,6 +260,145 @@ static void get_idx_file(char *name)\n \tsend_file(\"application/x-git-packed-objects-toc\", name);\n }\n \n+static int http_config(const char *var, const char *value, void *cb)\n+{\n+\tstruct rpc_service *svc = cb;\n+\n+\tif (!prefixcmp(var, \"http.\") &&\n+\t    !strcmp(var + 5, svc->config_name)) {\n+\t\tsvc->enabled = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n+\n+\t/* we are not interested in parsing any other configuration here */\n+\treturn 0;\n+}\n+\n+static struct rpc_service *select_service(const char *name)\n+{\n+\tstruct rpc_service *svc = NULL;\n+\tint i;\n+\n+\tif (prefixcmp(name, \"git-\"))\n+\t\tforbidden(\"Unsupported service: '%s'\", name);\n+\n+\tfor (i = 0; i < ARRAY_SIZE(rpc_service); i++) {\n+\t\tstruct rpc_service *s = &rpc_service[i];\n+\t\tif (!strcmp(s->name, name + 4)) {\n+\t\t\tsvc = s;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (!svc)\n+\t\tforbidden(\"Unsupported service: '%s'\", name);\n+\n+\tgit_config(http_config, svc);\n+\tif (svc->enabled < 0) {\n+\t\tconst char *user = getenv(\"REMOTE_USER\");\n+\t\tsvc->enabled = (user && *user) ? 1 : 0;\n+\t}\n+\tif (!svc->enabled)\n+\t\tforbidden(\"Service not enabled: '%s'\", svc->name);\n+\treturn svc;\n+}\n+\n+static void inflate_request(const char *prog_name, int out)\n+{\n+\tz_stream stream;\n+\tunsigned char in_buf[8192];\n+\tunsigned char out_buf[8192];\n+\tunsigned long cnt = 0;\n+\tint ret;\n+\n+\tmemset(&stream, 0, sizeof(stream));\n+\tret = inflateInit2(&stream, (15 + 16));\n+\tif (ret != Z_OK)\n+\t\tdie(\"cannot start zlib inflater, zlib err %d\", ret);\n+\n+\twhile (1) {\n+\t\tssize_t n = xread(0, in_buf, sizeof(in_buf));\n+\t\tif (n <= 0)\n+\t\t\tdie(\"request ended in the middle of the gzip stream\");\n+\n+\t\tstream.next_in = in_buf;\n+\t\tstream.avail_in = n;\n+\n+\t\twhile (0 < stream.avail_in) {\n+\t\t\tint ret;\n+\n+\t\t\tstream.next_out = out_buf;\n+\t\t\tstream.avail_out = sizeof(out_buf);\n+\n+\t\t\tret = inflate(&stream, Z_NO_FLUSH);\n+\t\t\tif (ret != Z_OK && ret != Z_STREAM_END)\n+\t\t\t\tdie(\"zlib error inflating request, result %d\", ret);\n+\n+\t\t\tn = stream.total_out - cnt;\n+\t\t\tif (write_in_full(out, out_buf, n) != n)\n+\t\t\t\tdie(\"%s aborted reading request\", prog_name);\n+\t\t\tcnt += n;\n+\n+\t\t\tif (ret == Z_STREAM_END)\n+\t\t\t\tgoto done;\n+\t\t}\n+\t}\n+\n+done:\n+\tinflateEnd(&stream);\n+\tclose(out);\n+}\n+\n+static void run_service(const char **argv)\n+{\n+\tconst char *encoding = getenv(\"HTTP_CONTENT_ENCODING\");\n+\tconst char *user = getenv(\"REMOTE_USER\");\n+\tconst char *host = getenv(\"REMOTE_ADDR\");\n+\tchar *env[3];\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint gzipped_request = 0;\n+\tstruct child_process cld;\n+\n+\tif (encoding && !strcmp(encoding, \"gzip\"))\n+\t\tgzipped_request = 1;\n+\telse if (encoding && !strcmp(encoding, \"x-gzip\"))\n+\t\tgzipped_request = 1;\n+\n+\tif (!user || !*user)\n+\t\tuser = \"anonymous\";\n+\tif (!host || !*host)\n+\t\thost = \"(none)\";\n+\n+\tmemset(&env, 0, sizeof(env));\n+\tstrbuf_addf(&buf, \"GIT_COMMITTER_NAME=%s\", user);\n+\tenv[0] = strbuf_detach(&buf, NULL);\n+\n+\tstrbuf_addf(&buf, \"GIT_COMMITTER_EMAIL=%s@http.%s\", user, host);\n+\tenv[1] = strbuf_detach(&buf, NULL);\n+\tenv[2] = NULL;\n+\n+\tmemset(&cld, 0, sizeof(cld));\n+\tcld.argv = argv;\n+\tcld.env = (const char *const *)env;\n+\tif (gzipped_request)\n+\t\tcld.in = -1;\n+\tcld.git_cmd = 1;\n+\tif (start_command(&cld))\n+\t\texit(1);\n+\n+\tclose(1);\n+\tif (gzipped_request)\n+\t\tinflate_request(argv[0], cld.in);\n+\telse\n+\t\tclose(0);\n+\n+\tif (finish_command(&cld))\n+\t\texit(1);\n+\tfree(env[0]);\n+\tfree(env[1]);\n+\tstrbuf_release(&buf);\n+}\n+\n static int show_text_ref(const char *name, const unsigned char *sha1,\n \tint flag, void *cb_data)\n {\n@@ -167,11 +419,32 @@ static int show_text_ref(const char *name, const unsigned char *sha1,\n \n static void get_info_refs(char *arg)\n {\n+\tconst char *service_name = get_parameter(\"service\");\n \tstruct strbuf buf = STRBUF_INIT;\n \n-\tfor_each_ref(show_text_ref, &buf);\n \thdr_nocache();\n-\tsend_strbuf(\"text/plain\", &buf);\n+\n+\tif (service_name) {\n+\t\tconst char *argv[] = {NULL /* service name */,\n+\t\t\t\"--stateless-rpc\", \"--advertise-refs\",\n+\t\t\t\".\", NULL};\n+\t\tstruct rpc_service *svc = select_service(service_name);\n+\n+\t\tstrbuf_addf(&buf, \"application/x-git-%s-advertisement\",\n+\t\t\tsvc->name);\n+\t\thdr_str(content_type, buf.buf);\n+\t\tend_headers();\n+\n+\t\tpacket_write(1, \"# service=git-%s\\n\", svc->name);\n+\t\tpacket_flush(1);\n+\n+\t\targv[0] = svc->name;\n+\t\trun_service(argv);\n+\n+\t} else {\n+\t\tfor_each_ref(show_text_ref, &buf);\n+\t\tsend_strbuf(\"text/plain\", &buf);\n+\t}\n \tstrbuf_release(&buf);\n }\n \n@@ -200,6 +473,48 @@ static void get_info_packs(char *arg)\n \tstrbuf_release(&buf);\n }\n \n+static void check_content_type(const char *accepted_type)\n+{\n+\tconst char *actual_type = getenv(\"CONTENT_TYPE\");\n+\n+\tif (!actual_type)\n+\t\tactual_type = \"\";\n+\n+\tif (strcmp(actual_type, accepted_type)) {\n+\t\thttp_status(415, \"Unsupported Media Type\");\n+\t\thdr_nocache();\n+\t\tend_headers();\n+\t\tformat_write(1,\n+\t\t\t\"Expected POST with Content-Type '%s',\"\n+\t\t\t\" but received '%s' instead.\\n\",\n+\t\t\taccepted_type, actual_type);\n+\t\texit(0);\n+\t}\n+}\n+\n+static void service_rpc(char *service_name)\n+{\n+\tconst char *argv[] = {NULL, \"--stateless-rpc\", \".\", NULL};\n+\tstruct rpc_service *svc = select_service(service_name);\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\tstrbuf_reset(&buf);\n+\tstrbuf_addf(&buf, \"application/x-git-%s-request\", svc->name);\n+\tcheck_content_type(buf.buf);\n+\n+\thdr_nocache();\n+\n+\tstrbuf_reset(&buf);\n+\tstrbuf_addf(&buf, \"application/x-git-%s-result\", svc->name);\n+\thdr_str(content_type, buf.buf);\n+\n+\tend_headers();\n+\n+\targv[0] = svc->name;\n+\trun_service(argv);\n+\tstrbuf_release(&buf);\n+}\n+\n static NORETURN void die_webcgi(const char *err, va_list params)\n {\n \tchar buffer[1000];\n@@ -226,7 +541,10 @@ static struct service_cmd {\n \t{\"GET\", \"/objects/info/[^/]*$\", get_text_file},\n \t{\"GET\", \"/objects/[0-9a-f]{2}/[0-9a-f]{38}$\", get_loose_object},\n \t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.pack$\", get_pack_file},\n-\t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.idx$\", get_idx_file}\n+\t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.idx$\", get_idx_file},\n+\n+\t{\"POST\", \"/git-upload-pack$\", service_rpc},\n+\t{\"POST\", \"/git-receive-pack$\", service_rpc}\n };\n \n int main(int argc, char **argv)\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125048","messageId":"1255577814-14745-15-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 14/17] Discover refs via smart HTTP server when available","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:51Z","receivedAt":"2009-10-15T03:36:51Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Instead of loading the cached info/refs, try to use the smart HTTP\nversion when the server supports it.  Since the smart variant is\nactually the pkt-line stream from the start of either upload-pack\nor receive-pack we need to parse these through get_remote_heads,\nwhich requires a background thread to feed its pipe.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n remote-curl.c |  149 ++++++++++++++++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 131 insertions(+), 18 deletions(-)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex af2fddf..c6e3172 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -5,6 +5,7 @@\n #include \"http.h\"\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n+#include \"pkt-line.h\"\n \n static struct remote *remote;\n static const char *url;\n@@ -75,21 +76,46 @@ static int set_option(const char *name, const char *value)\n \t}\n }\n \n-static struct ref *get_refs(void)\n+struct discovery {\n+\tconst char *service;\n+\tchar *buf_alloc;\n+\tchar *buf;\n+\tsize_t len;\n+\tunsigned proto_git : 1;\n+};\n+static struct discovery *last_discovery;\n+\n+static void free_discovery(struct discovery *d)\n+{\n+\tif (d) {\n+\t\tif (d == last_discovery)\n+\t\t\tlast_discovery = NULL;\n+\t\tfree(d->buf_alloc);\n+\t\tfree(d);\n+\t}\n+}\n+\n+static struct discovery* discover_refs(const char *service)\n {\n \tstruct strbuf buffer = STRBUF_INIT;\n-\tchar *data, *start, *mid;\n-\tchar *ref_name;\n+\tstruct discovery *last = last_discovery;\n \tchar *refs_url;\n-\tint i = 0;\n-\tint http_ret;\n+\tint http_ret, is_http = 0;\n \n-\tstruct ref *refs = NULL;\n-\tstruct ref *ref = NULL;\n-\tstruct ref *last_ref = NULL;\n+\tif (last && !strcmp(service, last->service))\n+\t\treturn last;\n+\tfree_discovery(last);\n \n-\trefs_url = xmalloc(strlen(url) + 11);\n-\tsprintf(refs_url, \"%s/info/refs\", url);\n+\tstrbuf_addf(&buffer, \"%s/info/refs\", url);\n+\tif (!prefixcmp(url, \"http://\") || !prefixcmp(url, \"https://\")) {\n+\t\tis_http = 1;\n+\t\tif (!strchr(url, '?'))\n+\t\t\tstrbuf_addch(&buffer, '?');\n+\t\telse\n+\t\t\tstrbuf_addch(&buffer, '&');\n+\t\tstrbuf_addf(&buffer, \"service=%s\", service);\n+\t}\n+\trefs_url = strbuf_detach(&buffer, NULL);\n \n \tinit_walker();\n \thttp_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);\n@@ -104,10 +130,86 @@ static struct ref *get_refs(void)\n \t\tdie(\"HTTP request failed\");\n \t}\n \n-\tdata = buffer.buf;\n+\tlast= xcalloc(1, sizeof(*last_discovery));\n+\tlast->service = service;\n+\tlast->buf_alloc = strbuf_detach(&buffer, &last->len);\n+\tlast->buf = last->buf_alloc;\n+\n+\tif (is_http && 5 <= last->len && last->buf[4] == '#') {\n+\t\t/* smart HTTP response; validate that the service\n+\t\t * pkt-line matches our request.\n+\t\t */\n+\t\tstruct strbuf exp = STRBUF_INIT;\n+\n+\t\tif (packet_get_line(&buffer, &last->buf, &last->len) <= 0)\n+\t\t\tdie(\"%s has invalid packet header\", refs_url);\n+\t\tif (buffer.len && buffer.buf[buffer.len - 1] == '\\n')\n+\t\t\tstrbuf_setlen(&buffer, buffer.len - 1);\n+\n+\t\tstrbuf_addf(&exp, \"# service=%s\", service);\n+\t\tif (strbuf_cmp(&exp, &buffer))\n+\t\t\tdie(\"invalid server response; got '%s'\", buffer.buf);\n+\t\tstrbuf_release(&exp);\n+\n+\t\t/* The header can include additional metadata lines, up\n+\t\t * until a packet flush marker.  Ignore these now, but\n+\t\t * in the future we might start to scan them.\n+\t\t */\n+\t\tstrbuf_reset(&buffer);\n+\t\twhile (packet_get_line(&buffer, &last->buf, &last->len) > 0)\n+\t\t\tstrbuf_reset(&buffer);\n+\n+\t\tlast->proto_git = 1;\n+\t}\n+\n+\tfree(refs_url);\n+\tstrbuf_release(&buffer);\n+\tlast_discovery = last;\n+\treturn last;\n+}\n+\n+static int write_discovery(int fd, void *data)\n+{\n+\tstruct discovery *heads = data;\n+\tint err = 0;\n+\tif (write_in_full(fd, heads->buf, heads->len) != heads->len)\n+\t\terr = 1;\n+\tclose(fd);\n+\treturn err;\n+}\n+\n+static struct ref *parse_git_refs(struct discovery *heads)\n+{\n+\tstruct ref *list = NULL;\n+\tstruct async async;\n+\n+\tmemset(&async, 0, sizeof(async));\n+\tasync.proc = write_discovery;\n+\tasync.data = heads;\n+\n+\tif (start_async(&async))\n+\t\tdie(\"cannot start thread to parse advertised refs\");\n+\tget_remote_heads(async.out, &list, 0, NULL, 0, NULL);\n+\tclose(async.out);\n+\tif (finish_async(&async))\n+\t\tdie(\"ref parsing thread failed\");\n+\treturn list;\n+}\n+\n+static struct ref *parse_info_refs(struct discovery *heads)\n+{\n+\tchar *data, *start, *mid;\n+\tchar *ref_name;\n+\tint i = 0;\n+\n+\tstruct ref *refs = NULL;\n+\tstruct ref *ref = NULL;\n+\tstruct ref *last_ref = NULL;\n+\n+\tdata = heads->buf;\n \tstart = NULL;\n \tmid = data;\n-\twhile (i < buffer.len) {\n+\twhile (i < heads->len) {\n \t\tif (!start) {\n \t\t\tstart = &data[i];\n \t\t}\n@@ -131,8 +233,7 @@ static struct ref *get_refs(void)\n \t\ti++;\n \t}\n \n-\tstrbuf_release(&buffer);\n-\n+\tinit_walker();\n \tref = alloc_ref(\"HEAD\");\n \tif (!walker->fetch_ref(walker, ref) &&\n \t    !resolve_remote_symref(ref, refs)) {\n@@ -142,11 +243,23 @@ static struct ref *get_refs(void)\n \t\tfree(ref);\n \t}\n \n-\tstrbuf_release(&buffer);\n-\tfree(refs_url);\n \treturn refs;\n }\n \n+static struct ref *get_refs(int for_push)\n+{\n+\tstruct discovery *heads;\n+\n+\tif (for_push)\n+\t\theads = discover_refs(\"git-receive-pack\");\n+\telse\n+\t\theads = discover_refs(\"git-upload-pack\");\n+\n+\tif (heads->proto_git)\n+\t\treturn parse_git_refs(heads);\n+\treturn parse_info_refs(heads);\n+}\n+\n static void output_refs(struct ref *refs)\n {\n \tstruct ref *posn;\n@@ -317,10 +430,10 @@ int main(int argc, const char **argv)\n \t\t\tparse_fetch(&buf);\n \n \t\t} else if (!strcmp(buf.buf, \"list\")) {\n-\t\t\toutput_refs(get_refs());\n+\t\t\toutput_refs(get_refs(0));\n \n \t\t} else if (!strcmp(buf.buf, \"list for-push\")) {\n-\t\t\toutput_refs(get_refs());\n+\t\t\toutput_refs(get_refs(1));\n \n \t\t} else if (!prefixcmp(buf.buf, \"push \")) {\n \t\t\tparse_push(&buf);\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125053","messageId":"1255577814-14745-16-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 15/17] Smart push over HTTP: client side","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:52Z","receivedAt":"2009-10-15T03:36:52Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The git-remote-curl backend detects if the remote server supports\nthe git-receive-pack service, and if so, runs git-send-pack in a\npipe to dump the command and pack data as a single POST request.\n\nThe advertisements from the server that were obtained during the\ndiscovery are passed into git-send-pack before the POST request\nstarts.  This permits git-send-pack to operate largely unmodified.\n\nFor smaller packs (those under 1 MiB) a HTTP/1.0 POST with a\nContent-Length is used, permitting interaction with any server.\nThe 1 MiB limit is arbitrary, but is sufficent to fit most deltas\ncreated by human authors against text sources with the occasional\nsmall binary file (e.g. few KiB icon image).  The configuration\noption http.postBuffer can be used to increase (or shink) this\nbuffer if the default is not sufficient.\n\nFor larger packs which cannot be spooled entirely into the helper's\nmemory space (due to http.postBuffer being too small), the POST\nrequest requires HTTP/1.1 and sets \"Transfer-Encoding: chunked\".\nThis permits the client to upload an unknown amount of data in one\nHTTP transaction without needing to pregenerate the entire pack\nfile locally.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n Documentation/config.txt |    8 ++\n builtin-send-pack.c      |  116 ++++++++++++++++++++++-\n http.c                   |    9 ++\n http.h                   |    1 +\n remote-curl.c            |  234 +++++++++++++++++++++++++++++++++++++++++++++-\n send-pack.h              |    3 +-\n sideband.c               |   11 ++-\n transport.c              |    1 +\n 8 files changed, 371 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex cd17814..7130d07 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1089,6 +1089,14 @@ http.maxRequests::\n \tHow many HTTP requests to launch in parallel. Can be overridden\n \tby the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.\n \n+http.postBuffer::\n+\tMaximum size in bytes of the buffer used by smart HTTP\n+\ttransports when POSTing data to the remote system.\n+\tFor requests larger than this buffer size, HTTP/1.1 and\n+\tTransfer-Encoding: chunked is used to avoid creating a\n+\tmassive pack file locally.  Default is 1 MiB, which is\n+\tsufficient for most requests.\n+\n http.lowSpeedLimit, http.lowSpeedTime::\n \tIf the HTTP transfer speed is less than 'http.lowSpeedLimit'\n \tfor longer than 'http.lowSpeedTime' seconds, the transfer is aborted.\ndiff --git a/builtin-send-pack.c b/builtin-send-pack.c\nindex 37e528e..a0fbad0 100644\n--- a/builtin-send-pack.c\n+++ b/builtin-send-pack.c\n@@ -2,9 +2,11 @@\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"pkt-line.h\"\n+#include \"sideband.h\"\n #include \"run-command.h\"\n #include \"remote.h\"\n #include \"send-pack.h\"\n+#include \"quote.h\"\n \n static const char send_pack_usage[] =\n \"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\\n\"\n@@ -59,7 +61,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext\n \tmemset(&po, 0, sizeof(po));\n \tpo.argv = argv;\n \tpo.in = -1;\n-\tpo.out = fd;\n+\tpo.out = args->stateless_rpc ? -1 : fd;\n \tpo.git_cmd = 1;\n \tif (start_command(&po))\n \t\tdie_errno(\"git pack-objects failed\");\n@@ -83,6 +85,20 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext\n \t}\n \n \tclose(po.in);\n+\n+\tif (args->stateless_rpc) {\n+\t\tchar *buf = xmalloc(LARGE_PACKET_MAX);\n+\t\twhile (1) {\n+\t\t\tssize_t n = xread(po.out, buf, LARGE_PACKET_MAX);\n+\t\t\tif (n <= 0)\n+\t\t\t\tbreak;\n+\t\t\tsend_sideband(fd, -1, buf, n, LARGE_PACKET_MAX);\n+\t\t}\n+\t\tfree(buf);\n+\t\tclose(po.out);\n+\t\tpo.out = -1;\n+\t}\n+\n \tif (finish_command(&po))\n \t\treturn error(\"pack-objects died with strange error\");\n \treturn 0;\n@@ -303,6 +319,59 @@ static int refs_pushed(struct ref *ref)\n \treturn 0;\n }\n \n+static void print_helper_status(struct ref *ref)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\tfor (; ref; ref = ref->next) {\n+\t\tconst char *msg = NULL;\n+\t\tconst char *res;\n+\n+\t\tswitch(ref->status) {\n+\t\tcase REF_STATUS_NONE:\n+\t\t\tres = \"error\";\n+\t\t\tmsg = \"no match\";\n+\t\t\tbreak;\n+\n+\t\tcase REF_STATUS_OK:\n+\t\t\tres = \"ok\";\n+\t\t\tbreak;\n+\n+\t\tcase REF_STATUS_UPTODATE:\n+\t\t\tres = \"ok\";\n+\t\t\tmsg = \"up to date\";\n+\t\t\tbreak;\n+\n+\t\tcase REF_STATUS_REJECT_NONFASTFORWARD:\n+\t\t\tres = \"error\";\n+\t\t\tmsg = \"non-fast forward\";\n+\t\t\tbreak;\n+\n+\t\tcase REF_STATUS_REJECT_NODELETE:\n+\t\tcase REF_STATUS_REMOTE_REJECT:\n+\t\t\tres = \"error\";\n+\t\t\tbreak;\n+\n+\t\tcase REF_STATUS_EXPECTING_REPORT:\n+\t\tdefault:\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tstrbuf_reset(&buf);\n+\t\tstrbuf_addf(&buf, \"%s %s\", res, ref->name);\n+\t\tif (ref->remote_status)\n+\t\t\tmsg = ref->remote_status;\n+\t\tif (msg) {\n+\t\t\tstrbuf_addch(&buf, ' ');\n+\t\t\tquote_two_c_style(&buf, \"\", msg, 0);\n+\t\t}\n+\t\tstrbuf_addch(&buf, '\\n');\n+\n+\t\tsafe_write(1, buf.buf, buf.len);\n+\t}\n+\tstrbuf_release(&buf);\n+}\n+\n int send_pack(struct send_pack_args *args,\n \t      int fd[], struct child_process *conn,\n \t      struct ref *remote_refs,\n@@ -310,6 +379,7 @@ int send_pack(struct send_pack_args *args,\n {\n \tint in = fd[0];\n \tint out = fd[1];\n+\tstruct strbuf req_buf = STRBUF_INIT;\n \tstruct ref *ref;\n \tint new_refs;\n \tint ask_for_status_report = 0;\n@@ -391,14 +461,14 @@ int send_pack(struct send_pack_args *args,\n \t\t\tchar *new_hex = sha1_to_hex(ref->new_sha1);\n \n \t\t\tif (ask_for_status_report) {\n-\t\t\t\tpacket_write(out, \"%s %s %s%c%s\",\n+\t\t\t\tpacket_buf_write(&req_buf, \"%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\telse\n-\t\t\t\tpacket_write(out, \"%s %s %s\",\n+\t\t\t\tpacket_buf_write(&req_buf, \"%s %s %s\",\n \t\t\t\t\told_hex, new_hex, ref->name);\n \t\t}\n \t\tref->status = expect_status_report ?\n@@ -406,7 +476,17 @@ int send_pack(struct send_pack_args *args,\n \t\t\tREF_STATUS_OK;\n \t}\n \n-\tpacket_flush(out);\n+\tif (args->stateless_rpc) {\n+\t\tif (!args->dry_run) {\n+\t\t\tpacket_buf_flush(&req_buf);\n+\t\t\tsend_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);\n+\t\t}\n+\t} else {\n+\t\tsafe_write(out, req_buf.buf, req_buf.len);\n+\t\tpacket_flush(out);\n+\t}\n+\tstrbuf_release(&req_buf);\n+\n \tif (new_refs && !args->dry_run) {\n \t\tif (pack_objects(out, remote_refs, extra_have, args) < 0) {\n \t\t\tfor (ref = remote_refs; ref; ref = ref->next)\n@@ -414,11 +494,15 @@ int send_pack(struct send_pack_args *args,\n \t\t\treturn -1;\n \t\t}\n \t}\n+\tif (args->stateless_rpc && !args->dry_run)\n+\t\tpacket_flush(out);\n \n \tif (expect_status_report)\n \t\tret = receive_status(in, remote_refs);\n \telse\n \t\tret = 0;\n+\tif (args->stateless_rpc)\n+\t\tpacket_flush(out);\n \n \tif (ret < 0)\n \t\treturn ret;\n@@ -478,6 +562,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)\n \tstruct extra_have_objects extra_have;\n \tstruct ref *remote_refs, *local_refs;\n \tint ret;\n+\tint helper_status = 0;\n \tint send_all = 0;\n \tconst char *receivepack = \"git-receive-pack\";\n \tint flags;\n@@ -523,6 +608,14 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)\n \t\t\t\targs.use_thin_pack = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--stateless-rpc\")) {\n+\t\t\t\targs.stateless_rpc = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--helper-status\")) {\n+\t\t\t\thelper_status = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tusage(send_pack_usage);\n \t\t}\n \t\tif (!dest) {\n@@ -551,7 +644,14 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \n-\tconn = git_connect(fd, dest, receivepack, args.verbose ? CONNECT_VERBOSE : 0);\n+\tif (args.stateless_rpc) {\n+\t\tconn = NULL;\n+\t\tfd[0] = 0;\n+\t\tfd[1] = 1;\n+\t} else {\n+\t\tconn = git_connect(fd, dest, receivepack,\n+\t\t\targs.verbose ? CONNECT_VERBOSE : 0);\n+\t}\n \n \tmemset(&extra_have, 0, sizeof(extra_have));\n \n@@ -575,12 +675,16 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)\n \n \tret = send_pack(&args, fd, conn, remote_refs, &extra_have);\n \n+\tif (helper_status)\n+\t\tprint_helper_status(remote_refs);\n+\n \tclose(fd[1]);\n \tclose(fd[0]);\n \n \tret |= finish_connect(conn);\n \n-\tprint_push_status(dest, remote_refs);\n+\tif (!helper_status)\n+\t\tprint_push_status(dest, remote_refs);\n \n \tif (!args.dry_run && remote) {\n \t\tstruct ref *ref;\ndiff --git a/http.c b/http.c\nindex 23b2a19..07e188a 100644\n--- a/http.c\n+++ b/http.c\n@@ -1,9 +1,11 @@\n #include \"http.h\"\n #include \"pack.h\"\n+#include \"sideband.h\"\n \n int data_received;\n int active_requests;\n int http_is_verbose;\n+size_t http_post_buffer = 16 * LARGE_PACKET_MAX;\n \n #ifdef USE_CURL_MULTI\n static int max_requests = -1;\n@@ -174,6 +176,13 @@ static int http_options(const char *var, const char *value, void *cb)\n \tif (!strcmp(\"http.proxy\", var))\n \t\treturn git_config_string(&curl_http_proxy, var, value);\n \n+\tif (!strcmp(\"http.postbuffer\", var)) {\n+\t\thttp_post_buffer = git_config_int(var, value);\n+\t\tif (http_post_buffer < LARGE_PACKET_MAX)\n+\t\t\thttp_post_buffer = LARGE_PACKET_MAX;\n+\t\treturn 0;\n+\t}\n+\n \t/* Fall back on the default ones */\n \treturn git_default_config(var, value, cb);\n }\ndiff --git a/http.h b/http.h\nindex 4c4e99c..1b0562f 100644\n--- a/http.h\n+++ b/http.h\n@@ -94,6 +94,7 @@ extern void http_cleanup(void);\n extern int data_received;\n extern int active_requests;\n extern int http_is_verbose;\n+extern size_t http_post_buffer;\n \n extern char curl_errorstr[CURL_ERROR_SIZE];\n \ndiff --git a/remote-curl.c b/remote-curl.c\nindex c6e3172..45436d1 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -6,6 +6,7 @@\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n #include \"pkt-line.h\"\n+#include \"sideband.h\"\n \n static struct remote *remote;\n static const char *url;\n@@ -16,7 +17,8 @@ struct options {\n \tunsigned long depth;\n \tunsigned progress : 1,\n \t\tfollowtags : 1,\n-\t\tdry_run : 1;\n+\t\tdry_run : 1,\n+\t\tthin : 1;\n };\n static struct options options;\n \n@@ -274,6 +276,187 @@ static void output_refs(struct ref *refs)\n \tfree_refs(refs);\n }\n \n+struct rpc_state {\n+\tconst char *service_name;\n+\tconst char **argv;\n+\tchar *service_url;\n+\tchar *hdr_content_type;\n+\tchar *hdr_accept;\n+\tchar *buf;\n+\tsize_t alloc;\n+\tsize_t len;\n+\tsize_t pos;\n+\tint in;\n+\tint out;\n+\tstruct strbuf result;\n+};\n+\n+static size_t rpc_out(void *ptr, size_t eltsize,\n+\t\tsize_t nmemb, void *buffer_)\n+{\n+\tsize_t max = eltsize * nmemb;\n+\tstruct rpc_state *rpc = buffer_;\n+\tsize_t avail = rpc->len - rpc->pos;\n+\n+\tif (!avail) {\n+\t\tavail = packet_read_line(rpc->out, rpc->buf, rpc->alloc);\n+\t\tif (!avail)\n+\t\t\treturn 0;\n+\t\trpc->pos = 0;\n+\t\trpc->len = avail;\n+\t}\n+\n+\tif (max < avail);\n+\t\tavail = max;\n+\tmemcpy(ptr, rpc->buf + rpc->pos, avail);\n+\trpc->pos += avail;\n+\treturn avail;\n+}\n+\n+static size_t rpc_in(const void *ptr, size_t eltsize,\n+\t\tsize_t nmemb, void *buffer_)\n+{\n+\tsize_t size = eltsize * nmemb;\n+\tstruct rpc_state *rpc = buffer_;\n+\twrite_or_die(rpc->in, ptr, size);\n+\treturn size;\n+}\n+\n+static int post_rpc(struct rpc_state *rpc)\n+{\n+\tstruct active_request_slot *slot;\n+\tstruct slot_results results;\n+\tstruct curl_slist *headers = NULL;\n+\tint err = 0, large_request = 0;\n+\n+\t/* Try to load the entire request, if we can fit it into the\n+\t * allocated buffer space we can use HTTP/1.0 and avoid the\n+\t * chunked encoding mess.\n+\t */\n+\twhile (1) {\n+\t\tsize_t left = rpc->alloc - rpc->len;\n+\t\tchar *buf = rpc->buf + rpc->len;\n+\t\tint n;\n+\n+\t\tif (left < LARGE_PACKET_MAX) {\n+\t\t\tlarge_request = 1;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tn = packet_read_line(rpc->out, buf, left);\n+\t\tif (!n)\n+\t\t\tbreak;\n+\t\trpc->len += n;\n+\t}\n+\n+\tslot = get_active_slot();\n+\tslot->results = &results;\n+\n+\tcurl_easy_setopt(slot->curl, CURLOPT_POST, 1);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);\n+\n+\theaders = curl_slist_append(headers, rpc->hdr_content_type);\n+\theaders = curl_slist_append(headers, rpc->hdr_accept);\n+\n+\tif (large_request) {\n+\t\t/* The request body is large and the size cannot be predicted.\n+\t\t * We must use chunked encoding to send it.\n+\t\t */\n+\t\theaders = curl_slist_append(headers, \"Expect: 100-continue\");\n+\t\theaders = curl_slist_append(headers, \"Transfer-Encoding: chunked\");\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);\n+\t\tif (options.verbosity > 1) {\n+\t\t\tfprintf(stderr, \"POST %s (chunked)\\n\", rpc->service_name);\n+\t\t\tfflush(stderr);\n+\t\t}\n+\n+\t} else {\n+\t\t/* We know the complete request size in advance, use the\n+\t\t * more normal Content-Length approach.\n+\t\t */\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);\n+\t\tif (options.verbosity > 1) {\n+\t\t\tfprintf(stderr, \"POST %s (%lu bytes)\\n\",\n+\t\t\t\trpc->service_name, (unsigned long)rpc->len);\n+\t\t\tfflush(stderr);\n+\t\t}\n+\t}\n+\n+\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);\n+\n+\tif (start_active_slot(slot)) {\n+\t\trun_active_slot(slot);\n+\t\tif (results.curl_result != CURLE_OK) {\n+\t\t\terr |= error(\"RPC failed; result=%d, HTTP code = %ld\",\n+\t\t\t\tresults.curl_result, results.http_code);\n+\t\t}\n+\t}\n+\tcurl_slist_free_all(headers);\n+\treturn err;\n+}\n+\n+static int rpc_service(struct rpc_state *rpc, struct discovery *heads)\n+{\n+\tconst char *svc = rpc->service_name;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct child_process client;\n+\tint err = 0;\n+\n+\tinit_walker();\n+\tmemset(&client, 0, sizeof(client));\n+\tclient.in = -1;\n+\tclient.out = -1;\n+\tclient.git_cmd = 1;\n+\tclient.argv = rpc->argv;\n+\tif (start_command(&client))\n+\t\texit(1);\n+\tif (heads)\n+\t\twrite_or_die(client.in, heads->buf, heads->len);\n+\n+\trpc->alloc = http_post_buffer;\n+\trpc->buf = xmalloc(rpc->alloc);\n+\trpc->in = client.in;\n+\trpc->out = client.out;\n+\tstrbuf_init(&rpc->result, 0);\n+\n+\tstrbuf_addf(&buf, \"%s/%s\", url, svc);\n+\trpc->service_url = strbuf_detach(&buf, NULL);\n+\n+\tstrbuf_addf(&buf, \"Content-Type: application/x-%s-request\", svc);\n+\trpc->hdr_content_type = strbuf_detach(&buf, NULL);\n+\n+\tstrbuf_addf(&buf, \"Accept: application/x-%s-response\", svc);\n+\trpc->hdr_accept = strbuf_detach(&buf, NULL);\n+\n+\twhile (!err) {\n+\t\tint n = packet_read_line(rpc->out, rpc->buf, rpc->alloc);\n+\t\tif (!n)\n+\t\t\tbreak;\n+\t\trpc->pos = 0;\n+\t\trpc->len = n;\n+\t\terr |= post_rpc(rpc);\n+\t}\n+\tstrbuf_read(&rpc->result, client.out, 0);\n+\n+\tclose(client.in);\n+\tclose(client.out);\n+\tclient.in = -1;\n+\tclient.out = -1;\n+\n+\terr |= finish_command(&client);\n+\tfree(rpc->service_url);\n+\tfree(rpc->hdr_content_type);\n+\tfree(rpc->hdr_accept);\n+\tfree(rpc->buf);\n+\tstrbuf_release(&buf);\n+\treturn err;\n+}\n+\n static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n {\n \tchar **targets = xmalloc(nr_heads * sizeof(char*));\n@@ -371,6 +554,52 @@ static int push_dav(int nr_spec, char **specs)\n \treturn 0;\n }\n \n+static int push_git(struct discovery *heads, int nr_spec, char **specs)\n+{\n+\tstruct rpc_state rpc;\n+\tconst char **argv;\n+\tint argc = 0, i, err;\n+\n+\targv = xmalloc((10 + nr_spec) * sizeof(char*));\n+\targv[argc++] = \"send-pack\";\n+\targv[argc++] = \"--stateless-rpc\";\n+\targv[argc++] = \"--helper-status\";\n+\tif (options.thin)\n+\t\targv[argc++] = \"--thin\";\n+\tif (options.dry_run)\n+\t\targv[argc++] = \"--dry-run\";\n+\tif (options.verbosity > 1)\n+\t\targv[argc++] = \"--verbose\";\n+\targv[argc++] = url;\n+\tfor (i = 0; i < nr_spec; i++)\n+\t\targv[argc++] = specs[i];\n+\targv[argc++] = NULL;\n+\n+\tmemset(&rpc, 0, sizeof(rpc));\n+\trpc.service_name = \"git-receive-pack\",\n+\trpc.argv = argv;\n+\n+\terr = rpc_service(&rpc, heads);\n+\tif (rpc.result.len)\n+\t\tsafe_write(1, rpc.result.buf, rpc.result.len);\n+\tstrbuf_release(&rpc.result);\n+\tfree(argv);\n+\treturn err;\n+}\n+\n+static int push(int nr_spec, char **specs)\n+{\n+\tstruct discovery *heads = discover_refs(\"git-receive-pack\");\n+\tint ret;\n+\n+\tif (heads->proto_git)\n+\t\tret = push_git(heads, nr_spec, specs);\n+\telse\n+\t\tret = push_dav(nr_spec, specs);\n+\tfree_discovery(heads);\n+\treturn ret;\n+}\n+\n static void parse_push(struct strbuf *buf)\n {\n \tchar **specs = NULL;\n@@ -391,7 +620,7 @@ static void parse_push(struct strbuf *buf)\n \t\t\tbreak;\n \t} while (1);\n \n-\tif (push_dav(nr_spec, specs))\n+\tif (push(nr_spec, specs))\n \t\texit(128); /* error already reported */\n \tfor (i = 0; i < nr_spec; i++)\n \t\tfree(specs[i]);\n@@ -414,6 +643,7 @@ int main(int argc, const char **argv)\n \n \toptions.verbosity = 1;\n \toptions.progress = !!isatty(2);\n+\toptions.thin = 1;\n \n \tremote = remote_get(argv[1]);\n \ndiff --git a/send-pack.h b/send-pack.h\nindex 8b3cf02..28141ac 100644\n--- a/send-pack.h\n+++ b/send-pack.h\n@@ -8,7 +8,8 @@ struct send_pack_args {\n \t\tforce_update:1,\n \t\tuse_thin_pack:1,\n \t\tuse_ofs_delta:1,\n-\t\tdry_run:1;\n+\t\tdry_run:1,\n+\t\tstateless_rpc:1;\n };\n \n int send_pack(struct send_pack_args *args,\ndiff --git a/sideband.c b/sideband.c\nindex 899b1ff..d5ffa1c 100644\n--- a/sideband.c\n+++ b/sideband.c\n@@ -135,9 +135,14 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet\n \t\tn = sz;\n \t\tif (packet_max - 5 < n)\n \t\t\tn = packet_max - 5;\n-\t\tsprintf(hdr, \"%04x\", n + 5);\n-\t\thdr[4] = band;\n-\t\tsafe_write(fd, hdr, 5);\n+\t\tif (0 <= band) {\n+\t\t\tsprintf(hdr, \"%04x\", n + 5);\n+\t\t\thdr[4] = band;\n+\t\t\tsafe_write(fd, hdr, 5);\n+\t\t} else {\n+\t\t\tsprintf(hdr, \"%04x\", n + 4);\n+\t\t\tsafe_write(fd, hdr, 4);\n+\t\t}\n \t\tsafe_write(fd, p, n);\n \t\tp += n;\n \t\tsz -= n;\ndiff --git a/transport.c b/transport.c\nindex 6d9652d..2ff1650 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -731,6 +731,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re\n \t\t\t\t NULL);\n \t}\n \n+\tmemset(&args, 0, sizeof(args));\n \targs.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);\n \targs.force_update = !!(flags & TRANSPORT_PUSH_FORCE);\n \targs.use_thin_pack = data->thin;\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125054","messageId":"1255577814-14745-17-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 16/17] Smart fetch over HTTP: client side","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:53Z","receivedAt":"2009-10-15T03:36:53Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The git-remote-curl backend detects if the remote server supports\nthe git-upload-pack service, and if so, runs git-fetch-pack locally\nin a pipe to generate the want/have commands.\n\nThe advertisements from the server that were obtained during the\ndiscovery are passed into git-fetch-pack before the POST request\nstarts, permitting server capability discovery and enablement.\n\nCommon objects that are discovered are appended onto the request as\nhave lines and are sent again on the next request.  This allows the\nremote side to reinitialize its in-memory list of common objects\nduring the next request.\n\nBecause all requests are relatively short, below git-remote-curl's\n1 MiB buffer limit, requests will use the standard Content-Length\nheader and be valid HTTP/1.0 POST requests.  This makes the fetch\nclient more tolerant of proxy servers which don't support HTTP/1.1\nor the chunked transfer encoding.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n builtin-fetch-pack.c |  110 ++++++++++++++++++++++++++++++++++++++++++--------\n fetch-pack.h         |    3 +-\n remote-curl.c        |   69 +++++++++++++++++++++++++++++--\n 3 files changed, 160 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 615f549..8ed4a6f 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -165,6 +165,24 @@ enum ack_type {\n \tACK_ready\n };\n \n+static void consume_shallow_list(int fd)\n+{\n+\tif (args.stateless_rpc && args.depth > 0) {\n+\t\t/* If we sent a depth we will get back \"duplicate\"\n+\t\t * shallow and unshallow commands every time there\n+\t\t * is a block of have lines exchanged.\n+\t\t */\n+\t\tchar line[1000];\n+\t\twhile (packet_read_line(fd, line, sizeof(line))) {\n+\t\t\tif (!prefixcmp(line, \"shallow \"))\n+\t\t\t\tcontinue;\n+\t\t\tif (!prefixcmp(line, \"unshallow \"))\n+\t\t\t\tcontinue;\n+\t\t\tdie(\"git fetch-pack: expected shallow list\");\n+\t\t}\n+\t}\n+}\n+\n static enum ack_type get_ack(int fd, unsigned char *result_sha1)\n {\n \tstatic char line[1000];\n@@ -190,6 +208,15 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)\n \tdie(\"git fetch_pack: expected ACK/NAK, got '%s'\", line);\n }\n \n+static void send_request(int fd, struct strbuf *buf)\n+{\n+\tif (args.stateless_rpc) {\n+\t\tsend_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);\n+\t\tpacket_flush(fd);\n+\t} else\n+\t\tsafe_write(fd, buf->buf, buf->len);\n+}\n+\n static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t       struct ref *refs)\n {\n@@ -199,7 +226,10 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \tunsigned in_vain = 0;\n \tint got_continue = 0;\n \tstruct strbuf req_buf = STRBUF_INIT;\n+\tsize_t state_len = 0;\n \n+\tif (args.stateless_rpc && multi_ack == 1)\n+\t\tdie(\"--stateless-rpc requires multi_ack_detailed\");\n \tif (marked)\n \t\tfor_each_ref(clear_marks, NULL);\n \tmarked = 1;\n@@ -256,13 +286,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \tif (args.depth > 0)\n \t\tpacket_buf_write(&req_buf, \"deepen %d\", args.depth);\n \tpacket_buf_flush(&req_buf);\n-\n-\tsafe_write(fd[1], req_buf.buf, req_buf.len);\n+\tstate_len = req_buf.len;\n \n \tif (args.depth > 0) {\n \t\tchar line[1024];\n \t\tunsigned char sha1[20];\n \n+\t\tsend_request(fd[1], &req_buf);\n \t\twhile (packet_read_line(fd[0], line, sizeof(line))) {\n \t\t\tif (!prefixcmp(line, \"shallow \")) {\n \t\t\t\tif (get_sha1_hex(line + 8, sha1))\n@@ -284,28 +314,40 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t\t}\n \t\t\tdie(\"expected shallow/unshallow, got %s\", line);\n \t\t}\n+\t} else if (!args.stateless_rpc)\n+\t\tsend_request(fd[1], &req_buf);\n+\n+\tif (!args.stateless_rpc) {\n+\t\t/* If we aren't using the stateless-rpc interface\n+\t\t * we don't need to retain the headers.\n+\t\t */\n+\t\tstrbuf_setlen(&req_buf, 0);\n+\t\tstate_len = 0;\n \t}\n \n \tflushes = 0;\n \tretval = -1;\n \twhile ((sha1 = get_rev())) {\n-\t\tpacket_write(fd[1], \"have %s\\n\", sha1_to_hex(sha1));\n+\t\tpacket_buf_write(&req_buf, \"have %s\\n\", sha1_to_hex(sha1));\n \t\tif (args.verbose)\n \t\t\tfprintf(stderr, \"have %s\\n\", sha1_to_hex(sha1));\n \t\tin_vain++;\n \t\tif (!(31 & ++count)) {\n \t\t\tint ack;\n \n-\t\t\tpacket_flush(fd[1]);\n+\t\t\tpacket_buf_flush(&req_buf);\n+\t\t\tsend_request(fd[1], &req_buf);\n+\t\t\tstrbuf_setlen(&req_buf, state_len);\n \t\t\tflushes++;\n \n \t\t\t/*\n \t\t\t * We keep one window \"ahead\" of the other side, and\n \t\t\t * will wait for an ACK only on the next one\n \t\t\t */\n-\t\t\tif (count == 32)\n+\t\t\tif (!args.stateless_rpc && count == 32)\n \t\t\t\tcontinue;\n \n+\t\t\tconsume_shallow_list(fd[0]);\n \t\t\tdo {\n \t\t\t\tack = get_ack(fd[0], result_sha1);\n \t\t\t\tif (args.verbose && ack)\n@@ -322,6 +364,17 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t\t\tcase ACK_continue: {\n \t\t\t\t\tstruct commit *commit =\n \t\t\t\t\t\tlookup_commit(result_sha1);\n+\t\t\t\t\tif (args.stateless_rpc\n+\t\t\t\t\t && ack == ACK_common\n+\t\t\t\t\t && !(commit->object.flags & COMMON)) {\n+\t\t\t\t\t\t/* We need to replay the have for this object\n+\t\t\t\t\t\t * on the next RPC request so the peer knows\n+\t\t\t\t\t\t * it is in common with us.\n+\t\t\t\t\t\t */\n+\t\t\t\t\t\tconst char *hex = sha1_to_hex(result_sha1);\n+\t\t\t\t\t\tpacket_buf_write(&req_buf, \"have %s\\n\", hex);\n+\t\t\t\t\t\tstate_len = req_buf.len;\n+\t\t\t\t\t}\n \t\t\t\t\tmark_common(commit, 0, 1);\n \t\t\t\t\tretval = 0;\n \t\t\t\t\tin_vain = 0;\n@@ -339,7 +392,8 @@ static int find_common(int fd[2], unsigned char *result_sha1,\n \t\t}\n \t}\n done:\n-\tpacket_write(fd[1], \"done\\n\");\n+\tpacket_buf_write(&req_buf, \"done\\n\");\n+\tsend_request(fd[1], &req_buf);\n \tif (args.verbose)\n \t\tfprintf(stderr, \"done\\n\");\n \tif (retval != 0) {\n@@ -348,6 +402,7 @@ done:\n \t}\n \tstrbuf_release(&req_buf);\n \n+\tconsume_shallow_list(fd[0]);\n \twhile (flushes || multi_ack) {\n \t\tint ack = get_ack(fd[0], result_sha1);\n \t\tif (ack) {\n@@ -672,6 +727,8 @@ static struct ref *do_fetch_pack(int fd[2],\n \t\t\t */\n \t\t\twarning(\"no common commits\");\n \n+\tif (args.stateless_rpc)\n+\t\tpacket_flush(fd[1]);\n \tif (get_pack(fd, pack_lockfile))\n \t\tdie(\"git fetch-pack: fetch failed.\");\n \n@@ -742,6 +799,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \tstruct ref *ref = NULL;\n \tchar *dest = NULL, **heads;\n \tint fd[2];\n+\tchar *pack_lockfile = NULL;\n+\tchar **pack_lockfile_ptr = NULL;\n \tstruct child_process *conn;\n \n \tnr_heads = 0;\n@@ -791,6 +850,15 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \t\t\t\targs.no_progress = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(\"--stateless-rpc\", arg)) {\n+\t\t\t\targs.stateless_rpc = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(\"--lock-pack\", arg)) {\n+\t\t\t\targs.lock_pack = 1;\n+\t\t\t\tpack_lockfile_ptr = &pack_lockfile;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tusage(fetch_pack_usage);\n \t\t}\n \t\tdest = (char *)arg;\n@@ -801,19 +869,27 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)\n \tif (!dest)\n \t\tusage(fetch_pack_usage);\n \n-\tconn = git_connect(fd, (char *)dest, args.uploadpack,\n-\t\t\t   args.verbose ? CONNECT_VERBOSE : 0);\n-\tif (conn) {\n-\t\tget_remote_heads(fd[0], &ref, 0, NULL, 0, NULL);\n-\n-\t\tref = fetch_pack(&args, fd, conn, ref, dest, nr_heads, heads, NULL);\n-\t\tclose(fd[0]);\n-\t\tclose(fd[1]);\n-\t\tif (finish_connect(conn))\n-\t\t\tref = NULL;\n+\tif (args.stateless_rpc) {\n+\t\tconn = NULL;\n+\t\tfd[0] = 0;\n+\t\tfd[1] = 1;\n \t} else {\n-\t\tref = NULL;\n+\t\tconn = git_connect(fd, (char *)dest, args.uploadpack,\n+\t\t\t\t   args.verbose ? CONNECT_VERBOSE : 0);\n+\t}\n+\n+\tget_remote_heads(fd[0], &ref, 0, NULL, 0, NULL);\n+\n+\tref = fetch_pack(&args, fd, conn, ref, dest,\n+\t\tnr_heads, heads, pack_lockfile_ptr);\n+\tif (pack_lockfile) {\n+\t\tprintf(\"lock %s\\n\", pack_lockfile);\n+\t\tfflush(stdout);\n \t}\n+\tclose(fd[0]);\n+\tclose(fd[1]);\n+\tif (finish_connect(conn))\n+\t\tref = NULL;\n \tret = !ref;\n \n \tif (!ret && nr_heads) {\ndiff --git a/fetch-pack.h b/fetch-pack.h\nindex 8bd9c32..fbe85ac 100644\n--- a/fetch-pack.h\n+++ b/fetch-pack.h\n@@ -13,7 +13,8 @@ struct fetch_pack_args\n \t\tfetch_all:1,\n \t\tverbose:1,\n \t\tno_progress:1,\n-\t\tinclude_tag:1;\n+\t\tinclude_tag:1,\n+\t\tstateless_rpc:1;\n };\n \n struct ref *fetch_pack(struct fetch_pack_args *args,\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 45436d1..eb71ffd 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -45,7 +45,7 @@ static int set_option(const char *name, const char *value)\n \t\t\toptions.progress = 0;\n \t\telse\n \t\t\treturn -1;\n-\t\treturn 1 /* TODO implement later */;\n+\t\treturn 0;\n \t}\n \telse if (!strcmp(name, \"depth\")) {\n \t\tchar *end;\n@@ -53,7 +53,7 @@ static int set_option(const char *name, const char *value)\n \t\tif (value == end || *end)\n \t\t\treturn -1;\n \t\toptions.depth = v;\n-\t\treturn 1 /* TODO implement later */;\n+\t\treturn 0;\n \t}\n \telse if (!strcmp(name, \"followtags\")) {\n \t\tif (!strcmp(value, \"true\"))\n@@ -62,7 +62,7 @@ static int set_option(const char *name, const char *value)\n \t\t\toptions.followtags = 0;\n \t\telse\n \t\t\treturn -1;\n-\t\treturn 1 /* TODO implement later */;\n+\t\treturn 0;\n \t}\n \telse if (!strcmp(name, \"dry-run\")) {\n \t\tif (!strcmp(value, \"true\"))\n@@ -462,6 +462,8 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n \tchar **targets = xmalloc(nr_heads * sizeof(char*));\n \tint ret, i;\n \n+\tif (options.depth)\n+\t\tdie(\"dumb http transport does not support --depth\");\n \tfor (i = 0; i < nr_heads; i++)\n \t\ttargets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));\n \n@@ -480,6 +482,65 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)\n \treturn ret ? error(\"Fetch failed.\") : 0;\n }\n \n+static int fetch_git(struct discovery *heads,\n+\tint nr_heads, struct ref **to_fetch)\n+{\n+\tstruct rpc_state rpc;\n+\tchar *depth_arg = NULL;\n+\tconst char **argv;\n+\tint argc = 0, i, err;\n+\n+\targv = xmalloc((15 + nr_heads) * sizeof(char*));\n+\targv[argc++] = \"fetch-pack\";\n+\targv[argc++] = \"--stateless-rpc\";\n+\targv[argc++] = \"--lock-pack\";\n+\tif (options.followtags)\n+\t\targv[argc++] = \"--include-tag\";\n+\tif (options.thin)\n+\t\targv[argc++] = \"--thin\";\n+\tif (options.verbosity >= 3) {\n+\t\targv[argc++] = \"-v\";\n+\t\targv[argc++] = \"-v\";\n+\t}\n+\tif (!options.progress)\n+\t\targv[argc++] = \"--no-progress\";\n+\tif (options.depth) {\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\tstrbuf_addf(&buf, \"--depth=%lu\", options.depth);\n+\t\tdepth_arg = strbuf_detach(&buf, NULL);\n+\t\targv[argc++] = depth_arg;\n+\t}\n+\targv[argc++] = url;\n+\tfor (i = 0; i < nr_heads; i++) {\n+\t\tstruct ref *ref = to_fetch[i];\n+\t\tif (!ref->name || !*ref->name)\n+\t\t\tdie(\"cannot fetch by sha1 over smart http\");\n+\t\targv[argc++] = ref->name;\n+\t}\n+\targv[argc++] = NULL;\n+\n+\tmemset(&rpc, 0, sizeof(rpc));\n+\trpc.service_name = \"git-upload-pack\",\n+\trpc.argv = argv;\n+\n+\terr = rpc_service(&rpc, heads);\n+\tif (rpc.result.len)\n+\t\tsafe_write(1, rpc.result.buf, rpc.result.len);\n+\tstrbuf_release(&rpc.result);\n+\tfree(argv);\n+\tfree(depth_arg);\n+\treturn err;\n+}\n+\n+static int fetch(int nr_heads, struct ref **to_fetch)\n+{\n+\tstruct discovery *d = discover_refs(\"git-upload-pack\");\n+\tif (d->proto_git)\n+\t\treturn fetch_git(d, nr_heads, to_fetch);\n+\telse\n+\t\treturn fetch_dumb(nr_heads, to_fetch);\n+}\n+\n static void parse_fetch(struct strbuf *buf)\n {\n \tstruct ref **to_fetch = NULL;\n@@ -522,7 +583,7 @@ static void parse_fetch(struct strbuf *buf)\n \t\t\tbreak;\n \t} while (1);\n \n-\tif (fetch_dumb(nr_heads, to_fetch))\n+\tif (fetch(nr_heads, to_fetch))\n \t\texit(128); /* error already reported */\n \tfree_refs(list_head);\n \tfree(to_fetch);\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125051","messageId":"1255577814-14745-18-git-send-email-spearce@spearce.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[RFC PATCH v3 17/17] Smart HTTP fetch: gzip requests","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T03:36:54Z","receivedAt":"2009-10-15T03:36:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"The upload-pack requests are mostly plain text and they compress\nrather well.  Deflating them with Content-Encoding: gzip can easily\ndrop the size of the request by 50%, reducing the amount of data\nto transfer as we negotiate the common commits.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\nCC: Daniel Barkalow <barkalow@iabervon.org>\n---\n remote-curl.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 50 insertions(+), 0 deletions(-)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex eb71ffd..b6420fe 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -289,6 +289,7 @@ struct rpc_state {\n \tint in;\n \tint out;\n \tstruct strbuf result;\n+\tunsigned gzip_request : 1;\n };\n \n static size_t rpc_out(void *ptr, size_t eltsize,\n@@ -327,6 +328,8 @@ static int post_rpc(struct rpc_state *rpc)\n \tstruct active_request_slot *slot;\n \tstruct slot_results results;\n \tstruct curl_slist *headers = NULL;\n+\tint use_gzip = rpc->gzip_request;\n+\tchar *gzip_body = NULL;\n \tint err = 0, large_request = 0;\n \n \t/* Try to load the entire request, if we can fit it into the\n@@ -340,6 +343,7 @@ static int post_rpc(struct rpc_state *rpc)\n \n \t\tif (left < LARGE_PACKET_MAX) {\n \t\t\tlarge_request = 1;\n+\t\t\tuse_gzip = 0;\n \t\t\tbreak;\n \t\t}\n \n@@ -355,6 +359,7 @@ static int post_rpc(struct rpc_state *rpc)\n \tcurl_easy_setopt(slot->curl, CURLOPT_POST, 1);\n \tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_ENCODING, \"\");\n \n \theaders = curl_slist_append(headers, rpc->hdr_content_type);\n \theaders = curl_slist_append(headers, rpc->hdr_accept);\n@@ -372,6 +377,49 @@ static int post_rpc(struct rpc_state *rpc)\n \t\t\tfflush(stderr);\n \t\t}\n \n+\t} else if (use_gzip && 1024 < rpc->len) {\n+\t\t/* The client backend isn't giving us compressed data so\n+\t\t * we can try to deflate it ourselves, this may save on.\n+\t\t * the transfer time.\n+\t\t */\n+\t\tsize_t size;\n+\t\tz_stream stream;\n+\t\tint ret;\n+\n+\t\tmemset(&stream, 0, sizeof(stream));\n+\t\tret = deflateInit2(&stream, Z_BEST_COMPRESSION,\n+\t\t\t\tZ_DEFLATED, (15 + 16),\n+\t\t\t\t8, Z_DEFAULT_STRATEGY);\n+\t\tif (ret != Z_OK)\n+\t\t\tdie(\"cannot deflate request; zlib init error %d\", ret);\n+\t\tsize = deflateBound(&stream, rpc->len);\n+\t\tgzip_body = xmalloc(size);\n+\n+\t\tstream.next_in = (unsigned char *)rpc->buf;\n+\t\tstream.avail_in = rpc->len;\n+\t\tstream.next_out = (unsigned char *)gzip_body;\n+\t\tstream.avail_out = size;\n+\n+\t\tret = deflate(&stream, Z_FINISH);\n+\t\tif (ret != Z_STREAM_END)\n+\t\t\tdie(\"cannot deflate request; zlib deflate error %d\", ret);\n+\n+\t\tret = deflateEnd(&stream);\n+\t\tif (ret != Z_OK)\n+\t\t\tdie(\"cannot deflate request; zlib end error %d\", ret);\n+\n+\t\tsize = stream.total_out;\n+\n+\t\theaders = curl_slist_append(headers, \"Content-Encoding: gzip\");\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);\n+\t\tcurl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, size);\n+\n+\t\tif (options.verbosity > 1) {\n+\t\t\tfprintf(stderr, \"POST %s (gzip %lu to %lu bytes)\\n\",\n+\t\t\t\trpc->service_name,\n+\t\t\t\t(unsigned long)rpc->len, (unsigned long)size);\n+\t\t\tfflush(stderr);\n+\t\t}\n \t} else {\n \t\t/* We know the complete request size in advance, use the\n \t\t * more normal Content-Length approach.\n@@ -397,6 +445,7 @@ static int post_rpc(struct rpc_state *rpc)\n \t\t}\n \t}\n \tcurl_slist_free_all(headers);\n+\tfree(gzip_body);\n \treturn err;\n }\n \n@@ -522,6 +571,7 @@ static int fetch_git(struct discovery *heads,\n \tmemset(&rpc, 0, sizeof(rpc));\n \trpc.service_name = \"git-upload-pack\",\n \trpc.argv = argv;\n+\trpc.gzip_request = 1;\n \n \terr = rpc_service(&rpc, heads);\n \tif (rpc.result.len)\n-- \n1.6.5.52.g0ff2e\n"},{"id":"125062","messageId":"7v63ah85ss.fsf@alter.siamese.dyndns.org","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-15T07:39:15Z","receivedAt":"2009-10-15T07:39:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> This v3 series is a respin, and includes fixes to address reviewer\n> comments from v2.\n\nThanks.\n"},{"id":"125067","messageId":"20091015185253.6117@nanako3.lavabit.com","threadId":"21244","inReplyTo":"7v63ah85ss.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-10-15T09:52:53Z","receivedAt":"2009-10-15T09:52:53Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Junio C Hamano <gitster@pobox.com> writes:\n\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>\n>> This v3 series is a respin, and includes fixes to address reviewer\n>> comments from v2.\n>\n> Thanks.\n\nJunio, you merged this series to your \"pu\" branch, but it breaks \"make test\" (t9801). Shawn's \"sp/smart-http\" topic doesn't have t9801 and passes all the tests.\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"125076","messageId":"20091015143340.GI10505@spearce.org","threadId":"21244","inReplyTo":"20091015185253.6117@nanako3.lavabit.com","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T14:33:40Z","receivedAt":"2009-10-15T14:33:40Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Nanako Shiraishi <nanako3@lavabit.com> wrote:\n> > \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> >\n> >> This v3 series is a respin, and includes fixes to address reviewer\n> >> comments from v2.\n> \n> Junio, you merged this series to your \"pu\" branch, but it breaks\n> \"make test\" (t9801). Shawn's \"sp/smart-http\" topic doesn't have\n> t9801 and passes all the tests.\n\nActually, pu contains v2 right now, not v3.\n\nAnd pu doesn't always pass the tests... because of issues like this.\n\nIt looks like there might be a semantic clash between John Herland's\njh/cvs-helper branch and my sp/smart-http branch... but digging\naround at the code I haven't quite identified what that might be.\n\n-- \nShawn.\n"},{"id":"125077","messageId":"200910151721.08352.johan@herland.net","threadId":"21244","inReplyTo":"20091015143340.GI10505@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2009-10-15T15:21:08Z","receivedAt":"2009-10-15T15:21:08Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Thursday 15 October 2009, Shawn O. Pearce wrote:\n> Nanako Shiraishi <nanako3@lavabit.com> wrote:\n> > > \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> > >> This v3 series is a respin, and includes fixes to address\n> > >> reviewer comments from v2.\n> >\n> > Junio, you merged this series to your \"pu\" branch, but it breaks\n> > \"make test\" (t9801). Shawn's \"sp/smart-http\" topic doesn't have\n> > t9801 and passes all the tests.\n>\n> Actually, pu contains v2 right now, not v3.\n>\n> And pu doesn't always pass the tests... because of issues like this.\n>\n> It looks like there might be a semantic clash between John Herland's\n> jh/cvs-helper branch and my sp/smart-http branch... but digging\n> around at the code I haven't quite identified what that might be.\n\nDon't have time to look into this at the moment, but a cursory gdb\nshows that the \"git fetch\" in test #4 in t9801 segfaults with the\nfollowing stacktrace:\n\n#0  0x00007f8dd67e8a47 in fclose () from /lib/libc.so.6\n#1  0x00000000004a05b5 in disconnect_helper (transport=<value optimized out>) at transport-helper.c:81\n#2  0x000000000049de1e in transport_disconnect (transport=0x1955490) at transport.c:952\n#3  0x0000000000423477 in cmd_fetch (argc=26566704, argv=0x0, prefix=<value optimized out>) at builtin-fetch.c:748\n#4  0x0000000000404233 in handle_internal_command (argc=2, argv=0x7fffdf293d20) at git.c:251\n#5  0x0000000000404426 in main (argc=2, argv=0x7fffdf293d20) at git.c:438\n\nDon't know if this helps...\n\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"125079","messageId":"20091015154142.GL10505@spearce.org","threadId":"21244","inReplyTo":"200910151721.08352.johan@herland.net","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T15:41:42Z","receivedAt":"2009-10-15T15:41:42Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Johan Herland <johan@herland.net> wrote:\n> Don't have time to look into this at the moment, but a cursory gdb\n> shows that the \"git fetch\" in test #4 in t9801 segfaults with the\n> following stacktrace:\n> \n> #0  0x00007f8dd67e8a47 in fclose () from /lib/libc.so.6\n> #1  0x00000000004a05b5 in disconnect_helper (transport=<value optimized out>) at transport-helper.c:81\n> #2  0x000000000049de1e in transport_disconnect (transport=0x1955490) at transport.c:952\n> #3  0x0000000000423477 in cmd_fetch (argc=26566704, argv=0x0, prefix=<value optimized out>) at builtin-fetch.c:748\n> #4  0x0000000000404233 in handle_internal_command (argc=2, argv=0x7fffdf293d20) at git.c:251\n> #5  0x0000000000404426 in main (argc=2, argv=0x7fffdf293d20) at git.c:438\n\nIt does.  It is caused by the disconnect_helper call inside of\nfetch_with_import.  You can't disconnect inside of the fetch method\nof a transport, the caller is going to disconnect you a second time.\n\nDuring that second disconnect the transport->data field is now\npointing at a garbage area of memory.  We're passing a garbage\npointer from data->out to fclose, and fclose is rightly upset.\n\nThis bug isn't due to the merge, its a bug in Johan's series that\nneeds to be fixed before it could merge down to next/master.\n\n-- \nShawn.\n"},{"id":"125102","messageId":"7vfx9k4d33.fsf@alter.siamese.dyndns.org","threadId":"21244","inReplyTo":"20091015154142.GL10505@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-15T20:27:44Z","receivedAt":"2009-10-15T20:27:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> It does.  It is caused by the disconnect_helper call inside of\n> fetch_with_import.  You can't disconnect inside of the fetch method\n> of a transport, the caller is going to disconnect you a second time.\n> ...\n> This bug isn't due to the merge, its a bug in Johan's series that\n> needs to be fixed before it could merge down to next/master.\n\nThanks; I pushed out 'pu' with your v3 this time.\n\nLast night I did a trial fetch merge with FETCH_HEAD into 'pu', but then\nafter I queued some fixes to 'maint' and 'master' to prepare for 1.6.5.1,\nI rebuilt 'pu' with the still-old sp/smart-http topic, and that is what\nwas sitting at k.org til this morning.\n\nI am a bit confused about your diagnosis, though.  As far as I recall,\nJohan's topic itself nor 'pu' with Johan's topic but without v2 of\nsp/smart-http did not have the issue.  Does that indicate that the\nbehaviour expected from the fetch method is different between the two\ntopics, and this indeed is a semantic conflict as you suspected initially?\nIn other words, if Johan's series is updated not to disconnect inside the\nfetch method of the transport, and if it is not merged with your series,\ndoes the caller still disconnect it properly?\n"},{"id":"125104","messageId":"20091015204543.GP10505@spearce.org","threadId":"21244","inReplyTo":"7vfx9k4d33.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-15T20:45:43Z","receivedAt":"2009-10-15T20:45:43Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \n> > It does.  It is caused by the disconnect_helper call inside of\n> > fetch_with_import.  You can't disconnect inside of the fetch method\n> > of a transport, the caller is going to disconnect you a second time.\n> > ...\n> > This bug isn't due to the merge, its a bug in Johan's series that\n> > needs to be fixed before it could merge down to next/master.\n...\n> I am a bit confused about your diagnosis, though.  As far as I recall,\n> Johan's topic itself nor 'pu' with Johan's topic but without v2 of\n> sp/smart-http did not have the issue.\n\nSadly, sometimes double frees do not result in segfaults, other\ntimes they do.  The reason you are not seeing a problem with these\nother variants is because of luck, not code correctness.\n\nActually, after some further research, the bug is not Johan's but is\nactually Daniel's.  Johan, I apologize for claiming it was your bug.\n\nIn:\n\n  commit 23a3380ee9c2d5164712c40f8821cb0fba24e80c\n  Author: Daniel Barkalow <barkalow@iabervon.org>\n  Date:   Thu Sep 3 22:14:01 2009 -0400\n\n    Add support for \"import\" helper command\n\nDaniel introduces the fetch_with_import() function to\ntransport-helper.c.  This method calls disconnect_helper():\n\n+static int fetch_with_import(struct transport *transport,\n+                            int nr_heads, struct ref **to_fetch)\n+{\n...\n+       disconnect_helper(transport);\n+       finish_command(&fastimport);\n\nUnfortunately this is in the middle of the transport_fetch() call\nstack; transport_fetch() called the static fetch() function in\ntransport-helper.c, which in turn called fetch_with_import().\n\nCallers (e.g. builtin-fetch.c) invoke transport_close() when\nthey are done with the handle (see line 704).  That in turn calls\ndisconnect_helper() a second time.\n\nThe disconnect_helper function is not prepared to be called twice:\n\nstatic int disconnect_helper(struct transport *transport)\n{\n\tstruct helper_data *data = transport->data;\n\tif (data->helper) {\n\t...\n\t}\n\tfree(data);\n\treturn 0;\n}\n\nBecause of that unexpected invocation inside of fetch_with_import\nwe have already free'd the memory block used by transport->data,\nand the second invocation attempts to free it again.  Worse, if the\nblock was reused by a subsequent malloc, data->helper might not be\nNULL, and we'd enter into the if block and do its work again.\n\nLong story short, transport_close() is what is supposed to perform\nthe work that disconnect_helper does, as its the final thing right\nbefore we free the struct transport block.  Free'ing the data block\ninside of the fetch or push functions is wrong.\n\nIts fine to close the helper and restart it within the single\nlifespan of a struct transport, but dammit, don't free the\nstruct helper_data until transport_close().\n\n-- \nShawn.\n"},{"id":"125135","messageId":"ca433830910152120l1bd358ads6401572ccc05b29@mail.gmail.com","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-16T04:20:29Z","receivedAt":"2009-10-16T04:20:29Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"On Wed, Oct 14, 2009 at 11:36 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> This series is still lacking:\n>\n>  * The HTTP protocol documentation\n>  * Tests for the smart http transport code (existing tests pass)\n\n* Dumb HTTP push support\n\nIt would be really nice if git-http-backend supported dumb pushing\nover WebDAV.  Currently, to support both smart and dumb pushing, one\nhas to configure Apache in a very awkward and confusing way (if it is\neven possible - I'm still trying to figure it out).  Without some way\nto support older clients, it will be very hard to transition to the\nnew protocol.\n\n\nAlso, your examples use \"DocumentRoot /pub/git\", but I think most\npeople would want to have their main website as the DocumentRoot, have\nthe URL \"/git\" serve the repositories through gitweb, and have that\nsame \"/git\" URL be `git clone'-able.  The Apache configuration for\nthis is complicated and non-intuitive, so I think an example of this\nin the documentation is warranted.  The following accomplishes what I\ndescribe, except it does not work with dump HTTP push, and does not\nallow anonymous read-only access.  (I am currently trying to figure\nout how to do both of these things.)\n\n-- 8< --\nDocumentRoot /var/www/htdocs\n# Rest of httpd config...\n\n<Directory /pub/git>\n   SetHandler git-http-backend\n   Action git-http-backend /git-http-backend virtual\n</Directory>\n\n# To allow anonymous access (but to disallow pushing), comment out the\nfollowing Location block.\n<Location /git-http-backend>\n   AuthName \"git\"\n   AuthType Basic\n   AuthUserFile /etc/apache2/passwd/git.passwd\n   Require valid-user\n</Location>\n\n# Each of the following Aliases should be one line:\nAliasMatch ^/git/(.*/(HEAD|info/refs|objects/(info/[^/]*|[0-9a-f]{2}/[0-9a-f]{38}|pack/pack-[0-9a-f]{40}\\.(pack|idx))|git-(upload|receive)-pack))$\n\"/pub/git/$1\"\nScriptAlias /git \"/var/www/cgi-bin/gitweb.cgi\"\nScriptAlias /git-http-backend \"/usr/local/libexec/git-core/git-http-backend\"\n-- >8 --\n"},{"id":"125182","messageId":"20091016143154.GS10505@spearce.org","threadId":"21244","inReplyTo":"ca433830910152120l1bd358ads6401572ccc05b29@mail.gmail.com","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-16T14:31:54Z","receivedAt":"2009-10-16T14:31:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Mark Lodato <lodatom@gmail.com> wrote:\n> On Wed, Oct 14, 2009 at 11:36 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> > This series is still lacking:\n> >\n> > ??* The HTTP protocol documentation\n> > ??* Tests for the smart http transport code (existing tests pass)\n> \n> * Dumb HTTP push support\n\nI'm not interested in implementing a WebDAV server.  13 years\nago when WebDAV was the new shiny I considered it.  Today, bleh,\nno desire.\n \n> It would be really nice if git-http-backend supported dumb pushing\n> over WebDAV.  Currently, to support both smart and dumb pushing, one\n> has to configure Apache in a very awkward and confusing way (if it is\n> even possible - I'm still trying to figure it out).\n\nSure, its confusing, its one reason nobody uses it.  Another is\nthat pushing over WebDAV is slow and error prone, locks get taken\nand have to get released, its a general mess.\n\n> Without some way\n> to support older clients, it will be very hard to transition to the\n> new protocol.\n\nWhy?\n\nSmart HTTP is primarily about improving the situation for a client\nfetching from the server.  If the server happens to allow writes,\nusers will just have to upgrade to a new enough version of Git that\nunderstands the push variant of the protocol.\n\nIf users don't want to upgrade, or can't upgrade, then you can't\npush over HTTP.  Simple.\n\nReally, what it comes down to is, I don't think it matters that\nwe don't have backwards compatiblity for pushing through WebDAV.\nIf you think it matters, you are free to write a patch series on\ntop of mine which adds the functionality.  But don't wait for me\nto do it, it won't happen.\n \n> Also, your examples use \"DocumentRoot /pub/git\", but I think most\n> people would want to have their main website as the DocumentRoot, have\n> the URL \"/git\" serve the repositories through gitweb, and have that\n> same \"/git\" URL be `git clone'-able.\n\nWhy not have git-http-backend exec gitweb when it gets a request\nfor the repository itself?  Why do you have to go through such\ncontortions in Apache for this?  The two CGIs are shipped in the\nsame software package, surely one could actually invoke the other.\n\n> The Apache configuration for\n> this is complicated and non-intuitive, so I think an example of this\n> in the documentation is warranted.  The following accomplishes what I\n> describe, except it does not work with dump HTTP push, and does not\n> allow anonymous read-only access.  (I am currently trying to figure\n> out how to do both of these things.)\n\nYes, I'd like to have examples in the git-http-backend manpage.\nI put a couple in there already, but they don't consider gitweb\nbecause I assumed we'd find a way to have gitweb be invoked out\nof git-http-backend.  Unfortunately that hasn't happened yet.\n \n-- \nShawn.\n"},{"id":"125216","messageId":"ca433830910161604g5a6bde76n26eb2b1e8155fb36@mail.gmail.com","threadId":"21244","inReplyTo":"20091016143154.GS10505@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2009-10-16T23:04:45Z","receivedAt":"2009-10-16T23:04:45Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"I just realized I forgot to say something in my last email: THANK\nYOU!!!  I have been looking forward to this for a long time.  I was\nplanning to one day to sit down and start thinking about how to\nimplement a smart protocol, and then I see a post saying that not only\nhas someone figured out the protocol, but he has implemented it!\nAmazing!  This is really crucial for corporate adoption, at least at\nmy job.  We need to have strong authentication for many users, and the\nSSH key management is just a nightmare, not to mention that not all\nusers can SSH due to firewalls.  This will save me so much time and\nfrustration.  Thanks!\n\nOn Fri, Oct 16, 2009 at 10:31 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> If users don't want to upgrade, or can't upgrade, then you can't\n> push over HTTP.  Simple.\n\nYeah, I realized after I wrote my previous email that it probably\ndoesn't matter - the current state of HTTP push is so awful that no\none probably uses it!\n\n> Really, what it comes down to is, I don't think it matters that\n> we don't have backwards compatiblity for pushing through WebDAV.\n> If you think it matters, you are free to write a patch series on\n> top of mine which adds the functionality.  But don't wait for me\n> to do it, it won't happen.\n\nAgreed.  I was just wondering if it was on the to-do list for the far\noff future.  Either way, it should probably be noted in the\ndocumentation that dumb push is not supported.\n\n>> Also, your examples use \"DocumentRoot /pub/git\", but I think most\n>> people would want to have their main website as the DocumentRoot, have\n>> the URL \"/git\" serve the repositories through gitweb, and have that\n>> same \"/git\" URL be `git clone'-able.\n>\n> Why not have git-http-backend exec gitweb when it gets a request\n> for the repository itself?  Why do you have to go through such\n> contortions in Apache for this?  The two CGIs are shipped in the\n> same software package, surely one could actually invoke the other.\n>\n> [snip]\n>\n> Yes, I'd like to have examples in the git-http-backend manpage.\n> I put a couple in there already, but they don't consider gitweb\n> because I assumed we'd find a way to have gitweb be invoked out\n> of git-http-backend.  Unfortunately that hasn't happened yet.\n\nThe gitweb part is just bonus.  (The only thing for gitweb is the one\nScriptAlias line.)  The real challenge is getting git-http-backend to\nserve repositories out of something other than DocumentRoot - say\nDocumentRoot is /var/www/htdocs but your git repositories are in\n/pub/git - which is why I posted the configuration.  If you'd like, I\ncan send you a patch to add this to the documentation.\n\nOne idea to improve the situation is to first try\n$GIT_PROJECT_ROOT$PATH_INFO, falling back to $PATH_TRANSLATED if\n$GIT_PROJECT_ROOT is empty.  This would make the configuration simple:\n\n-- 8< --\nSetEnv GIT_PROJECT_ROOT /pub/git\nScriptAlias /git /usr/libexec/git-core/git-http-backend\n-- >8 --\n\nAs far as having git-http-backend launch an external process such as\ngitweb, I personally don't think this is important enough to block\nthis from continuing.  One could configure the webserver as I have in\nmy previous email until such a feature is implemented.  For cgit, the\nsolution is simple - just integrate git-http-backend into the\nexecutable.\n\nRegards,\nMark\n"},{"id":"125217","messageId":"20091016231621.GW10505@spearce.org","threadId":"21244","inReplyTo":"ca433830910161604g5a6bde76n26eb2b1e8155fb36@mail.gmail.com","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-16T23:16:21Z","receivedAt":"2009-10-16T23:16:21Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Mark Lodato <lodatom@gmail.com> wrote:\n> The gitweb part is just bonus.  (The only thing for gitweb is the one\n> ScriptAlias line.)  The real challenge is getting git-http-backend to\n> serve repositories out of something other than DocumentRoot - say\n> DocumentRoot is /var/www/htdocs but your git repositories are in\n> /pub/git - which is why I posted the configuration.  If you'd like, I\n> can send you a patch to add this to the documentation.\n\nYes, a patch would be wonderful.\n \n> One idea to improve the situation is to first try\n> $GIT_PROJECT_ROOT$PATH_INFO, falling back to $PATH_TRANSLATED if\n> $GIT_PROJECT_ROOT is empty.  This would make the configuration simple:\n> \n> -- 8< --\n> SetEnv GIT_PROJECT_ROOT /pub/git\n> ScriptAlias /git /usr/libexec/git-core/git-http-backend\n> -- >8 --\n\nOooh.  Perhaps a good idea.  :-)\n\n-- \nShawn.\n"},{"id":"125321","messageId":"20091019105921.d58c2728.rctay89@gmail.com","threadId":"21244","inReplyTo":"1255577814-14745-11-git-send-email-spearce@spearce.org","subject":"Re: [RFC PATCH v3 10/17] Move WebDAV HTTP push under remote-curl","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-19T02:59:21Z","receivedAt":"2009-10-19T02:59:21Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Thu, Oct 15, 2009 at 11:36 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> diff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\n> @@ -34,6 +34,10 @@ Commands are given by the caller on the helper's standard input, one per line.\n>        value of the ref. A space-separated list of attributes follows\n>        the name; unrecognized attributes are ignored. After the\n>        complete list, outputs a blank line.\n> ++\n> +If 'push' is supported this may be called as 'list for-push'\n> +to obtain the current refs prior to sending one or more 'push'\n> +commands to the helper.\n\nThe new paragraph should have the same indentation as 'list'.\n\nIt would have been great if you implemented this as a filter, such that\n'list <attr>' lists the refs with the specified attribute <attr>,\nrather than hardcoding it.\n\n> @@ -59,6 +63,22 @@ suitably updated.\n> +When the push is complete, outputs one or more 'ok <dst>' or\n> +'error <dst> <why>?' lines to indicate success or failure of\n> +each pushed ref.  The status report output is terminated by\n> +a blank line.  The option field <why> may be quoted in a C\n> +style string if it contains an LF.\n\nYou should mention that this behaviour only occurs when the\n--helper-status option is used.\n\n> @@ -106,6 +132,11 @@ OPTIONS\n> +'option dry-run' \\{'true'|'false'\\}:\n> +       If true, pretend like the operation completed successfully,\n> +       but don't actually change any repository data.  For most\n> +       helpers this only applies to the 'push', if supported.\n> +\n\nThe 'like' after 'pretend' can be, like, removed. :)\n\n> diff --git a/http-push.c b/http-push.c\n> @@ -1941,9 +1946,14 @@ int main(int argc, char **argv)\n>\n>                if (is_null_sha1(ref->peer_ref->new_sha1)) {\n>                        if (delete_remote_branch(ref->name, 1) == -1) {\n> -                               error(\"Could not remove %s\", ref->name);\n> +                               if (helper_status)\n> +                                       printf(\"error %s cannot remove\\n\", ref->name);\n> +                               else\n> +                                       error(\"Could not remove %s\", ref->name);\n>                                rc = -4;\n>                        }\n\nI think error() calls should be left intact (as indicators to the\nuser), even when --helper-status is specified. It wouldn't affect\ntransport-helper.c's parsing of '(ok|error) <ref>' lines, since it\nreads stdout only.\n\nIn other words, the above would read:\n\n>                                error(\"Could not remove %s\", ref->name);\n> +                               if (helper_status)\n> +                                       printf(\"error %s cannot remove\\n\", ref->name);\n>                                rc = -4;\n>                        }\n\n> @@ -1968,12 +1980,15 @@ int main(int argc, char **argv)\n>                                 * commits at the remote end and likely\n>                                 * we were not up to date to begin with.\n>                                 */\n> -                               error(\"remote '%s' is not an ancestor of\\n\"\n> -                                     \"local '%s'.\\n\"\n> -                                     \"Maybe you are not up-to-date and \"\n> -                                     \"need to pull first?\",\n> -                                     ref->name,\n> -                                     ref->peer_ref->name);\n> +                               if (helper_status)\n> +                                       printf(\"error %s non-fast forward\\n\", ref->name);\n> +                               else\n> +                                       error(\"remote '%s' is not an ancestor of\\n\"\n> +                                                 \"local '%s'.\\n\"\n> +                                                 \"Maybe you are not up-to-date and \"\n> +                                                 \"need to pull first?\",\n> +                                                 ref->name,\n> +                                                 ref->peer_ref->name);\n>                                rc = -2;\n>                                continue;\n>                        }\n\nSame here.\n\n> @@ -1987,14 +2002,20 @@ int main(int argc, char **argv)\n>                /* Lock remote branch ref */\n>                ref_lock = lock_remote(ref->name, LOCK_TIME);\n>                if (ref_lock == NULL) {\n> -                       fprintf(stderr, \"Unable to lock remote branch %s\\n\",\n> -                               ref->name);\n> +                       if (helper_status)\n> +                               printf(\"error %s lock error\\n\", ref->name);\n> +                       else\n> +                               fprintf(stderr, \"Unable to lock remote branch %s\\n\",\n> +                                       ref->name);\n>                        rc = 1;\n>                        continue;\n>                }\n\nSame here.\n\nTwo more areas in http-push.c that should have status messages\n(generated on top of pu):\n\n(I'm not sure what ref should read when there's no match, but\ntransport-helper.c should have no problems parsing it with 'null'.)\n\n-->8--\n\ndiff --git a/http-push.c b/http-push.c\nindex 9010ccc..e979feb 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1916,9 +1916,12 @@ int main(int argc, char **argv)\n\n \t/* Remove a remote branch if -d or -D was specified */\n \tif (delete_branch) {\n-\t\tif (delete_remote_branch(refspec[0], force_delete) == -1)\n+\t\tif (delete_remote_branch(refspec[0], force_delete) == -1) {\n \t\t\tfprintf(stderr, \"Unable to delete remote branch %s\\n\",\n \t\t\t\trefspec[0]);\n+\t\t\tif (helper_status)\n+\t\t\t\tprintf(\"error %s cannot remove\\n\", refspec[0]);\n+\t\t}\n \t\tgoto cleanup;\n \t}\n\n@@ -1930,6 +1933,8 @@ int main(int argc, char **argv)\n \t}\n \tif (!remote_refs) {\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\");\n+\t\tif (helper_status)\n+\t\t\tprintf(\"error null no match\\n\");\n \t\trc = 0;\n \t\tgoto cleanup;\n \t}\n\n--\nCheers,\nRay Chuan\n"},{"id":"125696","messageId":"20091022192149.6117@nanako3.lavabit.com","threadId":"21244","inReplyTo":"20091015204543.GP10505@spearce.org","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-10-22T10:21:49Z","receivedAt":"2009-10-22T10:21:49Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting \"Shawn O. Pearce\" <spearce@spearce.org>\n\n> Actually, after some further research, the bug is not Johan's but is\n> actually Daniel's.  Johan, I apologize for claiming it was your bug.\n> ...\n> Long story short, transport_close() is what is supposed to perform\n> the work that disconnect_helper does, as its the final thing right\n> before we free the struct transport block.  Free'ing the data block\n> inside of the fetch or push functions is wrong.\n>\n> Its fine to close the helper and restart it within the single\n> lifespan of a struct transport, but dammit, don't free the\n> struct helper_data until transport_close().\n\nPing? Are there any progress on this issue?\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"125702","messageId":"alpine.LNX.2.00.0910221041562.14365@iabervon.org","threadId":"21244","inReplyTo":"20091022192149.6117@nanako3.lavabit.com","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-10-22T14:46:01Z","receivedAt":"2009-10-22T14:46:01Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Thu, 22 Oct 2009, Nanako Shiraishi wrote:\n\n> Quoting \"Shawn O. Pearce\" <spearce@spearce.org>\n> \n> > Actually, after some further research, the bug is not Johan's but is\n> > actually Daniel's.  Johan, I apologize for claiming it was your bug.\n> > ...\n> > Long story short, transport_close() is what is supposed to perform\n> > the work that disconnect_helper does, as its the final thing right\n> > before we free the struct transport block.  Free'ing the data block\n> > inside of the fetch or push functions is wrong.\n> >\n> > Its fine to close the helper and restart it within the single\n> > lifespan of a struct transport, but dammit, don't free the\n> > struct helper_data until transport_close().\n> \n> Ping? Are there any progress on this issue?\n\nAh, right. Shawn's analysis is correct, and I should have a different \nfunction to just finish the helper, but leave the rest of the data alone. \n(when I wrote it originally, I didn't have anything other than the \nconnection in there, so it was right to clear it, but now there's a real \nhelper_data and it needs to do the right things).\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"125735","messageId":"200910222148.31016.mcamen@mcamen.de","threadId":"21244","inReplyTo":"ca433830910161604g5a6bde76n26eb2b1e8155fb36@mail.gmail.com","subject":"Re: [RFC PATCH v3 00/17] Return of smart HTTP","fromName":"Marcus Camen","fromEmail":"mcamen@mcamen.de","sentAt":"2009-10-22T19:48:30Z","receivedAt":"2009-10-22T19:48:30Z","isPatch":true,"sender":{"key":"mcamen@mcamen.de","avatar":null},"body":"On Samstag 17 Oktober 2009, Mark Lodato wrote:\n> I just realized I forgot to say something in my last email: THANK\n> YOU!!!  I have been looking forward to this for a long time.  I was\n> planning to one day to sit down and start thinking about how to\n> implement a smart protocol, and then I see a post saying that not only\n> has someone figured out the protocol, but he has implemented it!\n> Amazing!  This is really crucial for corporate adoption, at least at\n> my job.  We need to have strong authentication for many users, and the\n> SSH key management is just a nightmare, not to mention that not all\n> users can SSH due to firewalls.  This will save me so much time and\n> frustration.  Thanks!\n\nAs I am using git in a corporate environment I couldn't agree more. smart-\nhttp definitely is the most import addition to git in the last months.\n\nSo far I didn't carry out extensive production runs but my first tests \nalready showed that the smart-http backend solves many problems we have \nwith the dumb webdav approach (no hooks, insane amount of http requests, \nslow performance, ...).\n\nAs I have a systems engineer (not a C coder) perspective on git I cannot \ncomment an any possible glitches of this implementation. I just want to \nmake sure that everyone recognizes just how import smart-http is for \ncorporate environments and that the current patch already solves a lot of \nproblems.\n\n\nRegards,\nMarcus\n"},{"id":"125886","messageId":"20091025231651.18c75559.rctay89@gmail.com","threadId":"21244","inReplyTo":"1255577814-14745-1-git-send-email-spearce@spearce.org","subject":"[PATCH 0/6] http: push and test fixes","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:16:51Z","receivedAt":"2009-10-25T15:16:51Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"This series applies on top of pu, and should apply cleanly on top of\nShawn's v3-smart-http branch.\n\nPatch 1: fixes a bug in http-push.c when fetching packs. This issue is\n  minor and is unlikely to be triggered by normal users (for a possible\n  trigger, see the \"http-push fetches packed objects\" test in\n  t5540-http-push).\n\nPatch 2: here, I collect my comments to Shawn's \"Move WebDAV HTTP push\n  under remote-curl\" on the disabling of messages to stderr when\n  --helper-status is used with http-push. I hope this will make it\n  easier for Shawn to squash into his series, in the event he decides\n  to.\n\nPatch 3: also in response to Shawn's \"Move WebDAV HTTP push under\n  remote-curl\", I collect here my mini-patch to add more reports for\n  transport-helper. Again, I hope this will make it easier for Shawn to\n  squash into his series.\n\nPatch 4-7: update tests, as Shawn's patches changed the behaviour of\n  the http push mechanism (dumb).\n\nTay Ray Chuan (7):\n  http-push: fix check condition on http.c::finish_http_pack_request()\n  http-push: allow stderr messages to appear alongside helper_status\n    ones\n  http-push: add more 'error <dst> <why>' status reports\n  t5540-http-push: expect success when pushing without arguments\n  t5540-http-push: check existence of fetched files\n  t5540-http-push: when deleting remote refs, don't need to branch -d\n    -r\n  t5540-http-push: remove redundant fetches\n\n http-push.c          |   30 ++++++++++++++++--------------\n t/t5540-http-push.sh |   38 +++++++++++++++++++-------------------\n 2 files changed, 35 insertions(+), 33 deletions(-)\n"},{"id":"125888","messageId":"20091025231809.15b470fa.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025231651.18c75559.rctay89@gmail.com","subject":"[PATCH 1/7] http-push: fix check condition on http.c::finish_http_pack_request()","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:18:09Z","receivedAt":"2009-10-25T15:18:09Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Check that http.c::finish_http_pack_request() returns 0 (for success).\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 9010ccc..24eec73 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -605,7 +605,7 @@ static void finish_request(struct transfer_request *request)\n \t\t\tpreq = (struct http_pack_request *)request->userData;\n\n \t\t\tif (preq) {\n-\t\t\t\tif (finish_http_pack_request(preq) > 0)\n+\t\t\t\tif (finish_http_pack_request(preq) == 0)\n \t\t\t\t\tfail = 0;\n \t\t\t\trelease_http_pack_request(preq);\n \t\t\t}\n--\n1.6.4.4\n"},{"id":"125887","messageId":"20091025231932.be9a6dfa.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025231651.18c75559.rctay89@gmail.com","subject":"[PATCH 2/7] http-push: allow stderr messages to appear alongside helper_status ones","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:19:32Z","receivedAt":"2009-10-25T15:19:32Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"These messages notifies user over pushing progress (or the lack\nthereof). It is safe for them to appear alongside status reports\n('ok|error <dst>'), since the reports go to stdout, while the\nnotifications go to stderr.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |   21 +++++++++------------\n 1 files changed, 9 insertions(+), 12 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 24eec73..b97ea1f 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1946,10 +1946,9 @@ int main(int argc, char **argv)\n\n \t\tif (is_null_sha1(ref->peer_ref->new_sha1)) {\n \t\t\tif (delete_remote_branch(ref->name, 1) == -1) {\n+\t\t\t\terror(\"Could not remove %s\", ref->name);\n \t\t\t\tif (helper_status)\n \t\t\t\t\tprintf(\"error %s cannot remove\\n\", ref->name);\n-\t\t\t\telse\n-\t\t\t\t\terror(\"Could not remove %s\", ref->name);\n \t\t\t\trc = -4;\n \t\t\t}\n \t\t\telse if (helper_status)\n@@ -1980,15 +1979,14 @@ int main(int argc, char **argv)\n \t\t\t\t * commits at the remote end and likely\n \t\t\t\t * we were not up to date to begin with.\n \t\t\t\t */\n+\t\t\t\terror(\"remote '%s' is not an ancestor of\\n\"\n+\t\t\t\t      \"local '%s'.\\n\"\n+\t\t\t\t      \"Maybe you are not up-to-date and \"\n+\t\t\t\t      \"need to pull first?\",\n+\t\t\t\t      ref->name,\n+\t\t\t\t      ref->peer_ref->name);\n \t\t\t\tif (helper_status)\n \t\t\t\t\tprintf(\"error %s non-fast forward\\n\", ref->name);\n-\t\t\t\telse\n-\t\t\t\t\terror(\"remote '%s' is not an ancestor of\\n\"\n-\t\t\t\t\t\t  \"local '%s'.\\n\"\n-\t\t\t\t\t\t  \"Maybe you are not up-to-date and \"\n-\t\t\t\t\t\t  \"need to pull first?\",\n-\t\t\t\t\t\t  ref->name,\n-\t\t\t\t\t\t  ref->peer_ref->name);\n \t\t\t\trc = -2;\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -2011,11 +2009,10 @@ int main(int argc, char **argv)\n \t\t/* Lock remote branch ref */\n \t\tref_lock = lock_remote(ref->name, LOCK_TIME);\n \t\tif (ref_lock == NULL) {\n+\t\t\tfprintf(stderr, \"Unable to lock remote branch %s\\n\",\n+\t\t\t\tref->name);\n \t\t\tif (helper_status)\n \t\t\t\tprintf(\"error %s lock error\\n\", ref->name);\n-\t\t\telse\n-\t\t\t\tfprintf(stderr, \"Unable to lock remote branch %s\\n\",\n-\t\t\t\t\tref->name);\n \t\t\trc = 1;\n \t\t\tcontinue;\n \t\t}\n--\n1.6.4.4\n"},{"id":"125889","messageId":"20091025232044.06d7ce5c.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025231932.be9a6dfa.rctay89@gmail.com","subject":"[PATCH 3/7] http-push: add more 'error <dst> <why>' status reports","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:20:44Z","receivedAt":"2009-10-25T15:20:44Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Complement c6aa27e (Move WebDAV HTTP push under remote-curl, Wed Oct\n14) by adding error reports for 'cannot remove' (failed to delete\nbranch) and 'no match'.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex b97ea1f..f10803a 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1916,9 +1916,12 @@ int main(int argc, char **argv)\n\n \t/* Remove a remote branch if -d or -D was specified */\n \tif (delete_branch) {\n-\t\tif (delete_remote_branch(refspec[0], force_delete) == -1)\n+\t\tif (delete_remote_branch(refspec[0], force_delete) == -1) {\n \t\t\tfprintf(stderr, \"Unable to delete remote branch %s\\n\",\n \t\t\t\trefspec[0]);\n+\t\t\tif (helper_status)\n+\t\t\t\tprintf(\"error %s cannot remove\\n\", refspec[0]);\n+\t\t}\n \t\tgoto cleanup;\n \t}\n\n@@ -1930,6 +1933,8 @@ int main(int argc, char **argv)\n \t}\n \tif (!remote_refs) {\n \t\tfprintf(stderr, \"No refs in common and none specified; doing nothing.\\n\");\n+\t\tif (helper_status)\n+\t\t\tprintf(\"error null no match\\n\");\n \t\trc = 0;\n \t\tgoto cleanup;\n \t}\n--\n1.6.4.4\n"},{"id":"125890","messageId":"20091025232142.6558d9e4.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025232044.06d7ce5c.rctay89@gmail.com","subject":"[PATCH 4/7] t5540-http-push: expect success when pushing without arguments","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:21:42Z","receivedAt":"2009-10-25T15:21:42Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Remove mention of packed refs from the test description, and expect\nsuccess.\n\nThe dumb http push mechanism used to learn about the refs on the remote\nrepository by recursing through the /refs directory in the repository.\nThis meant that it was unaware of packed refs, since it did not read\n/packed-refs. Thus the push failed, as no remote refs were found.\n\nBut after c6aa27e (Move WebDAV HTTP push under remote-curl, Wed Oct\n14), the dumb http mechanism additionally learns about the refs through\n/info/refs (via remote-curl.c::get_refs), so it is aware of packed\nrefs, even though it still doesn't read /packed-refs (assuming /info/\nrefs is up-to-date). Thus the push now succeeds.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n t/t5540-http-push.sh |   12 +-----------\n 1 files changed, 1 insertions(+), 11 deletions(-)\n\ndiff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh\nindex f4a2cf6..c7b8a40 100755\n--- a/t/t5540-http-push.sh\n+++ b/t/t5540-http-push.sh\n@@ -45,7 +45,7 @@ test_expect_success 'clone remote repository' '\n \tgit clone $HTTPD_URL/test_repo.git test_repo_clone\n '\n\n-test_expect_failure 'push to remote repository with packed refs' '\n+test_expect_success 'push to remote repository' '\n \tcd \"$ROOT_PATH\"/test_repo_clone &&\n \t: >path2 &&\n \tgit add path2 &&\n@@ -57,16 +57,6 @@ test_expect_failure 'push to remote repository with packed refs' '\n \t test $HEAD = $(git rev-parse --verify HEAD))\n '\n\n-test_expect_success ' push to remote repository with unpacked refs' '\n-\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git &&\n-\t rm packed-refs &&\n-\t git update-ref refs/heads/master \\\n-\t\t0c973ae9bd51902a28466f3850b543fa66a6aaf4) &&\n-\tgit push &&\n-\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git &&\n-\t test $HEAD = $(git rev-parse --verify HEAD))\n-'\n-\n test_expect_success 'http-push fetches unpacked objects' '\n \tcp -R \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git \\\n \t\t\"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_unpacked.git &&\n--\n1.6.4.4\n"},{"id":"125891","messageId":"20091025232227.96769e50.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025232142.6558d9e4.rctay89@gmail.com","subject":"[PATCH 5/7] t5540-http-push: check existence of fetched files","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:22:27Z","receivedAt":"2009-10-25T15:22:27Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n t/t5540-http-push.sh |   23 ++++++++++++++++++-----\n 1 files changed, 18 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh\nindex c7b8a40..ee7f84a 100755\n--- a/t/t5540-http-push.sh\n+++ b/t/t5540-http-push.sh\n@@ -64,13 +64,18 @@ test_expect_success 'http-push fetches unpacked objects' '\n \tgit clone $HTTPD_URL/test_repo_unpacked.git \\\n \t\t\"$ROOT_PATH\"/fetch_unpacked &&\n\n+\tCOMMIT_PATH=$(git rev-parse --verify HEAD |\n+\t\tsed -e \"s/^\\([0-9a-f]\\{2\\}\\)\\([0-9a-f]\\{38\\}\\)/\\1\\/\\2/\") &&\n+\n \t# By reset, we force git to retrieve the object\n \t(cd \"$ROOT_PATH\"/fetch_unpacked &&\n \t git reset --hard HEAD^ &&\n \t git remote rm origin &&\n \t git reflog expire --expire=0 --all &&\n \t git prune &&\n-\t git push -f -v $HTTPD_URL/test_repo_unpacked.git master)\n+\t test ! -e \".git/objects/$COMMIT_PATH\" &&\n+\t git push -f -v $HTTPD_URL/test_repo_unpacked.git master &&\n+\t test -e \".git/objects/$COMMIT_PATH\")\n '\n\n test_expect_success 'http-push fetches packed objects' '\n@@ -80,9 +85,14 @@ test_expect_success 'http-push fetches packed objects' '\n \tgit clone $HTTPD_URL/test_repo_packed.git \\\n \t\t\"$ROOT_PATH\"/test_repo_clone_packed &&\n\n-\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_packed.git &&\n-\t git --bare repack &&\n-\t git --bare prune-packed) &&\n+\tcd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_packed.git &&\n+\tgit --bare repack &&\n+\tgit --bare prune-packed &&\n+\n+\tPACK_PATH=$(cat \"objects/info/packs\" |\n+\t\tsed -e \"s/^P \\(pack-[0-9a-f]\\{40\\}\\.pack\\)/\\1/\") &&\n+\tCOMMIT_PATH=$(git rev-parse --verify HEAD |\n+\t\tsed -e \"s/^\\([0-9a-f]\\{2\\}\\)\\([0-9a-f]\\{38\\}\\)/\\1\\/\\2/\") &&\n\n \t# By reset, we force git to retrieve the packed object\n \t(cd \"$ROOT_PATH\"/test_repo_clone_packed &&\n@@ -90,7 +100,10 @@ test_expect_success 'http-push fetches packed objects' '\n \t git remote rm origin &&\n \t git reflog expire --expire=0 --all &&\n \t git prune &&\n-\t git push -f -v $HTTPD_URL/test_repo_packed.git master)\n+\t test ! -e \".git/objects/$COMMIT_PATH\" &&\n+\t test ! -e \".git/objects/pack/$PACK_PATH\" &&\n+\t git push -f -v $HTTPD_URL/test_repo_packed.git master &&\n+\t test -e \".git/objects/pack/$PACK_PATH\")\n '\n\n test_expect_success 'create and delete remote branch' '\n--\n1.6.4.4\n"},{"id":"125892","messageId":"20091025232310.2c512a1b.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025232227.96769e50.rctay89@gmail.com","subject":"[PATCH 6/7] t5540-http-push: when deleting remote refs, don't need to branch -d -r","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:23:10Z","receivedAt":"2009-10-25T15:23:10Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"In c6aa27e (Move WebDAV HTTP push under remote-curl, Wed Oct 14),\ntransport->push_refs became defined for http pushing. This enabled the\ncode to update local tracking refs (transport.c::update_tracking_ref()\nvia transport.c::transport_push()), allowing these refs to be deleted\ntogether with the remote ref, thus doing away with a manual branch -d\n-r.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n t/t5540-http-push.sh |    1 -\n 1 files changed, 0 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh\nindex ee7f84a..6bb5afa 100755\n--- a/t/t5540-http-push.sh\n+++ b/t/t5540-http-push.sh\n@@ -116,7 +116,6 @@ test_expect_success 'create and delete remote branch' '\n \tgit push origin dev &&\n \tgit fetch &&\n \tgit push origin :dev &&\n-\tgit branch -d -r origin/dev &&\n \tgit fetch &&\n \ttest_must_fail git show-ref --verify refs/remotes/origin/dev\n '\n--\n1.6.4.4\n"},{"id":"125893","messageId":"20091025232401.e82925a9.rctay89@gmail.com","threadId":"21244","inReplyTo":"20091025232310.2c512a1b.rctay89@gmail.com","subject":"[PATCH 7/7] t5540-http-push: remove redundant fetches","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-25T15:24:01Z","receivedAt":"2009-10-25T15:24:01Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n t/t5540-http-push.sh |    2 --\n 1 files changed, 0 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh\nindex 6bb5afa..3852dcb 100755\n--- a/t/t5540-http-push.sh\n+++ b/t/t5540-http-push.sh\n@@ -114,9 +114,7 @@ test_expect_success 'create and delete remote branch' '\n \ttest_tick &&\n \tgit commit -m dev &&\n \tgit push origin dev &&\n-\tgit fetch &&\n \tgit push origin :dev &&\n-\tgit fetch &&\n \ttest_must_fail git show-ref --verify refs/remotes/origin/dev\n '\n\n--\n1.6.4.4\n"},{"id":"125900","messageId":"20091025161630.GB8532@localhost","threadId":"21244","inReplyTo":"20091025232142.6558d9e4.rctay89@gmail.com","subject":"Re: [PATCH 4/7] t5540-http-push: expect success when pushing without arguments","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2009-10-25T16:16:31Z","receivedAt":"2009-10-25T16:16:31Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Sun, Oct 25, 2009 at 11:21:42PM +0800, Tay Ray Chuan wrote:\n\n> But after c6aa27e (Move WebDAV HTTP push under remote-curl, Wed Oct\n> 14), the dumb http mechanism additionally learns about the refs through\n> /info/refs (via remote-curl.c::get_refs), so it is aware of packed\n> refs, even though it still doesn't read /packed-refs (assuming /info/\n> refs is up-to-date). Thus the push now succeeds.\n\nIf left as is, it should actually fail, and for two reasons.\n\n1. push aborts immediately because info/refs is not updated by \"git\nupdate-ref\" so that it thinks everything is up-to-date from the previous\ntest. The old http-push code did not check for up-to-date refs which is why\nthis problem did not trigger so far. This is fixed in \"update http tests\naccording to remote-curl capabilities\".\n\n2. Even if info/refs is updated, a bug in the new remote-helper causes push\nto exit with error status 128. This is fixed in \"remote-helpers: return\nsuccessfully if everything up-to-date\".\n\nThis is unrelated to the original intention of the test, but I think it\ndoesn't hurt to keep it around, at least for the time being.\n\nIt's unfortunate that we both worked on t5540 at the same time. But except\nfor this point I think our changes are compatible.\n\nClemens\n"},{"id":"125901","messageId":"20091025164913.GA11267@localhost","threadId":"21244","inReplyTo":"20091025232227.96769e50.rctay89@gmail.com","subject":"Re: [PATCH 5/7] t5540-http-push: check existence of fetched files","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2009-10-25T16:49:13Z","receivedAt":"2009-10-25T16:49:13Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Sun, Oct 25, 2009 at 11:22:27PM +0800, Tay Ray Chuan wrote:\n\n>  \t# By reset, we force git to retrieve the object\n>  \t(cd \"$ROOT_PATH\"/fetch_unpacked &&\n>  \t git reset --hard HEAD^ &&\n>  \t git remote rm origin &&\n>  \t git reflog expire --expire=0 --all &&\n>  \t git prune &&\n> -\t git push -f -v $HTTPD_URL/test_repo_unpacked.git master)\n> +\t test ! -e \".git/objects/$COMMIT_PATH\" &&\n> +\t git push -f -v $HTTPD_URL/test_repo_unpacked.git master &&\n> +\t test -e \".git/objects/$COMMIT_PATH\")\n>  '\n\nThis fails with smart HTTP. First of all, the objects are packed,\nso I substituted the above with\n\n ! git rev-list -1 $HEAD &&\n git push -f -v $HTTPD_GIT_URL/test_repo_unpacked.git master &&\n git rev-list -1 $HEAD > rev-list.out &&\n test -n rev-list.out\n\nThat should be an equivalent test, right? But still, why should push\nre-fetch the commit we just pruned? Smart HTTP does not do that and\ntherefore fails the last rev-list test:\n\n ++ git rev-list -1 9d498b0bbc2a25438e2fbd19081948da86028c23\n fatal: bad object 9d498b0bbc2a25438e2fbd19081948da86028c23\n\nClemens\n"},{"id":"125990","messageId":"alpine.LNX.2.00.0910270032170.14365@iabervon.org","threadId":"21244","inReplyTo":"20091015204543.GP10505@spearce.org","subject":"[PATCH] Fix memory leak in transport-helper","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-10-27T04:55:46Z","receivedAt":"2009-10-27T04:55:46Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Thu, 15 Oct 2009, Shawn O. Pearce wrote:\n\n> The disconnect_helper function is not prepared to be called twice:\n> \n> static int disconnect_helper(struct transport *transport)\n> {\n> \tstruct helper_data *data = transport->data;\n> \tif (data->helper) {\n> \t...\n> \t}\n> \tfree(data);\n> \treturn 0;\n> }\n\nActually, my version just leaks transport->data; it looks like the \n\"free(data);\" line comes from your patch \"remote-helpers: Support custom \ntransport options\". Here's a version (against origin/master) that neither \nleaks memory nor frees too much for disconnecting temporarily. \n\ncommit 8731d804c20828d20130e286f088613b5d33d57a\nAuthor: Daniel Barkalow <barkalow@iabervon.org>\nDate:   Tue Oct 27 00:42:16 2009 -0400\n\n    Fix memory leak in helper method for disconnect.\n    \n    Since some cases may need to disconnect from the helper and reconnect,\n    wrap the function that just disconnects in a function that also frees\n    transport->data.\n    \n    Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex f57e84c..479539d 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n \treturn 0;\n }\n \n+static int close_helper(struct transport *transport)\n+{\n+\tdisconnect_helper(transport);\n+\tfree(transport->data);\n+\treturn 0;\n+}\n+\n static int fetch_with_fetch(struct transport *transport,\n \t\t\t    int nr_heads, const struct ref **to_fetch)\n {\n@@ -163,6 +170,6 @@ int transport_helper_init(struct transport *transport, const char *name)\n \ttransport->data = data;\n \ttransport->get_refs_list = get_refs_list;\n \ttransport->fetch = fetch;\n-\ttransport->disconnect = disconnect_helper;\n+\ttransport->disconnect = close_helper;\n \treturn 0;\n }\n"},{"id":"126018","messageId":"alpine.DEB.1.00.0910271510430.4985@pacific.mpi-cbg.de","threadId":"21244","inReplyTo":"alpine.LNX.2.00.0910270032170.14365@iabervon.org","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-10-27T14:11:23Z","receivedAt":"2009-10-27T14:11:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 27 Oct 2009, Daniel Barkalow wrote:\n\n> diff --git a/transport-helper.c b/transport-helper.c\n> index f57e84c..479539d 100644\n> --- a/transport-helper.c\n> +++ b/transport-helper.c\n> @@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n>  \treturn 0;\n>  }\n>  \n> +static int close_helper(struct transport *transport)\n> +{\n> +\tdisconnect_helper(transport);\n> +\tfree(transport->data);\n> +\treturn 0;\n> +}\n\nWhy did you not leech the transport->data = NULL; part from Peff/Sverre's \npatch?\n\nCiao,\nDscho\n"},{"id":"126041","messageId":"alpine.LNX.2.00.0910271329510.14365@iabervon.org","threadId":"21244","inReplyTo":"alpine.DEB.1.00.0910271510430.4985@pacific.mpi-cbg.de","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-10-27T17:37:19Z","receivedAt":"2009-10-27T17:37:19Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 27 Oct 2009, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Tue, 27 Oct 2009, Daniel Barkalow wrote:\n> \n> > diff --git a/transport-helper.c b/transport-helper.c\n> > index f57e84c..479539d 100644\n> > --- a/transport-helper.c\n> > +++ b/transport-helper.c\n> > @@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n> >  \treturn 0;\n> >  }\n> >  \n> > +static int close_helper(struct transport *transport)\n> > +{\n> > +\tdisconnect_helper(transport);\n> > +\tfree(transport->data);\n> > +\treturn 0;\n> > +}\n> \n> Why did you not leech the transport->data = NULL; part from Peff/Sverre's \n> patch?\n\nBecause this code is only called just before transport itself is freed by \nthe caller, and, in general, a transport with these methods is invalid \nwithout a valid transport->data. I expect that's also why Peff called it a \nhack not appropriate for actual application.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126045","messageId":"20091027183105.GA9504@sigill.intra.peff.net","threadId":"21244","inReplyTo":"alpine.LNX.2.00.0910271329510.14365@iabervon.org","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-27T18:31:05Z","receivedAt":"2009-10-27T18:31:05Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Oct 27, 2009 at 01:37:19PM -0400, Daniel Barkalow wrote:\n\n> > Why did you not leech the transport->data = NULL; part from Peff/Sverre's \n> > patch?\n> \n> Because this code is only called just before transport itself is freed by \n> the caller, and, in general, a transport with these methods is invalid \n> without a valid transport->data. I expect that's also why Peff called it a \n> hack not appropriate for actual application.\n\nMore or less. I called it a hack because I didn't even look far enough\nto know whether or not that was the case. I was just trying to get it to\nstop segfaulting so Sverre could continue his work.\n\n-Peff\n"},{"id":"126049","messageId":"alpine.DEB.1.00.0910271954020.11562@felix-maschine","threadId":"21244","inReplyTo":"alpine.LNX.2.00.0910271329510.14365@iabervon.org","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-10-27T18:54:31Z","receivedAt":"2009-10-27T18:54:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 27 Oct 2009, Daniel Barkalow wrote:\n\n> On Tue, 27 Oct 2009, Johannes Schindelin wrote:\n> \n> > Hi,\n> > \n> > On Tue, 27 Oct 2009, Daniel Barkalow wrote:\n> > \n> > > diff --git a/transport-helper.c b/transport-helper.c\n> > > index f57e84c..479539d 100644\n> > > --- a/transport-helper.c\n> > > +++ b/transport-helper.c\n> > > @@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n> > >  \treturn 0;\n> > >  }\n> > >  \n> > > +static int close_helper(struct transport *transport)\n> > > +{\n> > > +\tdisconnect_helper(transport);\n> > > +\tfree(transport->data);\n> > > +\treturn 0;\n> > > +}\n> > \n> > Why did you not leech the transport->data = NULL; part from Peff/Sverre's \n> > patch?\n> \n> Because this code is only called just before transport itself is freed by \n> the caller, and, in general, a transport with these methods is invalid \n> without a valid transport->data. I expect that's also why Peff called it a \n> hack not appropriate for actual application.\n\nSo you mean to imply that this method is not about closing, but about \nreleasing the structure.  Right?\n\nCiao,\nDscho\n"},{"id":"126051","messageId":"alpine.LNX.2.00.0910271456410.14365@iabervon.org","threadId":"21244","inReplyTo":"alpine.DEB.1.00.0910271954020.11562@felix-maschine","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-10-27T19:05:57Z","receivedAt":"2009-10-27T19:05:57Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Tue, 27 Oct 2009, Johannes Schindelin wrote:\n\n> Hi,\n> \n> On Tue, 27 Oct 2009, Daniel Barkalow wrote:\n> \n> > On Tue, 27 Oct 2009, Johannes Schindelin wrote:\n> > \n> > > Hi,\n> > > \n> > > On Tue, 27 Oct 2009, Daniel Barkalow wrote:\n> > > \n> > > > diff --git a/transport-helper.c b/transport-helper.c\n> > > > index f57e84c..479539d 100644\n> > > > --- a/transport-helper.c\n> > > > +++ b/transport-helper.c\n> > > > @@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n> > > >  \treturn 0;\n> > > >  }\n> > > >  \n> > > > +static int close_helper(struct transport *transport)\n> > > > +{\n> > > > +\tdisconnect_helper(transport);\n> > > > +\tfree(transport->data);\n> > > > +\treturn 0;\n> > > > +}\n> > > \n> > > Why did you not leech the transport->data = NULL; part from Peff/Sverre's \n> > > patch?\n> > \n> > Because this code is only called just before transport itself is freed by \n> > the caller, and, in general, a transport with these methods is invalid \n> > without a valid transport->data. I expect that's also why Peff called it a \n> > hack not appropriate for actual application.\n> \n> So you mean to imply that this method is not about closing, but about \n> releasing the structure.  Right?\n\nYes, that's the word I was failing to come up with last night, thanks.\nJunio, \"s/close/release/g\" on that patch should improve comprehensibility \ngreatly. (And changing the transport method name would probably also \nimprove matters)\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126077","messageId":"20091028010831.GP10505@spearce.org","threadId":"21244","inReplyTo":"20091019105921.d58c2728.rctay89@gmail.com","subject":"Re: [RFC PATCH v3 10/17] Move WebDAV HTTP push under remote-curl","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-28T01:08:31Z","receivedAt":"2009-10-28T01:08:31Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Tay Ray Chuan <rctay89@gmail.com> wrote:\n> On Thu, Oct 15, 2009 at 11:36 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> > diff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\n> > @@ -34,6 +34,10 @@ Commands are given by the caller on the helper's standard input, one per line.\n> >        value of the ref. A space-separated list of attributes follows\n> >        the name; unrecognized attributes are ignored. After the\n> >        complete list, outputs a blank line.\n> > ++\n> > +If 'push' is supported this may be called as 'list for-push'\n> > +to obtain the current refs prior to sending one or more 'push'\n> > +commands to the helper.\n> \n> The new paragraph should have the same indentation as 'list'.\n\nIsn't the style I have here the standard way of adding a second\nparagraph to a list item?\n \n> It would have been great if you implemented this as a filter, such that\n> 'list <attr>' lists the refs with the specified attribute <attr>,\n> rather than hardcoding it.\n\nAck, will fix.\n \n> > @@ -59,6 +63,22 @@ suitably updated.\n> > +When the push is complete, outputs one or more 'ok <dst>' or\n> > +'error <dst> <why>?' lines to indicate success or failure of\n> > +each pushed ref.  The status report output is terminated by\n> > +a blank line.  The option field <why> may be quoted in a C\n> > +style string if it contains an LF.\n> \n> You should mention that this behaviour only occurs when the\n> --helper-status option is used.\n\nNo.  This manual page is about what a helper program must do, so I\nmean what \"git-remote-curl\" must do.  The fact that git-remote-curl\nhonors this output format via passing the --helper-status option\ninto a command it executes is an implementation detail.\n\n> > @@ -106,6 +132,11 @@ OPTIONS\n> > +'option dry-run' \\{'true'|'false'\\}:\n> > +       If true, pretend like the operation completed successfully,\n> > +       but don't actually change any repository data.  For most\n> > +       helpers this only applies to the 'push', if supported.\n> > +\n> \n> The 'like' after 'pretend' can be, like, removed. :)\n\nThanks, fixed.\n \n> Two more areas in http-push.c that should have status messages\n> (generated on top of pu):\n\nI folded your patches into my series, thanks.\n \n-- \nShawn.\n"},{"id":"126103","messageId":"7vocnsrnok.fsf@alter.siamese.dyndns.org","threadId":"21244","inReplyTo":"alpine.LNX.2.00.0910271456410.14365@iabervon.org","subject":"Re: [PATCH] Fix memory leak in transport-helper","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-28T07:18:51Z","receivedAt":"2009-10-28T07:18:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> On Tue, 27 Oct 2009, Johannes Schindelin wrote:\n>\n>> So you mean to imply that this method is not about closing, but about \n>> releasing the structure.  Right?\n>\n> Yes, that's the word I was failing to come up with last night, thanks.\n> Junio, \"s/close/release/g\" on that patch should improve comprehensibility \n> greatly. (And changing the transport method name would probably also \n> improve matters)\n\nThanks, both.\n"},{"id":"126124","messageId":"be6fef0d0910280401u76033c32j5eb6823a67b204f9@mail.gmail.com","threadId":"21244","inReplyTo":"20091028010831.GP10505@spearce.org","subject":"Re: [RFC PATCH v3 10/17] Move WebDAV HTTP push under remote-curl","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-10-28T11:01:42Z","receivedAt":"2009-10-28T11:01:42Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Wed, Oct 28, 2009 at 9:08 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Isn't the style I have here the standard way of adding a second\n> paragraph to a list item?\n\nsorry, I didn't catch the '+'-line style.\n\n> I folded your patches into my series, thanks.\n\nYou're welcome.\n\n-- \nCheers,\nRay Chuan\n"}]}