threads / patch / 63314

patch, 2 partsremove unnecessary if statement

Subject: [PATCH 0/2] remove unnecessary if statement

## tl;dr

3 messages between Apr 20, 2025 and Apr 20, 2025. Diffs are folded; open one to read it.

replies: 2people: 1as markdown or json

Usman Akinyemi· Apr 20, 2025, 02:54 UTC · lore

Since we already teach the `repo_config()` in "f29f1990b5 (config: teach repo_config to allow `repo` to be NULL, 2025-03-08)" to allow `repo` to be NULL, no need to check if `repo` is NULL before calling `repo_config()`.

This was suggested by Patrick Steinhardt <ps@pks.im>
Usman Akinyemi (2):
  builtin/add: remove unnecessary if statement
  builtin/difftool: remove unnecessary if statement
 builtin/add.c      | 3 +--
 builtin/difftool.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
-- 
2.49.0
Usman Akinyemi· Apr 20, 2025, 02:54 UTC · re: Usman Akinyemi · lore

[PATCH 1/2] builtin/add: remove unnecessary if statement

Since we already teach the `repo_config()` in "f29f1990b5 (config: teach repo_config to allow `repo` to be NULL, 2025-03-08)" to allow `repo` to be NULL, no need to check if `repo` is NULL before calling `repo_config()`.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
---
 builtin/add.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to builtin/add.c +1 −2
diff --git a/builtin/add.c b/builtin/add.c
index 78dfb26577..747511b68b 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -386,8 +386,7 @@ int cmd_add(int argc,
 	char *ps_matched = NULL;
 	struct lock_file lock_file = LOCK_INIT;
 
-	if (repo)
-		repo_config(repo, add_config, NULL);
+	repo_config(repo, add_config, NULL);
 
 	argc = parse_options(argc, argv, prefix, builtin_add_options,
 			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
-- 
2.49.0
Usman Akinyemi· Apr 20, 2025, 02:54 UTC · re: Usman Akinyemi · lore

[PATCH 2/2] builtin/difftool: remove unnecessary if statement

Since we already teach the `repo_config()` in "f29f1990b5 (config: teach repo_config to allow `repo` to be NULL, 2025-03-08)" to allow `repo` to be NULL, no need to check if `repo` is NULL before calling `repo_config()`.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
---
 builtin/difftool.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to builtin/difftool.c +1 −2
diff --git a/builtin/difftool.c b/builtin/difftool.c
index 41cd00066c..c7348a1dca 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -750,8 +750,7 @@ int cmd_difftool(int argc,
 	};
 	struct child_process child = CHILD_PROCESS_INIT;
 
-	if (repo)
-		repo_config(repo, difftool_config, &dt_options);
+	repo_config(repo, difftool_config, &dt_options);
 	dt_options.symlinks = dt_options.has_symlinks;
 
 	argc = parse_options(argc, argv, prefix, builtin_difftool_options,
-- 
2.49.0

← back to recent threads