summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-20 02:19:19 -0400
committerJunio C Hamano <gitster@pobox.com>2016-10-26 13:30:51 -0700
commitef2ed5013c4160284d9de18903bd4f7d0542d810 (patch)
tree6c11907a3c953aa672bfe70534fec122c22e4744 /sha1_name.c
parent4ce742fc9c09cd3b95be309bc093f8fa54c15f96 (diff)
downloadgit-ef2ed5013c4160284d9de18903bd4f7d0542d810.tar.gz
find_unique_abbrev: use 4-buffer ring
Some code paths want to format multiple abbreviated sha1s in the same output line. Because we use a single static buffer for our return value, they have to either break their output into several calls or allocate their own arrays and use find_unique_abbrev_r(). Intead, let's mimic sha1_to_hex() and use a ring of several buffers, so that the return value stays valid through multiple calls. This shortens some of the callers, and makes it harder to for them to make a silly mistake. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 4092836146..36ce9b9f45 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -472,7 +472,9 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
const char *find_unique_abbrev(const unsigned char *sha1, int len)
{
- static char hex[GIT_SHA1_HEXSZ + 1];
+ static int bufno;
+ static char hexbuffer[4][GIT_SHA1_HEXSZ + 1];
+ char *hex = hexbuffer[3 & ++bufno];
find_unique_abbrev_r(hex, sha1, len);
return hex;
}