summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2018-01-17 17:54:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-17 20:21:32 (GMT)
commitea6577303f4059683f8f257bdecbcafb05001ce9 (patch)
tree1ac60041f78ab7af5f557bc8b2028b73994bfa52 /http.c
parent3013dff8662eae06457fe6e5348dfe2270810ab2 (diff)
downloadgit-ea6577303f4059683f8f257bdecbcafb05001ce9.zip
git-ea6577303f4059683f8f257bdecbcafb05001ce9.tar.gz
git-ea6577303f4059683f8f257bdecbcafb05001ce9.tar.bz2
sha1_file: remove static strbuf from sha1_file_name()
Using a static buffer in sha1_file_name() is error prone and the performance improvements it gives are not needed in many of the callers. So let's get rid of this static buffer and, if necessary or helpful, let's use one in the caller. Suggested-by: Jeff Hostetler <git@jeffhostetler.com> Helped-by: Kevin Daudt <me@ikke.info> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http.c')
-rw-r--r--http.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/http.c b/http.c
index 713525f..7f1e187 100644
--- a/http.c
+++ b/http.c
@@ -2150,7 +2150,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
unsigned char *sha1)
{
char *hex = sha1_to_hex(sha1);
- const char *filename;
+ struct strbuf filename = STRBUF_INIT;
char prevfile[PATH_MAX];
int prevlocal;
char prev_buf[PREV_BUF_SIZE];
@@ -2162,14 +2162,15 @@ struct http_object_request *new_http_object_request(const char *base_url,
hashcpy(freq->sha1, sha1);
freq->localfile = -1;
- filename = sha1_file_name(sha1);
+ sha1_file_name(&filename, sha1);
snprintf(freq->tmpfile, sizeof(freq->tmpfile),
- "%s.temp", filename);
+ "%s.temp", filename.buf);
- snprintf(prevfile, sizeof(prevfile), "%s.prev", filename);
+ snprintf(prevfile, sizeof(prevfile), "%s.prev", filename.buf);
unlink_or_warn(prevfile);
rename(freq->tmpfile, prevfile);
unlink_or_warn(freq->tmpfile);
+ strbuf_release(&filename);
if (freq->localfile != -1)
error("fd leakage in start: %d", freq->localfile);
@@ -2284,6 +2285,7 @@ void process_http_object_request(struct http_object_request *freq)
int finish_http_object_request(struct http_object_request *freq)
{
struct stat st;
+ struct strbuf filename = STRBUF_INIT;
close(freq->localfile);
freq->localfile = -1;
@@ -2309,8 +2311,10 @@ int finish_http_object_request(struct http_object_request *freq)
unlink_or_warn(freq->tmpfile);
return -1;
}
- freq->rename =
- finalize_object_file(freq->tmpfile, sha1_file_name(freq->sha1));
+
+ sha1_file_name(&filename, freq->sha1);
+ freq->rename = finalize_object_file(freq->tmpfile, filename.buf);
+ strbuf_release(&filename);
return freq->rename;
}