{"thread":{"id":"18200","subject":"[PATCH v2] http: use strbuf API in quote_ref_url","startedAt":"2009-03-07T16:47:21Z","lastAt":"2009-03-07T17:32:40Z","messageCount":2,"participants":["Tay Ray Chuan","Johannes Schindelin"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"107310","messageId":"49B2A519.8050802@gmail.com","threadId":"18200","inReplyTo":null,"subject":"[PATCH v2] http: use strbuf API in quote_ref_url","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-03-07T16:47:21Z","receivedAt":"2009-03-07T16:47:21Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"In addition, ''quote_ref_url'' inserts a slash between the base URL and\nremote ref path only if needed. Previously, this insertion wasn't\ncontingent on the lack of a separating slash.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n\nDifferences from v1:\n *use buf when checking for '/'\n *remove for's braces\n\n http.c |   30 ++++++++++--------------------\n 1 files changed, 10 insertions(+), 20 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex cdedeb6..1691498 100644\n--- a/http.c\n+++ b/http.c\n@@ -577,31 +577,21 @@ static inline int hex(int v)\n\n static char *quote_ref_url(const char *base, const char *ref)\n {\n+\tstruct strbuf buf = STRBUF_INIT;\n \tconst char *cp;\n-\tchar *dp, *qref;\n-\tint len, baselen, ch;\n+\tint ch;\n\n-\tbaselen = strlen(base);\n-\tlen = baselen + 2; /* '/' after base and terminating NUL */\n-\tfor (cp = ref; (ch = *cp) != 0; cp++, len++)\n+\tstrbuf_addstr(&buf, base);\n+\tif (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')\n+\t\tstrbuf_addstr(&buf, \"/\");\n+\n+\tfor (cp = ref; (ch = *cp) != 0; cp++)\n \t\tif (needs_quote(ch))\n-\t\t\tlen += 2; /* extra two hex plus replacement % */\n-\tqref = xmalloc(len);\n-\tmemcpy(qref, base, baselen);\n-\tdp = qref + baselen;\n-\t*(dp++) = '/';\n-\tfor (cp = ref; (ch = *cp) != 0; cp++) {\n-\t\tif (needs_quote(ch)) {\n-\t\t\t*dp++ = '%';\n-\t\t\t*dp++ = hex((ch >> 4) & 0xF);\n-\t\t\t*dp++ = hex(ch & 0xF);\n-\t\t}\n+\t\t\tstrbuf_addf(&buf, \"%%%02x\", ch);\n \t\telse\n-\t\t\t*dp++ = ch;\n-\t}\n-\t*dp = 0;\n+\t\t\tstrbuf_addch(&buf, *cp);\n\n-\treturn qref;\n+\treturn strbuf_detach(&buf, NULL);\n }\n\n int http_fetch_ref(const char *base, struct ref *ref)\n-- \n1.6.2.rc1\n"},{"id":"107316","messageId":"alpine.DEB.1.00.0903071832270.10279@pacific.mpi-cbg.de","threadId":"18200","inReplyTo":"49B2A519.8050802@gmail.com","subject":"Re: [PATCH v2] http: use strbuf API in quote_ref_url","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-07T17:32:40Z","receivedAt":"2009-03-07T17:32:40Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 8 Mar 2009, Tay Ray Chuan wrote:\n\n> In addition, ''quote_ref_url'' inserts a slash between the base URL and\n> remote ref path only if needed. Previously, this insertion wasn't\n> contingent on the lack of a separating slash.\n> \n> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>\n\nThanks, and ACK ;-)\n\nCiao,\nDscho\n"}]}