summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-07-24 06:20:15 -0500
committerJunio C Hamano <gitster@pobox.com>2010-07-25 22:09:11 -0700
commit93a00542eaeb40c31b4de2497f5413a2fc0f36f4 (patch)
treefd50299c17606e237f5149e1bcd94a8a61fd065c /setup.c
parente4e303479b62e474c52ee1f9edd265d7333117d9 (diff)
downloadgit-93a00542eaeb40c31b4de2497f5413a2fc0f36f4.tar.gz
setup: split off a function to checks working dir for .git file
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>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/setup.c b/setup.c
index 16bee6d485..3d25d0f205 100644
--- a/setup.c
+++ b/setup.c
@@ -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.
@@ -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;