From: Junio C Hamano Date: Wed, 19 Aug 2009 06:33:16 +0000 (-0700) Subject: Merge branch 'rc/maint-http-fix' X-Git-Tag: v1.6.5-rc0~57 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9ebfda109eeb69e8f313ffa7fb85bdba0f16e405?ds=inline;hp=-c Merge branch 'rc/maint-http-fix' * rc/maint-http-fix: http.c: don't assume that urls don't end with slash --- 9ebfda109eeb69e8f313ffa7fb85bdba0f16e405 diff --combined http.c index 14d535747d,6182640c1e..eb0c669801 --- a/http.c +++ b/http.c @@@ -719,7 -719,9 +719,9 @@@ void append_remote_object_url(struct st const char *hex, int only_two_digit_prefix) { - strbuf_addf(buf, "%s/objects/%.*s/", url, 2, hex); + end_url_with_slash(buf, url); + + strbuf_addf(buf, "objects/%.*s/", 2, hex); if (!only_two_digit_prefix) strbuf_addf(buf, "%s", hex+2); } @@@ -1004,6 -1006,7 +1006,6 @@@ int finish_http_pack_request(struct htt struct http_pack_request *new_http_pack_request( struct packed_git *target, const char *base_url) { - char *url; char *filename; long prev_posn = 0; char range[RANGE_HEADER_SIZE]; @@@ -1017,7 -1020,8 +1019,7 @@@ end_url_with_slash(&buf, base_url); strbuf_addf(&buf, "objects/pack/pack-%s.pack", sha1_to_hex(target->sha1)); - url = strbuf_detach(&buf, NULL); - preq->url = xstrdup(url); + preq->url = strbuf_detach(&buf, NULL); filename = sha1_pack_name(target->sha1); snprintf(preq->filename, sizeof(preq->filename), "%s", filename); @@@ -1033,7 -1037,7 +1035,7 @@@ preq->slot->local = preq->packfile; curl_easy_setopt(preq->slot->curl, CURLOPT_FILE, preq->packfile); curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(preq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(preq->slot->curl, CURLOPT_URL, preq->url); curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); @@@ -1057,8 -1061,6 +1059,8 @@@ abort: free(filename); + free(preq->url); + free(preq); return NULL; } @@@ -1098,6 -1100,7 +1100,6 @@@ struct http_object_request *new_http_ob char *hex = sha1_to_hex(sha1); char *filename; char prevfile[PATH_MAX]; - char *url; int prevlocal; unsigned char prev_buf[PREV_BUF_SIZE]; ssize_t prev_read = 0; @@@ -1151,7 -1154,8 +1153,7 @@@ git_SHA1_Init(&freq->c); - url = get_remote_object_url(base_url, hex, 0); - freq->url = xstrdup(url); + freq->url = get_remote_object_url(base_url, hex, 0); /* * If a previous temp file is present, process what was already @@@ -1187,11 -1191,7 +1189,11 @@@ if (prev_posn>0) { prev_posn = 0; lseek(freq->localfile, 0, SEEK_SET); - ftruncate(freq->localfile, 0); + if (ftruncate(freq->localfile, 0) < 0) { + error("Couldn't truncate temporary file %s for %s: %s", + freq->tmpfile, freq->filename, strerror(errno)); + goto abort; + } } } @@@ -1200,7 -1200,7 +1202,7 @@@ curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq); curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr); - curl_easy_setopt(freq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url); curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); /* @@@ -1220,9 -1220,9 +1222,9 @@@ return freq; - free(url); abort: free(filename); + free(freq->url); free(freq); return NULL; }