sha1_file_name(): overwrite buffer instead of appending
The sha1_file_name() function is used to generate the path to a loose object in the object directory. It doesn't make much sense for it to append, since the the path we write may be absolute (i.e., you cannot reliably build up a path with it). Because many callers use it with a static buffer, they have to strbuf_reset() manually before each call (and the other callers always use an empty buffer, so they don't care either way). Let's handle this automatically. Since we're changing the semantics, let's take the opportunity to give it a more hash-neutral name (which will also catch any callers from topics in flight). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
263db403fa
commit
b69fb867b4
4
http.c
4
http.c
@ -2314,7 +2314,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
|
||||
hashcpy(freq->sha1, sha1);
|
||||
freq->localfile = -1;
|
||||
|
||||
sha1_file_name(the_repository, &filename, sha1);
|
||||
loose_object_path(the_repository, &filename, sha1);
|
||||
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
|
||||
|
||||
strbuf_addf(&prevfile, "%s.prev", filename.buf);
|
||||
@ -2465,7 +2465,7 @@ int finish_http_object_request(struct http_object_request *freq)
|
||||
unlink_or_warn(freq->tmpfile.buf);
|
||||
return -1;
|
||||
}
|
||||
sha1_file_name(the_repository, &filename, freq->sha1);
|
||||
loose_object_path(the_repository, &filename, freq->sha1);
|
||||
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
|
||||
strbuf_release(&filename);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user