Skip to content

Commit

Permalink
http.c: Don't store destination name in request structures
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Apr 17, 2010
1 parent 3065274 commit 0da8b2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion http-walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static int fetch_object(struct walker *walker, struct alt_base *repo, unsigned c
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
ret = error("unable to write sha1 filename %s",
req->filename);
sha1_file_name(req->sha1));
}

release_http_object_request(req);
Expand Down
14 changes: 6 additions & 8 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ int finish_http_pack_request(struct http_pack_request *preq)
lst = &((*lst)->next);
*lst = (*lst)->next;

ret = move_temp_to_file(preq->tmpfile, preq->filename);
ret = move_temp_to_file(preq->tmpfile, sha1_pack_name(p->sha1));
if (ret)
return ret;
if (verify_pack(p))
Expand Down Expand Up @@ -1043,7 +1043,6 @@ struct http_pack_request *new_http_pack_request(
preq->url = strbuf_detach(&buf, NULL);

filename = sha1_pack_name(target->sha1);
snprintf(preq->filename, sizeof(preq->filename), "%s", filename);
snprintf(preq->tmpfile, sizeof(preq->tmpfile), "%s.temp", filename);
preq->packfile = fopen(preq->tmpfile, "a");
if (!preq->packfile) {
Expand Down Expand Up @@ -1133,7 +1132,6 @@ struct http_object_request *new_http_object_request(const char *base_url,
freq->localfile = -1;

filename = sha1_file_name(sha1);
snprintf(freq->filename, sizeof(freq->filename), "%s", filename);
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
"%s.temp", filename);

Expand Down Expand Up @@ -1162,8 +1160,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
}

if (freq->localfile < 0) {
error("Couldn't create temporary file %s for %s: %s",
freq->tmpfile, freq->filename, strerror(errno));
error("Couldn't create temporary file %s: %s",
freq->tmpfile, strerror(errno));
goto abort;
}

Expand Down Expand Up @@ -1210,8 +1208,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
prev_posn = 0;
lseek(freq->localfile, 0, SEEK_SET);
if (ftruncate(freq->localfile, 0) < 0) {
error("Couldn't truncate temporary file %s for %s: %s",
freq->tmpfile, freq->filename, strerror(errno));
error("Couldn't truncate temporary file %s: %s",
freq->tmpfile, strerror(errno));
goto abort;
}
}
Expand Down Expand Up @@ -1287,7 +1285,7 @@ int finish_http_object_request(struct http_object_request *freq)
return -1;
}
freq->rename =
move_temp_to_file(freq->tmpfile, freq->filename);
move_temp_to_file(freq->tmpfile, sha1_file_name(freq->sha1));

return freq->rename;
}
Expand Down
2 changes: 0 additions & 2 deletions http.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ struct http_pack_request
struct packed_git *target;
struct packed_git **lst;
FILE *packfile;
char filename[PATH_MAX];
char tmpfile[PATH_MAX];
struct curl_slist *range_header;
struct active_request_slot *slot;
Expand All @@ -167,7 +166,6 @@ extern void release_http_pack_request(struct http_pack_request *preq);
struct http_object_request
{
char *url;
char filename[PATH_MAX];
char tmpfile[PATH_MAX];
int localfile;
CURLcode curl_result;
Expand Down

0 comments on commit 0da8b2e

Please sign in to comment.