{"thread":{"id":"19693","subject":"[PATCH 14/23] http: create function end_url_with_slash","startedAt":"2009-06-05T16:04:56Z","lastAt":"2009-06-05T16:04:56Z","messageCount":1,"participants":["Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":23},"messages":[{"id":"115529","messageId":"20090606000456.70a24b3c.rctay89@gmail.com","threadId":"19693","inReplyTo":null,"subject":"[PATCH 14/23] http: create function end_url_with_slash","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-06-05T16:04:56Z","receivedAt":"2009-06-05T16:04:56Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"The logic to append a slash to the url if necessary in quote_ref_url\n(added in 113106e \"http.c: use strbuf API in quote_ref_url\") has been\nmoved to a new function, end_url_with_slash.\n\nThe method takes a strbuf, the URL, and the path to be appended to the\nURL. It first adds the URL to the strbuf. It then appends a slash\nif the URL does not end with a slash.\n\nThe check on ref in quote_ref_url for a slash at the beginning has been\nremoved as a result of using end_url_with_slash. This check is not\nneeded, because slashes will be quoted anyway.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http.c |   12 +++++++++---\n 1 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex 3ca60bb..75fce9e 100644\n--- a/http.c\n+++ b/http.c\n@@ -620,6 +620,7 @@ void finish_all_active_slots(void)\n \t\t}\n }\n\n+/* Helpers for modifying and creating URLs */\n static inline int needs_quote(int ch)\n {\n \tif (((ch >= 'A') && (ch <= 'Z'))\n@@ -640,15 +641,20 @@ static inline int hex(int v)\n \t\treturn 'A' + v - 10;\n }\n\n+static void end_url_with_slash(struct strbuf *buf, const char *url)\n+{\n+\tstrbuf_addstr(buf, url);\n+\tif (buf->len && buf->buf[buf->len - 1] != '/')\n+\t\tstrbuf_addstr(buf, \"/\");\n+}\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 \tint ch;\n\n-\tstrbuf_addstr(&buf, base);\n-\tif (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/')\n-\t\tstrbuf_addstr(&buf, \"/\");\n+\tend_url_with_slash(&buf, base);\n\n \tfor (cp = ref; (ch = *cp) != 0; cp++)\n \t\tif (needs_quote(ch))\n--\n1.6.3.1\n"}]}