Skip to content

Commit 1bd1907

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3315870 commit 1bd1907

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

builtin/init-db.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -311,34 +311,6 @@ static void create_object_directory(void)
311311
strbuf_release(&path);
312312
}
313313

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-
342314
static void separate_git_dir(const char *git_dir)
343315
{
344316
struct stat st;
@@ -364,9 +336,29 @@ int init_db(const char *git_dir, const char *real_git_dir,
364336
const char *template_dir, unsigned int flags)
365337
{
366338
int reinit;
339+
int exist_ok = flags & INIT_DB_EXIST_OK;
367340

368-
set_git_dir_init(git_dir, real_git_dir, flags & INIT_DB_EXIST_OK);
341+
if (real_git_dir) {
342+
struct stat st;
369343

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;
370362
git_dir = get_git_dir();
371363

372364
if (git_link)

0 commit comments

Comments
 (0)