@matheusbsbs / matheus-bagliano / commits / 68698da540
Fork 0

setup: split off code to handle stumbling upon a repository

If a repository is found as an ancestor of the original working directory, it is assumed by default to be bare. Handle this case with its own function. 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:25 UTC 68698da540acb0c891b810396d704fef3643c576
1 file changed +21 -13
setup.c
+21 -13
@@ -360,6 +360,24 @@ static int cwd_contains_git_dir(const char **gitfile_dirp)
360 return is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT);
361 }
362
363 +static const char *setup_bare_git_dir(const char *work_tree_env,
364 + int offset, int len, char *cwd, int *nongit_ok)
365 +{
366 + int root_len;
367 +
368 + inside_git_dir = 1;
369 + if (!work_tree_env)
370 + inside_work_tree = 0;
371 + if (offset != len) {
372 + root_len = offset_1st_component(cwd);
373 + cwd[offset > root_len ? offset : root_len] = '\0';
374 + set_git_dir(cwd);
375 + } else
376 + set_git_dir(".");
377 + check_repository_format_gently(nongit_ok);
378 + return NULL;
379 +}
380 +
381 /*
382 * We cannot decide in this function whether we are in the work tree or
383 * not, since the config can only be read _after_ this function was called.
@@ -421,19 +439,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
439 for (;;) {
440 if (cwd_contains_git_dir(&gitfile_dir))
441 break;
424 - if (is_git_directory(".")) {
425 - inside_git_dir = 1;
426 - if (!work_tree_env)
427 - inside_work_tree = 0;
428 - if (offset != len) {
429 - root_len = offset_1st_component(cwd);
430 - cwd[offset > root_len ? offset : root_len] = '\0';
431 - set_git_dir(cwd);
432 - } else
433 - set_git_dir(".");
434 - check_repository_format_gently(nongit_ok);
435 - return NULL;
436 - }
442 + if (is_git_directory("."))
443 + return setup_bare_git_dir(work_tree_env, offset,
444 + len, cwd, nongit_ok);
445 while (--offset > ceil_offset && cwd[offset] != '/');
446 if (offset <= ceil_offset) {
447 if (nongit_ok) {