"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Klemens Nanni <kn@openbsd.org>
Subject:
diff: reduce duplicate code
To:
gameoftrees@openbsd.org
Date:
Thu, 1 Apr 2021 19:50:38 +0200

Download raw body.

Thread
Condense error checking to reduce a future diff moving those lines around.
---
 got/got.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/got/got.c b/got/got.c
index 5d1639cc..192b847b 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4381,19 +4381,11 @@ cmd_diff(int argc, char *argv[])
 			error = got_worktree_open(&worktree, cwd);
 			if (error && error->code != GOT_ERR_NOT_WORKTREE)
 				goto done;
-			if (worktree) {
-				repo_path = strdup(
-				    got_worktree_get_repo_path(worktree));
-				if (repo_path == NULL) {
-					error = got_error_from_errno("strdup");
-					goto done;
-				}
-			} else {
-				repo_path = strdup(cwd);
-				if (repo_path == NULL) {
-					error = got_error_from_errno("strdup");
-					goto done;
-				}
+			repo_path = strdup(worktree ?
+			    got_worktree_get_repo_path(worktree) : cwd);
+			if (repo_path == NULL) {
+				error = got_error_from_errno("strdup");
+				goto done;
 			}
 		}
 	} else
-- 
2.31.0