Skip to content

Commit

Permalink
setup: split off a function to checks working dir for .git file
Browse files Browse the repository at this point in the history
The repository discovery procedure looks something like this:

	while (same filesystem) {
		check .git in working dir
		check .
		chdir(..)
	}

Add a function for the first step to make the actual code look a bit
closer to that pseudocode.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jonathan Nieder authored and Junio C Hamano committed Jul 26, 2010
1 parent e4e3034 commit 93a0054
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
return retval;
}

static int cwd_contains_git_dir(const char **gitfile_dirp)
{
const char *gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
*gitfile_dirp = gitfile_dir;
if (gitfile_dir) {
if (set_git_dir(gitfile_dir))
die("Repository setup failed");
return 1;
}
return is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT);
}

/*
* We cannot decide in this function whether we are in the work tree or
* not, since the config can only be read _after_ this function was called.
Expand Down Expand Up @@ -407,13 +419,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
current_device = buf.st_dev;
}
for (;;) {
gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
if (gitfile_dir) {
if (set_git_dir(gitfile_dir))
die("Repository setup failed");
break;
}
if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
if (cwd_contains_git_dir(&gitfile_dir))
break;
if (is_git_directory(".")) {
inside_git_dir = 1;
Expand Down

0 comments on commit 93a0054

Please sign in to comment.