{"thread":{"id":"17436","subject":"[PATCH v2] http-push: refactor request url creation","startedAt":"2009-01-29T14:59:07Z","lastAt":"2009-01-29T22:31:52Z","messageCount":4,"participants":["Tay Ray Chuan","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"102464","messageId":"4981C43B.9030409@gmail.com","threadId":"17436","inReplyTo":null,"subject":"[PATCH v2] http-push: refactor request url creation","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-01-29T14:59:07Z","receivedAt":"2009-01-29T14:59:07Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Currently, functions that deal with objects on the remote repository have to allocate and\ndo strcpys to generate the URL.\n\nThis patch saves them this trouble, by providing two functions, \"append_remote_object_url\"\nand \"get_remote_object_url\".\n\nBoth generate a URL, with either the object's 2-digit hex directory (eg. /objects/a1/), or\nthe complete object location (eg. /objects/a1/b2).\n\nHowever, they differ in that \"append_remote_object_url\" appends this URL to a strbuf, while\n\"get_remote_object_url\" wraps around the former and returns the URL directly in char*.\nUsers usually would use \"get_remote_object_url\", but may find \"append_remote_object_url\"\nuseful if they require further string operations on the URL.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\nAcked-by: Junio C Hamano <gitster@pobox.com>\n---\n\n* renamed only_two_digit_postfix in original patch to only_two_digit_prefix\n* rebased and generated on master (5dc1308)\n* updated with Junio's changes (if (...) and fix memory leak)\n* updated with Junio's double interface\n* added back use of temporary string \"url\" in \"start_fetch_loose\"\n* rebased and generated on master (a34a9db)\n\n  http-push.c |   62 +++++++++++++++++++++++-----------------------------------\n  1 files changed, 25 insertions(+), 37 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 59037df..816e658 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -209,6 +209,20 @@ static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum d\n  \treturn dav_headers;\n  }\n\n+static void append_remote_object_url(struct strbuf *buf, const char *url, const char *hex, int only_two_digit_prefix)\n+{\n+\tstrbuf_addf(buf, \"%sobjects/%.*s/\", url, 2, hex);\n+\tif (!only_two_digit_prefix)\n+\t\tstrbuf_addf(buf, \"%s\", hex+2);\n+}\n+\n+static char *get_remote_object_url(const char *url, const char *hex, int only_two_digit_prefix)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tappend_remote_object_url(&buf, url, hex, only_two_digit_prefix);\n+\treturn strbuf_detach(&buf, NULL);\n+}\n+\n  static void finish_request(struct transfer_request *request);\n  static void release_request(struct transfer_request *request);\n\n@@ -255,7 +269,6 @@ static void start_fetch_loose(struct transfer_request *request)\n  \tchar *filename;\n  \tchar prevfile[PATH_MAX];\n  \tchar *url;\n-\tchar *posn;\n  \tint prevlocal;\n  \tunsigned char prev_buf[PREV_BUF_SIZE];\n  \tssize_t prev_read = 0;\n@@ -305,17 +318,8 @@ static void start_fetch_loose(struct transfer_request *request)\n\n  \tgit_SHA1_Init(&request->c);\n\n-\turl = xmalloc(strlen(remote->url) + 50);\n-\trequest->url = xmalloc(strlen(remote->url) + 50);\n-\tstrcpy(url, remote->url);\n-\tposn = url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n-\tmemcpy(posn, hex, 2);\n-\tposn += 2;\n-\t*(posn++) = '/';\n-\tstrcpy(posn, hex + 2);\n-\tstrcpy(request->url, url);\n+\turl = get_remote_object_url(remote->url, hex, 0);\n+\trequest->url = xstrdup(url);\n\n  \t/* If a previous temp file is present, process what was already\n  \t   fetched. */\n@@ -388,16 +392,8 @@ static void start_mkcol(struct transfer_request *request)\n  {\n  \tchar *hex = sha1_to_hex(request->obj->sha1);\n  \tstruct active_request_slot *slot;\n-\tchar *posn;\n\n-\trequest->url = xmalloc(strlen(remote->url) + 13);\n-\tstrcpy(request->url, remote->url);\n-\tposn = request->url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n-\tmemcpy(posn, hex, 2);\n-\tposn += 2;\n-\tstrcpy(posn, \"/\");\n+\trequest->url = get_remote_object_url(remote->url, hex, 1);\n\n  \tslot = get_active_slot();\n  \tslot->callback_func = process_response;\n@@ -512,7 +508,7 @@ static void start_put(struct transfer_request *request)\n  {\n  \tchar *hex = sha1_to_hex(request->obj->sha1);\n  \tstruct active_request_slot *slot;\n-\tchar *posn;\n+\tstruct strbuf buf = STRBUF_INIT;\n  \tenum object_type type;\n  \tchar hdr[50];\n  \tvoid *unpacked;\n@@ -551,21 +547,13 @@ static void start_put(struct transfer_request *request)\n\n  \trequest->buffer.buf.len = stream.total_out;\n\n-\trequest->url = xmalloc(strlen(remote->url) +\n-\t\t\t       strlen(request->lock->token) + 51);\n-\tstrcpy(request->url, remote->url);\n-\tposn = request->url + strlen(remote->url);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n-\tmemcpy(posn, hex, 2);\n-\tposn += 2;\n-\t*(posn++) = '/';\n-\tstrcpy(posn, hex + 2);\n-\trequest->dest = xmalloc(strlen(request->url) + 14);\n-\tsprintf(request->dest, \"Destination: %s\", request->url);\n-\tposn += 38;\n-\t*(posn++) = '_';\n-\tstrcpy(posn, request->lock->token);\n+\tstrbuf_addstr(&buf, \"Destination: \");\n+\tappend_remote_object_url(&buf, remote->url, hex, 0);\n+\trequest->dest = strbuf_detach(&buf, NULL);\n+\n+\tappend_remote_object_url(&buf, remote->url, hex, 0);\n+\tstrbuf_addstr(&buf, request->lock->token);\n+\trequest->url = strbuf_detach(&buf, NULL);\n\n  \tslot = get_active_slot();\n  \tslot->callback_func = process_response;\n-- \n1.6.1.1.241.gc53a6.dirty\n"},{"id":"102465","messageId":"alpine.DEB.1.00.0901291608330.3586@pacific.mpi-cbg.de","threadId":"17436","inReplyTo":"4981C43B.9030409@gmail.com","subject":"Re: [PATCH v2] http-push: refactor request url creation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-29T15:10:53Z","receivedAt":"2009-01-29T15:10:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 29 Jan 2009, Tay Ray Chuan wrote:\n\n> Currently, functions that deal with objects on the remote repository have to\n> allocate and\n> do strcpys to generate the URL.\n\nThat is a funny way to wrap the commit message :-)\n\n> +static void append_remote_object_url(struct strbuf *buf, const char *url,\n> const char *hex, int only_two_digit_prefix)\n\nHere, you still have a corrupt patch.  Which might be helped by wrapping \nthe overly long line in the first place?\n\nCiao,\nDscho\n"},{"id":"102478","messageId":"7vk58ef2il.fsf@gitster.siamese.dyndns.org","threadId":"17436","inReplyTo":"alpine.DEB.1.00.0901291608330.3586@pacific.mpi-cbg.de","subject":"Re: [PATCH v2] http-push: refactor request url creation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-29T17:25:22Z","receivedAt":"2009-01-29T17:25:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Thu, 29 Jan 2009, Tay Ray Chuan wrote:\n>\n>> Currently, functions that deal with objects on the remote repository have to\n>> allocate and\n>> do strcpys to generate the URL.\n>\n> That is a funny way to wrap the commit message :-)\n\nThat's format=flowed in action, isn't it?\n"},{"id":"102512","messageId":"be6fef0d0901291431v5d728c0fl638e445ed881d031@mail.gmail.com","threadId":"17436","inReplyTo":"7vk58ef2il.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH v2] http-push: refactor request url creation","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-01-29T22:31:52Z","receivedAt":"2009-01-29T22:31:52Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"On Fri, Jan 30, 2009 at 1:25 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n>> On Thu, 29 Jan 2009, Tay Ray Chuan wrote:\n>>\n>>> Currently, functions that deal with objects on the remote repository have to\n>>> allocate and\n>>> do strcpys to generate the URL.\n>>\n>> That is a funny way to wrap the commit message :-)\n>\n> That's format=flowed in action, isn't it?\n\nOk, I've turned that off.\n\nEh, no I didn't wrap anything, my message looks fine here:\n\nhttp://permalink.gmane.org/gmane.comp.version-control.git/107691\n\n...turning off format=flowed would fix that?\n\n-- \nCheers,\nRay Chuan\n"}]}