summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-07-24 07:11:58 -0500
committerJunio C Hamano <gitster@pobox.com>2010-08-04 11:21:44 -0700
commit98937bef1bf1c8eea90c209c601d4338a43a3479 (patch)
tree4a99ff181482247f236935f192e76e5d409bf56c /setup.c
parent3f8099fce7779631fe8827a8979d7b57629a36de (diff)
downloadgit-98937bef1bf1c8eea90c209c601d4338a43a3479.tar.gz
setup: split off a function to handle ordinary .git directories
Finish the clean-up of setup_git_directory_gently() by splitting the last case of validation+setup (global variables, prefix, check_format, set_git_dir) into its own function. Now setup_git_git_directory_gently itself takes care of discovery only and the functions that pick up from there are nearby in the source file so they can be easily compared. 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.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/setup.c b/setup.c
index 5734a1f1c1..d19aa7d7a9 100644
--- a/setup.c
+++ b/setup.c
@@ -360,6 +360,28 @@ static int cwd_contains_git_dir(const char **gitfile_dirp)
return is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT);
}
+static const char *setup_discovered_git_dir(const char *work_tree_env,
+ int offset, int len, char *cwd, int *nongit_ok)
+{
+ int root_len;
+
+ inside_git_dir = 0;
+ if (!work_tree_env)
+ inside_work_tree = 1;
+ root_len = offset_1st_component(cwd);
+ git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
+ if (check_repository_format_gently(nongit_ok))
+ return NULL;
+ if (offset == len)
+ return NULL;
+
+ /* Make "offset" point to past the '/', and add a '/' at the end */
+ offset++;
+ cwd[len++] = '/';
+ cwd[len] = 0;
+ return cwd + offset;
+}
+
static const char *setup_bare_git_dir(const char *work_tree_env,
int offset, int len, char *cwd, int *nongit_ok)
{
@@ -411,7 +433,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
static char cwd[PATH_MAX+1];
const char *gitdirenv;
const char *gitfile_dir;
- int len, offset, ceil_offset, root_len;
+ int len, offset, ceil_offset;
dev_t current_device = 0;
int one_filesystem = 1;
@@ -456,7 +478,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
current_device = get_device_or_die(".", NULL);
for (;;) {
if (cwd_contains_git_dir(&gitfile_dir))
- break;
+ return setup_discovered_git_dir(work_tree_env, offset,
+ len, cwd, nongit_ok);
if (is_git_directory("."))
return setup_bare_git_dir(work_tree_env, offset,
len, cwd, nongit_ok);
@@ -482,22 +505,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
die_errno("Cannot change to '%s/..'", cwd);
}
}
-
- inside_git_dir = 0;
- if (!work_tree_env)
- inside_work_tree = 1;
- root_len = offset_1st_component(cwd);
- git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
- if (check_repository_format_gently(nongit_ok))
- return NULL;
- if (offset == len)
- return NULL;
-
- /* Make "offset" point to past the '/', and add a '/' at the end */
- offset++;
- cwd[len++] = '/';
- cwd[len] = 0;
- return cwd + offset;
}
int git_config_perm(const char *var, const char *value)