Skip to content

Commit

Permalink
Allow multiple "git_path()" uses
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Sep 16, 2006
1 parent 9d0734a commit e7676d2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion path.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
#include "cache.h"
#include <pwd.h>

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

static char *get_pathname(void)
{
static char pathname_array[4][PATH_MAX];
static int index;
return pathname_array[3 & ++index];
}

static char *cleanup_path(char *path)
{
/* Clean it up */
Expand All @@ -31,6 +37,7 @@ char *mkpath(const char *fmt, ...)
{
va_list args;
unsigned len;
char *pathname = get_pathname();

va_start(args, fmt);
len = vsnprintf(pathname, PATH_MAX, fmt, args);
Expand All @@ -43,6 +50,7 @@ char *mkpath(const char *fmt, ...)
char *git_path(const char *fmt, ...)
{
const char *git_dir = get_git_dir();
char *pathname = get_pathname();
va_list args;
unsigned len;

Expand Down

0 comments on commit e7676d2

Please sign in to comment.