aboutsummaryrefslogtreecommitdiff
path: root/http-fetch.c
diff options
context:
space:
mode:
authorGerrit Pape <pape@smarden.org>2007-03-28 09:46:15 +0000
committerJunio C Hamano <junkio@cox.net>2007-03-28 04:44:16 -0700
commit2afea3bcd2a2b3327d7e8bdabc9aebd6bef24c6e (patch)
treebcb30c2e8deda164d9caa391eb3b87e7dda603f5 /http-fetch.c
parentfa21b6023288d5ee0afa79021493a199b1c9bac5 (diff)
downloadgit-2afea3bcd2a2b3327d7e8bdabc9aebd6bef24c6e.tar.gz
git-2afea3bcd2a2b3327d7e8bdabc9aebd6bef24c6e.tar.xz
http-fetch: don't use double-slash as directory separator in URLs
Please see http://bugs.debian.org/409887 http-fetch expected the URL given at the command line to have a trailing slash anyway, and then added '/objects...' when requesting objects files from the http server. Now it doesn't require the trailing slash in <url> anymore, and strips trailing slashes if given nonetheless. Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'http-fetch.c')
-rw-r--r--http-fetch.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/http-fetch.c b/http-fetch.c
index e6cd11db7..58b77a7a1 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -16,7 +16,7 @@ static struct curl_slist *no_pragma_header;
struct alt_base
{
- const char *base;
+ char *base;
int path_len;
int got_indices;
struct packed_git *packs;
@@ -158,12 +158,12 @@ static void start_object_request(struct object_request *obj_req)
SHA1_Init(&obj_req->c);
- url = xmalloc(strlen(obj_req->repo->base) + 50);
- obj_req->url = xmalloc(strlen(obj_req->repo->base) + 50);
+ url = xmalloc(strlen(obj_req->repo->base) + 51);
+ obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51);
strcpy(url, obj_req->repo->base);
posn = url + strlen(obj_req->repo->base);
- strcpy(posn, "objects/");
- posn += 8;
+ strcpy(posn, "/objects/");
+ posn += 9;
memcpy(posn, hex, 2);
posn += 2;
*(posn++) = '/';
@@ -938,14 +938,14 @@ static char *quote_ref_url(const char *base, const char *ref)
int len, baselen, ch;
baselen = strlen(base);
- len = baselen + 6; /* "refs/" + NUL */
+ len = baselen + 7; /* "/refs/" + NUL */
for (cp = ref; (ch = *cp) != 0; cp++, len++)
if (needs_quote(ch))
len += 2; /* extra two hex plus replacement % */
qref = xmalloc(len);
memcpy(qref, base, baselen);
- memcpy(qref + baselen, "refs/", 5);
- for (cp = ref, dp = qref + baselen + 5; (ch = *cp) != 0; cp++) {
+ memcpy(qref + baselen, "/refs/", 6);
+ for (cp = ref, dp = qref + baselen + 6; (ch = *cp) != 0; cp++) {
if (needs_quote(ch)) {
*dp++ = '%';
*dp++ = hex((ch >> 4) & 0xF);
@@ -1044,7 +1044,10 @@ int main(int argc, const char **argv)
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
alt = xmalloc(sizeof(*alt));
- alt->base = url;
+ alt->base = xmalloc(strlen(url) + 1);
+ strcpy(alt->base, url);
+ for (path = alt->base + strlen(alt->base) - 1; *path == '/'; --path)
+ *path = 0;
alt->got_indices = 0;
alt->packs = NULL;
alt->next = NULL;