diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-06-13 11:22:00 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-06-13 11:22:00 -0700 |
commit | e391fdfc69bd64e11f31416c38ab491a04c0ffa0 (patch) | |
tree | bb9920933fe815e9763ec1986d12368b648364cd /sha1_file.c | |
parent | 0267d8bf3c4081f17c0291876bd88e3aeeb25c56 (diff) | |
parent | 560fb6a183e1cdbc2948b06cc60bba07f79804a6 (diff) | |
download | git-e391fdfc69bd64e11f31416c38ab491a04c0ffa0.tar.gz git-e391fdfc69bd64e11f31416c38ab491a04c0ffa0.tar.xz |
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.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c index d8e61a65d..e42ef96d4 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, |