Skip to content

Commit e7676d2

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Allow multiple "git_path()" uses
This allows you to maintain a few filesystem pathnames concurrently, by simply replacing the single static "pathname" buffer with a LRU of four buffers. We did exactly the same thing with sha1_to_hex(), for pretty much exactly the same reason. Sometimes you want to use two pathnames, and while it's easy enough to xstrdup() them, why not just do the LU buffer thing. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 9d0734a commit e7676d2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

path.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
#include "cache.h"
1414
#include <pwd.h>
1515

16-
static char pathname[PATH_MAX];
1716
static char bad_path[] = "/bad-path/";
1817

18+
static char *get_pathname(void)
19+
{
20+
static char pathname_array[4][PATH_MAX];
21+
static int index;
22+
return pathname_array[3 & ++index];
23+
}
24+
1925
static char *cleanup_path(char *path)
2026
{
2127
/* Clean it up */
@@ -31,6 +37,7 @@ char *mkpath(const char *fmt, ...)
3137
{
3238
va_list args;
3339
unsigned len;
40+
char *pathname = get_pathname();
3441

3542
va_start(args, fmt);
3643
len = vsnprintf(pathname, PATH_MAX, fmt, args);
@@ -43,6 +50,7 @@ char *mkpath(const char *fmt, ...)
4350
char *git_path(const char *fmt, ...)
4451
{
4552
const char *git_dir = get_git_dir();
53+
char *pathname = get_pathname();
4654
va_list args;
4755
unsigned len;
4856

0 commit comments

Comments
 (0)