{"thread":{"id":"7451","subject":"[PATCH] http-fetch: don't use double-slash as directory separator in URLs","startedAt":"2007-03-28T09:46:15Z","lastAt":"2007-03-28T09:47:35Z","messageCount":2,"participants":["Gerrit Pape"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"38244","messageId":"20070328094615.32277.qmail@47bcc7bfa0b709.315fe32.mid.smarden.org","threadId":"7451","inReplyTo":null,"subject":"[PATCH] http-fetch: don't use double-slash as directory separator in URLs","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-03-28T09:46:15Z","receivedAt":"2007-03-28T09:46:15Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"Please see http://bugs.debian.org/409887\n\nhttp-fetch expected the URL given at the command line to have a trailing\nslash anyway, and then added '/objects...' when requesting objects files\nfrom the http server.\n\nNow it doesn't require the trailing slash in <url> anymore, and strips\ntrailing slashes if given nonetheless.\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n git-clone.sh |    2 +-\n git-fetch.sh |    2 +-\n http-fetch.c |   21 ++++++++++++---------\n 3 files changed, 14 insertions(+), 11 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 6ba477d..513b574 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -60,7 +60,7 @@ Perhaps git-update-server-info needs to be run there?\"\n \t\telse\n \t\t\ttname=$name\n \t\tfi\n-\t\tgit-http-fetch $v -a -w \"$tname\" \"$name\" \"$1/\" || exit 1\n+\t\tgit-http-fetch $v -a -w \"$tname\" \"$name\" \"$1\" || exit 1\n \tdone <\"$clone_tmp/refs\"\n \trm -fr \"$clone_tmp\"\n \thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" ||\ndiff --git a/git-fetch.sh b/git-fetch.sh\nindex 9334933..fd70696 100755\n--- a/git-fetch.sh\n+++ b/git-fetch.sh\n@@ -248,7 +248,7 @@ fetch_per_ref () {\n \t  expr \"z$head\" : \"z$_x40\\$\" >/dev/null ||\n \t\tdie \"No such ref $remote_name at $remote\"\n \t  echo >&2 \"Fetching $remote_name from $remote using $proto\"\n-\t  git-http-fetch -v -a \"$head\" \"$remote/\" || exit\n+\t  git-http-fetch -v -a \"$head\" \"$remote\" || exit\n \t  ;;\n       rsync://*)\n \t  test -n \"$shallow_depth\" &&\ndiff --git a/http-fetch.c b/http-fetch.c\nindex e6cd11d..58b77a7 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -16,7 +16,7 @@ static struct curl_slist *no_pragma_header;\n \n struct alt_base\n {\n-\tconst char *base;\n+\tchar *base;\n \tint path_len;\n \tint got_indices;\n \tstruct packed_git *packs;\n@@ -158,12 +158,12 @@ static void start_object_request(struct object_request *obj_req)\n \n \tSHA1_Init(&obj_req->c);\n \n-\turl = xmalloc(strlen(obj_req->repo->base) + 50);\n-\tobj_req->url = xmalloc(strlen(obj_req->repo->base) + 50);\n+\turl = xmalloc(strlen(obj_req->repo->base) + 51);\n+\tobj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);\n \tstrcpy(url, obj_req->repo->base);\n \tposn = url + strlen(obj_req->repo->base);\n-\tstrcpy(posn, \"objects/\");\n-\tposn += 8;\n+\tstrcpy(posn, \"/objects/\");\n+\tposn += 9;\n \tmemcpy(posn, hex, 2);\n \tposn += 2;\n \t*(posn++) = '/';\n@@ -938,14 +938,14 @@ static char *quote_ref_url(const char *base, const char *ref)\n \tint len, baselen, ch;\n \n \tbaselen = strlen(base);\n-\tlen = baselen + 6; /* \"refs/\" + NUL */\n+\tlen = baselen + 7; /* \"/refs/\" + NUL */\n \tfor (cp = ref; (ch = *cp) != 0; cp++, len++)\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-\tmemcpy(qref + baselen, \"refs/\", 5);\n-\tfor (cp = ref, dp = qref + baselen + 5; (ch = *cp) != 0; cp++) {\n+\tmemcpy(qref + baselen, \"/refs/\", 6);\n+\tfor (cp = ref, dp = qref + baselen + 6; (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@@ -1044,7 +1044,10 @@ int main(int argc, const char **argv)\n \tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n \n \talt = xmalloc(sizeof(*alt));\n-\talt->base = url;\n+\talt->base = xmalloc(strlen(url) + 1);\n+\tstrcpy(alt->base, url);\n+\tfor (path = alt->base + strlen(alt->base) - 1; *path == '/'; --path)\n+\t\t*path = 0;\n \talt->got_indices = 0;\n \talt->packs = NULL;\n \talt->next = NULL;\n-- \n1.5.1-rc2.GIT\n"},{"id":"38245","messageId":"20070328094735.32395.qmail@f0b3463ad4d11a.315fe32.mid.smarden.org","threadId":"7451","inReplyTo":"20070328094615.32277.qmail@47bcc7bfa0b709.315fe32.mid.smarden.org","subject":"[PATCH] http-fetch: remove path_len from struct alt_base, it was computed but never used","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-03-28T09:47:35Z","receivedAt":"2007-03-28T09:47:35Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"Signed-off-by: Gerrit Pape <pape@smarden.org>\n---\n http-fetch.c |   20 +++-----------------\n 1 files changed, 3 insertions(+), 17 deletions(-)\n\ndiff --git a/http-fetch.c b/http-fetch.c\nindex 58b77a7..557b403 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -17,7 +17,6 @@ static struct curl_slist *no_pragma_header;\n struct alt_base\n {\n \tchar *base;\n-\tint path_len;\n \tint got_indices;\n \tstruct packed_git *packs;\n \tstruct alt_base *next;\n@@ -515,7 +514,6 @@ static void process_alternates_response(void *callback_data)\n \t\t\tint serverlen = 0;\n \t\t\tstruct alt_base *newalt;\n \t\t\tchar *target = NULL;\n-\t\t\tchar *path;\n \t\t\tif (data[i] == '/') {\n \t\t\t\t/* This counts\n \t\t\t\t * http://git.host/pub/scm/linux.git/\n@@ -583,12 +581,6 @@ static void process_alternates_response(void *callback_data)\n \t\t\t\tnewalt->base = target;\n \t\t\t\tnewalt->got_indices = 0;\n \t\t\t\tnewalt->packs = NULL;\n-\t\t\t\tpath = strstr(target, \"//\");\n-\t\t\t\tif (path) {\n-\t\t\t\t\tpath = strchr(path+2, '/');\n-\t\t\t\t\tif (path)\n-\t\t\t\t\t\tnewalt->path_len = strlen(path);\n-\t\t\t\t}\n \n \t\t\t\twhile (tail->next != NULL)\n \t\t\t\t\ttail = tail->next;\n@@ -999,7 +991,7 @@ int main(int argc, const char **argv)\n \tconst char **write_ref = NULL;\n \tchar **commit_id;\n \tconst char *url;\n-\tchar *path;\n+\tchar *s;\n \tint arg = 1;\n \tint rc = 0;\n \n@@ -1046,17 +1038,11 @@ int main(int argc, const char **argv)\n \talt = xmalloc(sizeof(*alt));\n \talt->base = xmalloc(strlen(url) + 1);\n \tstrcpy(alt->base, url);\n-\tfor (path = alt->base + strlen(alt->base) - 1; *path == '/'; --path)\n-\t\t*path = 0;\n+\tfor (s = alt->base + strlen(alt->base) - 1; *s == '/'; --s)\n+\t\t*s = 0;\n \talt->got_indices = 0;\n \talt->packs = NULL;\n \talt->next = NULL;\n-\tpath = strstr(url, \"//\");\n-\tif (path) {\n-\t\tpath = strchr(path+2, '/');\n-\t\tif (path)\n-\t\t\talt->path_len = strlen(path);\n-\t}\n \n \tif (pull(commits, commit_id, write_ref, url))\n \t\trc = 1;\n-- \n1.5.1-rc2.GIT\n"}]}