Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-06-13 22:22:00 +0400
committerJunio C Hamano <gitster@pobox.com>2010-06-13 22:22:00 +0400
commite391fdfc69bd64e11f31416c38ab491a04c0ffa0 (patch)
treebb9920933fe815e9763ec1986d12368b648364cd /sha1_file.c
parent0267d8bf3c4081f17c0291876bd88e3aeeb25c56 (diff)
parent560fb6a183e1cdbc2948b06cc60bba07f79804a6 (diff)
Merge branch 'jk/maint-sha1-file-name-fix'
* jk/maint-sha1-file-name-fix: remove over-eager caching in sha1_file_name
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c
index d8e61a65d1..e42ef96d45 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -102,20 +102,22 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
*/
char *sha1_file_name(const unsigned char *sha1)
{
- static char *name, *base;
+ static char buf[PATH_MAX];
+ const char *objdir;
+ int len;
- if (!base) {
- const char *sha1_file_directory = get_object_directory();
- int len = strlen(sha1_file_directory);
- base = xmalloc(len + 60);
- memcpy(base, sha1_file_directory, len);
- memset(base+len, 0, 60);
- base[len] = '/';
- base[len+3] = '/';
- name = base + len + 1;
- }
- fill_sha1_path(name, sha1);
- return base;
+ objdir = get_object_directory();
+ len = strlen(objdir);
+
+ /* '/' + sha1(2) + '/' + sha1(38) + '\0' */
+ if (len + 43 > PATH_MAX)
+ die("insanely long object directory %s", objdir);
+ memcpy(buf, objdir, len);
+ buf[len] = '/';
+ buf[len+3] = '/';
+ buf[len+42] = '\0';
+ fill_sha1_path(buf + len + 1, sha1);
+ return buf;
}
static char *sha1_get_pack_name(const unsigned char *sha1,