提交 162eb5f8 编写于 作者: S Shawn O. Pearce 提交者: Junio C Hamano

http.c: Remove unnecessary strdup of sha1_to_hex result

Most of the time the dumb HTTP transport is run without the verbose
flag set, so we only need the result of sha1_to_hex(sha1) once, to
construct the pack URL.  Don't bother with an unnecessary malloc,
copy, free chain of this buffer.

If verbose is set, we'll format the SHA-1 twice now.  But this
tiny extra CPU time spent is nothing compared to the slowdown that
is usually imposed by the verbose messages being sent to the tty,
and is entirely trivial compared to the latency involved with the
remote HTTP server sending something as big as a pack file.
Signed-off-by: NShawn O. Pearce <spearce@spearce.org>
Acked-by: NTay Ray Chuan <rctay89@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 0da8b2e7
...@@ -899,7 +899,6 @@ int http_fetch_ref(const char *base, struct ref *ref) ...@@ -899,7 +899,6 @@ int http_fetch_ref(const char *base, struct ref *ref)
static int fetch_pack_index(unsigned char *sha1, const char *base_url) static int fetch_pack_index(unsigned char *sha1, const char *base_url)
{ {
int ret = 0; int ret = 0;
char *hex = xstrdup(sha1_to_hex(sha1));
char *filename; char *filename;
char *url = NULL; char *url = NULL;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
...@@ -910,10 +909,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url) ...@@ -910,10 +909,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
} }
if (http_is_verbose) if (http_is_verbose)
fprintf(stderr, "Getting index for pack %s\n", hex); fprintf(stderr, "Getting index for pack %s\n", sha1_to_hex(sha1));
end_url_with_slash(&buf, base_url); end_url_with_slash(&buf, base_url);
strbuf_addf(&buf, "objects/pack/pack-%s.idx", hex); strbuf_addf(&buf, "objects/pack/pack-%s.idx", sha1_to_hex(sha1));
url = strbuf_detach(&buf, NULL); url = strbuf_detach(&buf, NULL);
filename = sha1_pack_index_name(sha1); filename = sha1_pack_index_name(sha1);
...@@ -921,7 +920,6 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url) ...@@ -921,7 +920,6 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
ret = error("Unable to get pack index %s\n", url); ret = error("Unable to get pack index %s\n", url);
cleanup: cleanup:
free(hex);
free(url); free(url);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册