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>
Nguyễn Thái Ngọc Duy committed
Jul 24, 2010 at 07:11 UTC
98937bef1bf1c8eea90c209c601d4338a43a3479
1 file changed
+25
-18
setup.c
+25
-18
@@ -360,6 +360,28 @@ 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_discovered_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 = 0;
369
+ if (!work_tree_env)
370
+ inside_work_tree = 1;
371
+ root_len = offset_1st_component(cwd);
372
+ git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
373
+ if (check_repository_format_gently(nongit_ok))
374
+ return NULL;
375
+ if (offset == len)
376
+ return NULL;
377
+
378
+ /* Make "offset" point to past the '/', and add a '/' at the end */
379
+ offset++;
380
+ cwd[len++] = '/';
381
+ cwd[len] = 0;
382
+ return cwd + offset;
383
+}
384
+
385
static const char *setup_bare_git_dir(const char *work_tree_env,
386
int offset, int len, char *cwd, int *nongit_ok)
387
{
@@ -411,7 +433,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
433
static char cwd[PATH_MAX+1];
434
const char *gitdirenv;
435
const char *gitfile_dir;
414
- int len, offset, ceil_offset, root_len;
436
+ int len, offset, ceil_offset;
437
dev_t current_device = 0;
438
int one_filesystem = 1;
439
@@ -456,7 +478,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
478
current_device = get_device_or_die(".", NULL);
479
for (;;) {
480
if (cwd_contains_git_dir(&gitfile_dir))
459
- break;
481
+ return setup_discovered_git_dir(work_tree_env, offset,
482
+ len, cwd, nongit_ok);
483
if (is_git_directory("."))
484
return setup_bare_git_dir(work_tree_env, offset,
485
len, cwd, nongit_ok);
@@ -482,22 +505,6 @@ const char *setup_git_directory_gently(int *nongit_ok)
505
die_errno("Cannot change to '%s/..'", cwd);
506
}
507
}
485
-
486
- inside_git_dir = 0;
487
- if (!work_tree_env)
488
- inside_work_tree = 1;
489
- root_len = offset_1st_component(cwd);
490
- git_work_tree_cfg = xstrndup(cwd, offset > root_len ? offset : root_len);
491
- if (check_repository_format_gently(nongit_ok))
492
- return NULL;
493
- if (offset == len)
494
- return NULL;
495
-
496
- /* Make "offset" point to past the '/', and add a '/' at the end */
497
- offset++;
498
- cwd[len++] = '/';
499
- cwd[len] = 0;
500
- return cwd + offset;
508
}
509
510
int git_config_perm(const char *var, const char *value)