{"thread":{"id":"25809","subject":"Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()","startedAt":"2010-11-22T17:14:34Z","lastAt":"2010-11-25T08:21:10Z","messageCount":12,"participants":["Jonathan Nieder","Tay Ray Chuan"],"isPatch":true,"patchVersion":2,"patchTotal":7},"messages":[{"id":"156326","messageId":"20101122171433.GB2084@burratino","threadId":"25809","inReplyTo":"1290433657-4444-4-git-send-email-rctay89@gmail.com","subject":"Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-11-22T17:14:34Z","receivedAt":"2010-11-22T17:14:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Tay Ray Chuan wrote:\n\n> --- a/url.c\n> +++ b/url.c\n> @@ -132,3 +132,11 @@ void end_url_with_slash(struct strbuf *buf, const char *url)\n>  \tif (buf->len && buf->buf[buf->len - 1] != '/')\n>  \t\tstrbuf_addstr(buf, \"/\");\n>  }\n> +\n> +void str_end_url_with_slash(const char *url, char **dest) {\n> +\tstruct strbuf buf = STRBUF_INIT;\n> +\tend_url_with_slash(&buf, url);\n> +\tif (dest)\n> +\t\tfree(*dest);\n> +\t*dest = strbuf_detach(&buf, NULL);\n\nI think this should be\n\n\tend_url_with_slash(&buf, url);\n\tfree(*dest);\n\t*dest = strbuf_detach(...\n\nIf dest were NULL, the assignment would segfault anyway.  If dest were\nnon-NULL and *dest NULL, the free() would be a no-op.\n"},{"id":"156327","messageId":"AANLkTinADtgPfOESd8OTxk20GDFDN2DCOZt7jf0ra_x8@mail.gmail.com","threadId":"25809","inReplyTo":"20101122171433.GB2084@burratino","subject":"Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-22T17:19:18Z","receivedAt":"2010-11-22T17:19:18Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Tue, Nov 23, 2010 at 1:14 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Tay Ray Chuan wrote:\n>\n>> --- a/url.c\n>> +++ b/url.c\n>> @@ -132,3 +132,11 @@ void end_url_with_slash(struct strbuf *buf, const char *url)\n>>       if (buf->len && buf->buf[buf->len - 1] != '/')\n>>               strbuf_addstr(buf, \"/\");\n>>  }\n>> +\n>> +void str_end_url_with_slash(const char *url, char **dest) {\n>> +     struct strbuf buf = STRBUF_INIT;\n>> +     end_url_with_slash(&buf, url);\n>> +     if (dest)\n>> +             free(*dest);\n>> +     *dest = strbuf_detach(&buf, NULL);\n>\n> I think this should be\n>\n>        end_url_with_slash(&buf, url);\n>        free(*dest);\n>        *dest = strbuf_detach(...\n>\n> If dest were NULL, the assignment would segfault anyway.  If dest were\n> non-NULL and *dest NULL, the free() would be a no-op.\n\nThanks for the tip.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"156534","messageId":"1290673270-4284-1-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290433298-6000-1-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 0/9] http: end urls with slash","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:01Z","receivedAt":"2010-11-25T08:21:01Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"This patch series contains Gabriel's fix, as well as some related work I did in\nthe area while looking through the code paths.\n\nChanged from v2:\n - new patches (#2 and #9) that reworks http-fetch url slashing code, and test\n   that this doesn't break anything.\n - patch #4: remove pointer check before running free(), as pointed out by\n   Johnathan.\n\nAll other patches remain unchanged.\n\nContents:\n[1/9] t5550-http-fetch: add missing '&&'\n[2/9] t5550-http-fetch: add test for http-fetch\n[3/9] shift end_url_with_slash() from http.[ch] to url.[ch]\n[4/9] url: add str wrapper for end_url_with_slash()\n[5/9] http-backend: use end_url_with_slash()\n[6/9] http-push: Normalise directory names when pushing to some WebDAV servers\n[7/9] http-push: check path length before using it\n[8/9] http-push: add trailing slash at arg-parse time, instead of later on\n[9/9] http-fetch: rework url handling\n\n Makefile              |    2 +-\n http-backend.c        |    4 +---\n http-fetch.c          |   16 +++++-----------\n http-push.c           |   31 ++++++++++++++++---------------\n http.c                |    8 +-------\n http.h                |    2 +-\n t/t5550-http-fetch.sh |   16 ++++++++++++++--\n url.c                 |   14 ++++++++++++++\n url.h                 |    3 +++\n 9 files changed, 56 insertions(+), 40 deletions(-)\n\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156533","messageId":"1290673270-4284-2-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-1-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 1/9] t5550-http-fetch: add missing '&&'","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:02Z","receivedAt":"2010-11-25T08:21:02Z","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/t5550-http-fetch.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 2fb48d0..39f7b7c 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -37,7 +37,7 @@ test_expect_success 'clone http repository' '\n test_expect_success 'fetch changes via http' '\n \techo content >>file &&\n \tgit commit -a -m two &&\n-\tgit push public\n+\tgit push public &&\n \t(cd clone && git pull) &&\n \ttest_cmp file clone/file\n '\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156525","messageId":"1290673270-4284-3-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-2-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 2/9] t5550-http-fetch: add test for http-fetch","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:03Z","receivedAt":"2010-11-25T08:21:03Z","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\nNew in v3.\n\n t/t5550-http-fetch.sh |   14 +++++++++++++-\n 1 files changed, 13 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh\nindex 39f7b7c..d3bf5ce 100755\n--- a/t/t5550-http-fetch.sh\n+++ b/t/t5550-http-fetch.sh\n@@ -30,7 +30,8 @@ test_expect_success 'create http-accessible bare repository' '\n '\n \n test_expect_success 'clone http repository' '\n-\tgit clone $HTTPD_URL/dumb/repo.git clone &&\n+\tgit clone $HTTPD_URL/dumb/repo.git clone-tmpl &&\n+\tcp -R clone-tmpl clone &&\n \ttest_cmp file clone/file\n '\n \n@@ -42,6 +43,17 @@ test_expect_success 'fetch changes via http' '\n \ttest_cmp file clone/file\n '\n \n+test_expect_success 'fetch changes via manual http-fetch' '\n+\tcp -R clone-tmpl clone2 &&\n+\n+\tHEAD=$(git rev-parse --verify HEAD) &&\n+\t(cd clone2 &&\n+\t git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&\n+\t git checkout master-new &&\n+\t test $HEAD = $(git rev-parse --verify HEAD)) &&\n+\ttest_cmp file clone2/file\n+'\n+\n test_expect_success 'http remote detects correct HEAD' '\n \tgit push public master:other &&\n \t(cd clone &&\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156526","messageId":"1290673270-4284-4-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-3-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 3/9] shift end_url_with_slash() from http.[ch] to url.[ch]","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:04Z","receivedAt":"2010-11-25T08:21:04Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"This allows non-http/curl users to access it too (eg. http-backend.c).\n\nUpdate include headers in end_url_with_slash() users too.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n Makefile |    2 +-\n http.c   |    8 +-------\n http.h   |    2 +-\n url.c    |    7 +++++++\n url.h    |    2 ++\n 5 files changed, 12 insertions(+), 9 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex ca1d1fe..e02b0f4 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1922,7 +1922,7 @@ builtin/tar-tree.o archive-tar.o: tar.h\n builtin/pack-objects.o: thread-utils.h\n connect.o transport.o http-backend.o: url.h\n http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h\n-http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h\n+http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h\n \n xdiff-interface.o $(XDIFF_OBJS): \\\n \txdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \\\ndiff --git a/http.c b/http.c\nindex 17bcf19..310dd86 100644\n--- a/http.c\n+++ b/http.c\n@@ -2,6 +2,7 @@\n #include \"pack.h\"\n #include \"sideband.h\"\n #include \"run-command.h\"\n+#include \"url.h\"\n \n int data_received;\n int active_requests;\n@@ -733,13 +734,6 @@ static inline int hex(int v)\n \t\treturn 'A' + v - 10;\n }\n \n-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;\ndiff --git a/http.h b/http.h\nindex 173f74c..5c6e243 100644\n--- a/http.h\n+++ b/http.h\n@@ -8,6 +8,7 @@\n \n #include \"strbuf.h\"\n #include \"remote.h\"\n+#include \"url.h\"\n \n /*\n  * We detect based on the cURL version if multi-transfer is\n@@ -117,7 +118,6 @@ extern void append_remote_object_url(struct strbuf *buf, const char *url,\n \t\t\t\t     int only_two_digit_prefix);\n extern char *get_remote_object_url(const char *url, const char *hex,\n \t\t\t\t   int only_two_digit_prefix);\n-extern void end_url_with_slash(struct strbuf *buf, const char *url);\n \n /* Options for http_request_*() */\n #define HTTP_NO_CACHE\t\t1\ndiff --git a/url.c b/url.c\nindex cd8f74f..7cebc64 100644\n--- a/url.c\n+++ b/url.c\n@@ -125,3 +125,10 @@ char *url_decode_parameter_value(const char **query)\n \tstruct strbuf out = STRBUF_INIT;\n \treturn url_decode_internal(query, \"&\", &out, 1);\n }\n+\n+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+}\ndiff --git a/url.h b/url.h\nindex 15817f8..8cb74d4 100644\n--- a/url.h\n+++ b/url.h\n@@ -7,4 +7,6 @@ extern char *url_decode(const char *url);\n extern char *url_decode_parameter_name(const char **query);\n extern char *url_decode_parameter_value(const char **query);\n \n+extern void end_url_with_slash(struct strbuf *buf, const char *url);\n+\n #endif /* URL_H */\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156527","messageId":"1290673270-4284-5-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-4-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 4/9] url: add str wrapper for end_url_with_slash()","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:05Z","receivedAt":"2010-11-25T08:21:05Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Helped-by: Johnathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n\nChanged from v2: removed pointer check before free(), as suggested by Johnathan.\n\n url.c |    7 +++++++\n url.h |    1 +\n 2 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/url.c b/url.c\nindex 7cebc64..6a54959 100644\n--- a/url.c\n+++ b/url.c\n@@ -132,3 +132,10 @@ void end_url_with_slash(struct strbuf *buf, const char *url)\n \tif (buf->len && buf->buf[buf->len - 1] != '/')\n \t\tstrbuf_addstr(buf, \"/\");\n }\n+\n+void str_end_url_with_slash(const char *url, char **dest) {\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tend_url_with_slash(&buf, url);\n+\tfree(*dest);\n+\t*dest = strbuf_detach(&buf, NULL);\n+}\ndiff --git a/url.h b/url.h\nindex 8cb74d4..7100e32 100644\n--- a/url.h\n+++ b/url.h\n@@ -8,5 +8,6 @@ extern char *url_decode_parameter_name(const char **query);\n extern char *url_decode_parameter_value(const char **query);\n \n extern void end_url_with_slash(struct strbuf *buf, const char *url);\n+extern void str_end_url_with_slash(const char *url, char **dest);\n \n #endif /* URL_H */\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156528","messageId":"1290673270-4284-6-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-5-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 5/9] http-backend: use end_url_with_slash()","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:06Z","receivedAt":"2010-11-25T08:21:06Z","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 http-backend.c |    4 +---\n 1 files changed, 1 insertions(+), 3 deletions(-)\n\ndiff --git a/http-backend.c b/http-backend.c\nindex 14c90c2..8501504 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -510,9 +510,7 @@ static char* getdir(void)\n \t\t\tdie(\"GIT_PROJECT_ROOT is set but PATH_INFO is not\");\n \t\tif (daemon_avoid_alias(pathinfo))\n \t\t\tdie(\"'%s': aliased\", pathinfo);\n-\t\tstrbuf_addstr(&buf, root);\n-\t\tif (buf.buf[buf.len - 1] != '/')\n-\t\t\tstrbuf_addch(&buf, '/');\n+\t\tend_url_with_slash(&buf, root);\n \t\tif (pathinfo[0] == '/')\n \t\t\tpathinfo++;\n \t\tstrbuf_addstr(&buf, pathinfo);\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156529","messageId":"1290673270-4284-7-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-6-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 6/9] http-push: Normalise directory names when pushing to some WebDAV servers","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:07Z","receivedAt":"2010-11-25T08:21:07Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Fix a bug when pushing to WebDAV servers which do not use a trailing\nslash for collection names. The previous implementation fails to see\nthat the requested resource \"refs/\" is the same resource as \"refs\"\nand loads every reference twice (once for refs/ and once for refs).\n\nThis implementation normalises every collection name by appending a\ntrailing slash if necessary.\n\nThis can be tested with old versions of Apache (such as the WebDAV\nserver of GMX, Apache 2.0.63).\n\nBased-on-patch-by: Gabriel Corona <gabriel.corona@enst-bretagne.fr>\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex c9bcd11..565e580 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1090,6 +1090,10 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)\n \tif (tag_closed) {\n \t\tif (!strcmp(ctx->name, DAV_PROPFIND_RESP) && ls->dentry_name) {\n \t\t\tif (ls->dentry_flags & IS_DIR) {\n+\n+\t\t\t\t/* ensure collection names end with slash */\n+\t\t\t\tstr_end_url_with_slash(ls->dentry_name, &ls->dentry_name);\n+\n \t\t\t\tif (ls->flags & PROCESS_DIRS) {\n \t\t\t\t\tls->userFunc(ls);\n \t\t\t\t}\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156530","messageId":"1290673270-4284-8-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-7-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 7/9] http-push: check path length before using it","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:08Z","receivedAt":"2010-11-25T08:21:08Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"We use path_len to skip the base url/path, but we do not know for sure\nif path does indeed contain the base url/path. Check if this is so.\n\nHelped-by: Johnathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |   12 ++++++++++--\n 1 files changed, 10 insertions(+), 2 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex 565e580..bfa1fe7 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1116,8 +1116,16 @@ static void handle_remote_ls_ctx(struct xml_ctx *ctx, int tag_closed)\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (path) {\n-\t\t\t\tpath += repo->path_len;\n-\t\t\t\tls->dentry_name = xstrdup(path);\n+\t\t\t\tconst char *url = repo->url;\n+\t\t\t\tif (repo->path)\n+\t\t\t\t\turl = repo->path;\n+\t\t\t\tif (strncmp(path, url, repo->path_len))\n+\t\t\t\t\terror(\"Parsed path '%s' does not match url: '%s'\\n\",\n+\t\t\t\t\t      path, url);\n+\t\t\t\telse {\n+\t\t\t\t\tpath += repo->path_len;\n+\t\t\t\t\tls->dentry_name = xstrdup(path);\n+\t\t\t\t}\n \t\t\t}\n \t\t} else if (!strcmp(ctx->name, DAV_PROPFIND_COLLECTION)) {\n \t\t\tls->dentry_flags |= IS_DIR;\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156531","messageId":"1290673270-4284-9-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-8-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 8/9] http-push: add trailing slash at arg-parse time, instead of later on","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:09Z","receivedAt":"2010-11-25T08:21:09Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"That way, we don't have to update repo->path and repo->path_len again\nafter adding the trailing slash.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-push.c |   15 ++-------------\n 1 files changed, 2 insertions(+), 13 deletions(-)\n\ndiff --git a/http-push.c b/http-push.c\nindex bfa1fe7..ff41a0e 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1801,7 +1801,6 @@ int main(int argc, char **argv)\n \tint new_refs;\n \tstruct ref *ref, *local_refs;\n \tstruct remote *remote;\n-\tchar *rewritten_url = NULL;\n \n \tgit_extract_argv0_path(argv[0]);\n \n@@ -1847,8 +1846,8 @@ int main(int argc, char **argv)\n \t\t}\n \t\tif (!repo->url) {\n \t\t\tchar *path = strstr(arg, \"//\");\n-\t\t\trepo->url = arg;\n-\t\t\trepo->path_len = strlen(arg);\n+\t\t\tstr_end_url_with_slash(arg, &repo->url);\n+\t\t\trepo->path_len = strlen(repo->url);\n \t\t\tif (path) {\n \t\t\t\trepo->path = strchr(path+2, '/');\n \t\t\t\tif (repo->path)\n@@ -1884,15 +1883,6 @@ int main(int argc, char **argv)\n \tremote->url[remote->url_nr++] = repo->url;\n \thttp_init(remote);\n \n-\tif (repo->url && repo->url[strlen(repo->url)-1] != '/') {\n-\t\trewritten_url = xmalloc(strlen(repo->url)+2);\n-\t\tstrcpy(rewritten_url, repo->url);\n-\t\tstrcat(rewritten_url, \"/\");\n-\t\trepo->path = rewritten_url + (repo->path - repo->url);\n-\t\trepo->path_len++;\n-\t\trepo->url = rewritten_url;\n-\t}\n-\n #ifdef USE_CURL_MULTI\n \tis_running_queue = 0;\n #endif\n@@ -2100,7 +2090,6 @@ int main(int argc, char **argv)\n \t}\n \n  cleanup:\n-\tfree(rewritten_url);\n \tif (info_ref_lock)\n \t\tunlock_remote(info_ref_lock);\n \tfree(repo);\n-- \n1.7.3.2.495.gc7b3f\n"},{"id":"156532","messageId":"1290673270-4284-10-git-send-email-rctay89@gmail.com","threadId":"25809","inReplyTo":"1290673270-4284-9-git-send-email-rctay89@gmail.com","subject":"[PATCH v3 9/9] http-fetch: rework url handling","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-11-25T08:21:10Z","receivedAt":"2010-11-25T08:21:10Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Do away with a second url variable, rewritten_url, and make url\nnon-const. This is safe because the functions called with url (ie.\nget_http_walker() and walker_fetch()) do not modify it (ie. marked with\nconst char *).\n\nAlso, replace code that adds a trailing slash with a call to\nstr_end_url_with_slash().\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n\nNew in v3.\n\n http-fetch.c |   16 +++++-----------\n 1 files changed, 5 insertions(+), 11 deletions(-)\n\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 762c750..923904f 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -14,8 +14,7 @@ int main(int argc, const char **argv)\n \tint commits;\n \tconst char **write_ref = NULL;\n \tchar **commit_id;\n-\tconst char *url;\n-\tchar *rewritten_url = NULL;\n+\tchar *url = NULL;\n \tint arg = 1;\n \tint rc = 0;\n \tint get_tree = 0;\n@@ -57,19 +56,14 @@ int main(int argc, const char **argv)\n \t\tcommit_id = (char **) &argv[arg++];\n \t\tcommits = 1;\n \t}\n-\turl = argv[arg];\n+\n+\tif (argv[arg])\n+\t\tstr_end_url_with_slash(argv[arg], &url);\n \n \tprefix = setup_git_directory();\n \n \tgit_config(git_default_config, NULL);\n \n-\tif (url && url[strlen(url)-1] != '/') {\n-\t\trewritten_url = xmalloc(strlen(url)+2);\n-\t\tstrcpy(rewritten_url, url);\n-\t\tstrcat(rewritten_url, \"/\");\n-\t\turl = rewritten_url;\n-\t}\n-\n \thttp_init(NULL);\n \twalker = get_http_walker(url);\n \twalker->get_tree = get_tree;\n@@ -93,7 +87,7 @@ int main(int argc, const char **argv)\n \twalker_free(walker);\n \thttp_cleanup();\n \n-\tfree(rewritten_url);\n+\tfree(url);\n \n \treturn rc;\n }\n-- \n1.7.3.2.495.gc7b3f\n"}]}