git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] init: remove unnecessary check

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 3, 2011, 12:34 UTC
Message-ID
<1299155691-11850-1-git-send-email-pclouds@gmail.com>

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 <pclouds@gmail.com>
---
 builtin/init-db.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 4f5348e..fbeb380 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -498,13 +498,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 		is_bare_repository_cfg = guess_repository_type(git_dir);
 
 	if (!is_bare_repository_cfg) {
-		if (git_dir) {
-			const char *git_dir_parent = strrchr(git_dir, '/');
-			if (git_dir_parent) {
-				char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
-				git_work_tree_cfg = xstrdup(make_absolute_path(rel));
-				free(rel);
-			}
+		const char *git_dir_parent = strrchr(git_dir, '/');
+		if (git_dir_parent) {
+			char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
+			git_work_tree_cfg = xstrdup(make_absolute_path(rel));
+			free(rel);
 		}
 		if (!git_work_tree_cfg) {
 			git_work_tree_cfg = xcalloc(PATH_MAX, 1);
-- 
1.7.4.74.g639db
Message 1 of 1 in “init: remove unnecessary check”
  1. init: remove unnecessary checkNguyễn Thái Ngọc Duy, Mar 3, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.