Skip to content

Commit b31d202

Browse files
pcloudsgitster
authored andcommitted
init: remove unnecessary check
git_dir must always be non-NULL so "if (git_dir)" is unnecessary. Before this code, if git_dir == NULL, it will default to DEFAULT_GIT_DIR_ENVIRONMENT. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec48d4b commit b31d202

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

builtin/init-db.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
498498
is_bare_repository_cfg = guess_repository_type(git_dir);
499499

500500
if (!is_bare_repository_cfg) {
501-
if (git_dir) {
502-
const char *git_dir_parent = strrchr(git_dir, '/');
503-
if (git_dir_parent) {
504-
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
505-
git_work_tree_cfg = xstrdup(make_absolute_path(rel));
506-
free(rel);
507-
}
501+
const char *git_dir_parent = strrchr(git_dir, '/');
502+
if (git_dir_parent) {
503+
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
504+
git_work_tree_cfg = xstrdup(make_absolute_path(rel));
505+
free(rel);
508506
}
509507
if (!git_work_tree_cfg) {
510508
git_work_tree_cfg = xcalloc(PATH_MAX, 1);

0 commit comments

Comments
 (0)