Skip to content

Commit

Permalink
[PATCH] Provide access to git_dir through get_git_dir().
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Sven Verdoolaege authored and Junio C Hamano committed Sep 27, 2005
1 parent edde7a8 commit 5da1606
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
#define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE"

extern char *get_git_dir(void);
extern char *get_object_directory(void);
extern char *get_refs_directory(void);
extern char *get_index_file(void);
Expand Down
5 changes: 1 addition & 4 deletions fsck-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,7 @@ static int fsck_head_link(void)
char hex[40];
unsigned char sha1[20];
static char path[PATH_MAX], link[PATH_MAX];
const char *git_dir;

git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
const char *git_dir = get_git_dir();

snprintf(path, sizeof(path), "%s/HEAD", git_dir);
if (readlink(path, link, sizeof(link)) < 0)
Expand Down
4 changes: 1 addition & 3 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ char *mkpath(const char *fmt, ...)

char *git_path(const char *fmt, ...)
{
const char *git_dir;
const char *git_dir = get_git_dir();
va_list args;
unsigned len;

git_dir = getenv(GIT_DIR_ENVIRONMENT);
if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
len = strlen(git_dir);
if (len > PATH_MAX-100)
return bad_path;
Expand Down
7 changes: 7 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ static void setup_git_env(void)
git_graft_file = strdup(git_path("info/grafts"));
}

char *get_git_dir(void)
{
if (!git_dir)
setup_git_env();
return git_dir;
}

char *get_object_directory(void)
{
if (!git_object_dir)
Expand Down

0 comments on commit 5da1606

Please sign in to comment.