init: kill set_git_dir_init()
This is a pure code move, necessary to kill the global variable git_link later (and also helps a bit in the next patch). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Sep 25, 2016 at 10:14 UTC
1bd1907951a42040fa14fd19e432df9cb4107180
1 file changed
+21
-29
builtin/init-db.c
+21
-29
@@ -311,34 +311,6 @@ static void create_object_directory(void)
311
strbuf_release(&path);
312
}
313
314
-static int set_git_dir_init(const char *git_dir,
315
- const char *real_git_dir,
316
- int exist_ok)
317
-{
318
- if (real_git_dir) {
319
- struct stat st;
320
-
321
- if (!exist_ok && !stat(git_dir, &st))
322
- die(_("%s already exists"), git_dir);
323
-
324
- if (!exist_ok && !stat(real_git_dir, &st))
325
- die(_("%s already exists"), real_git_dir);
326
-
327
- /*
328
- * make sure symlinks are resolved because we'll be
329
- * moving the target repo later on in separate_git_dir()
330
- */
331
- git_link = xstrdup(real_path(git_dir));
332
- set_git_dir(real_path(real_git_dir));
333
- }
334
- else {
335
- set_git_dir(real_path(git_dir));
336
- git_link = NULL;
337
- }
338
- startup_info->have_repository = 1;
339
- return 0;
340
-}
341
-
314
static void separate_git_dir(const char *git_dir)
315
{
316
struct stat st;
@@ -364,9 +336,29 @@ int init_db(const char *git_dir, const char *real_git_dir,
336
const char *template_dir, unsigned int flags)
337
{
338
int reinit;
339
+ int exist_ok = flags & INIT_DB_EXIST_OK;
340
368
- set_git_dir_init(git_dir, real_git_dir, flags & INIT_DB_EXIST_OK);
341
+ if (real_git_dir) {
342
+ struct stat st;
343
344
+ if (!exist_ok && !stat(git_dir, &st))
345
+ die(_("%s already exists"), git_dir);
346
+
347
+ if (!exist_ok && !stat(real_git_dir, &st))
348
+ die(_("%s already exists"), real_git_dir);
349
+
350
+ /*
351
+ * make sure symlinks are resolved because we'll be
352
+ * moving the target repo later on in separate_git_dir()
353
+ */
354
+ git_link = xstrdup(real_path(git_dir));
355
+ set_git_dir(real_path(real_git_dir));
356
+ }
357
+ else {
358
+ set_git_dir(real_path(git_dir));
359
+ git_link = NULL;
360
+ }
361
+ startup_info->have_repository = 1;
362
git_dir = get_git_dir();
363
364
if (git_link)