@matheusbsbs / matheus-bagliano / commits / 93a00542ea
Fork 0

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>

Jonathan Nieder committed Jul 24, 2010 at 06:20 UTC 93a00542eaeb40c31b4de2497f5413a2fc0f36f4
1 file changed +13 -7
setup.c
+13 -7
@@ -348,6 +348,18 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
348 return retval;
349 }
350
351 +static int cwd_contains_git_dir(const char **gitfile_dirp)
352 +{
353 + const char *gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
354 + *gitfile_dirp = gitfile_dir;
355 + if (gitfile_dir) {
356 + if (set_git_dir(gitfile_dir))
357 + die("Repository setup failed");
358 + return 1;
359 + }
360 + return is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT);
361 +}
362 +
363 /*
364 * We cannot decide in this function whether we are in the work tree or
365 * 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)
419 current_device = buf.st_dev;
420 }
421 for (;;) {
410 - gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
411 - if (gitfile_dir) {
412 - if (set_git_dir(gitfile_dir))
413 - die("Repository setup failed");
414 - break;
415 - }
416 - if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
422 + if (cwd_contains_git_dir(&gitfile_dir))
423 break;
424 if (is_git_directory(".")) {
425 inside_git_dir = 1;