setup: split off a function to handle hitting ceiling in repo search
Perhaps some day, other similar conditions (hitting the mount point, hitting the root of the file system) will share this code. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Jul 24, 2010 at 06:26 UTC
f161edebb64f08bfc615fd9c28ebae3333255e2e
1 file changed
+12
-9
setup.c
+12
-9
@@ -378,6 +378,16 @@ static const char *setup_bare_git_dir(const char *work_tree_env,
378
return NULL;
379
}
380
381
+static const char *setup_nongit(const char *cwd, int *nongit_ok)
382
+{
383
+ if (!nongit_ok)
384
+ die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
385
+ if (chdir(cwd))
386
+ die_errno("Cannot come back to cwd");
387
+ *nongit_ok = 1;
388
+ return NULL;
389
+}
390
+
391
/*
392
* We cannot decide in this function whether we are in the work tree or
393
* not, since the config can only be read _after_ this function was called.
@@ -443,15 +453,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
453
return setup_bare_git_dir(work_tree_env, offset,
454
len, cwd, nongit_ok);
455
while (--offset > ceil_offset && cwd[offset] != '/');
446
- if (offset <= ceil_offset) {
447
- if (nongit_ok) {
448
- if (chdir(cwd))
449
- die_errno("Cannot come back to cwd");
450
- *nongit_ok = 1;
451
- return NULL;
452
- }
453
- die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
454
- }
456
+ if (offset <= ceil_offset)
457
+ return setup_nongit(cwd, nongit_ok);
458
if (one_filesystem) {
459
if (stat("..", &buf)) {
460
cwd[offset] = '\0';