http.c: Don't store destination name in request structures
The destination name within the object store is easily computed on demand, reusing a static buffer held by sha1_file.c. We don't need to copy the entire path into the request structure for safe keeping, when it can be easily reformatted after the download has been completed. This reduces the size of the per-request structure, and removes yet another PATH_MAX based limit. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shawn O. Pearce committed
Apr 17, 2010 at 13:07 UTC
0da8b2e7c80a6dd9743e5233cdc5acd836c9a8d3
3 files changed
+7
-11
http-walker.c
+1
-1
@@ -510,7 +510,7 @@ static int fetch_object(struct walker *walker, struct alt_base *repo, unsigned c
510
ret = error("File %s has bad hash", hex);
511
} else if (req->rename < 0) {
512
ret = error("unable to write sha1 filename %s",
513
- req->filename);
513
+ sha1_file_name(req->sha1));
514
}
515
516
release_http_object_request(req);
http.c
+6
-8
@@ -1014,7 +1014,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
1014
lst = &((*lst)->next);
1015
*lst = (*lst)->next;
1016
1017
- ret = move_temp_to_file(preq->tmpfile, preq->filename);
1017
+ ret = move_temp_to_file(preq->tmpfile, sha1_pack_name(p->sha1));
1018
if (ret)
1019
return ret;
1020
if (verify_pack(p))
@@ -1043,7 +1043,6 @@ struct http_pack_request *new_http_pack_request(
1043
preq->url = strbuf_detach(&buf, NULL);
1044
1045
filename = sha1_pack_name(target->sha1);
1046
- snprintf(preq->filename, sizeof(preq->filename), "%s", filename);
1046
snprintf(preq->tmpfile, sizeof(preq->tmpfile), "%s.temp", filename);
1047
preq->packfile = fopen(preq->tmpfile, "a");
1048
if (!preq->packfile) {
@@ -1133,7 +1132,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
1132
freq->localfile = -1;
1133
1134
filename = sha1_file_name(sha1);
1136
- snprintf(freq->filename, sizeof(freq->filename), "%s", filename);
1135
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
1136
"%s.temp", filename);
1137
@@ -1162,8 +1160,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
1160
}
1161
1162
if (freq->localfile < 0) {
1165
- error("Couldn't create temporary file %s for %s: %s",
1166
- freq->tmpfile, freq->filename, strerror(errno));
1163
+ error("Couldn't create temporary file %s: %s",
1164
+ freq->tmpfile, strerror(errno));
1165
goto abort;
1166
}
1167
@@ -1210,8 +1208,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
1208
prev_posn = 0;
1209
lseek(freq->localfile, 0, SEEK_SET);
1210
if (ftruncate(freq->localfile, 0) < 0) {
1213
- error("Couldn't truncate temporary file %s for %s: %s",
1214
- freq->tmpfile, freq->filename, strerror(errno));
1211
+ error("Couldn't truncate temporary file %s: %s",
1212
+ freq->tmpfile, strerror(errno));
1213
goto abort;
1214
}
1215
}
@@ -1287,7 +1285,7 @@ int finish_http_object_request(struct http_object_request *freq)
1285
return -1;
1286
}
1287
freq->rename =
1290
- move_temp_to_file(freq->tmpfile, freq->filename);
1288
+ move_temp_to_file(freq->tmpfile, sha1_file_name(freq->sha1));
1289
1290
return freq->rename;
1291
}
http.h
-2
@@ -152,7 +152,6 @@ struct http_pack_request
152
struct packed_git *target;
153
struct packed_git **lst;
154
FILE *packfile;
155
- char filename[PATH_MAX];
155
char tmpfile[PATH_MAX];
156
struct curl_slist *range_header;
157
struct active_request_slot *slot;
@@ -167,7 +166,6 @@ extern void release_http_pack_request(struct http_pack_request *preq);
166
struct http_object_request
167
{
168
char *url;
170
- char filename[PATH_MAX];
169
char tmpfile[PATH_MAX];
170
int localfile;
171
CURLcode curl_result;