Commit 0165e885bcb04cb3134df0dbe32f27b8deeabc65

Edward Thomson 2020-04-05T22:29:56

worktree: use GIT_ASSERT

diff --git a/src/worktree.c b/src/worktree.c
index 5b1e279..7d447e8 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -37,7 +37,8 @@ int git_worktree_list(git_strarray *wts, git_repository *repo)
 	size_t i, len;
 	int error;
 
-	assert(wts && repo);
+	GIT_ASSERT_ARG(wts);
+	GIT_ASSERT_ARG(repo);
 
 	wts->count = 0;
 	wts->strings = NULL;
@@ -73,7 +74,8 @@ char *git_worktree__read_link(const char *base, const char *file)
 {
 	git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
 
-	assert(base && file);
+	GIT_ASSERT_ARG_WITH_RETVAL(base, NULL);
+	GIT_ASSERT_ARG_WITH_RETVAL(file, NULL);
 
 	if (git_buf_joinpath(&path, base, file) < 0)
 		goto err;
@@ -106,7 +108,9 @@ static int write_wtfile(const char *base, const char *file, const git_buf *buf)
 	git_buf path = GIT_BUF_INIT;
 	int err;
 
-	assert(base && file && buf);
+	GIT_ASSERT_ARG(base);
+	GIT_ASSERT_ARG(file);
+	GIT_ASSERT_ARG(buf);
 
 	if ((err = git_buf_joinpath(&path, base, file)) < 0)
 		goto out;
@@ -170,7 +174,8 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na
 	git_worktree *wt = NULL;
 	int error;
 
-	assert(repo && name);
+	GIT_ASSERT_ARG(repo);
+	GIT_ASSERT_ARG(name);
 
 	*out = NULL;
 
@@ -237,7 +242,7 @@ void git_worktree_free(git_worktree *wt)
 
 int git_worktree_validate(const git_worktree *wt)
 {
-	assert(wt);
+	GIT_ASSERT_ARG(wt);
 
 	if (!is_worktree_dir(wt->gitdir_path)) {
 		git_error_set(GIT_ERROR_WORKTREE,
@@ -304,7 +309,10 @@ int git_worktree_add(git_worktree **out, git_repository *repo,
 	if (opts)
 		memcpy(&wtopts, opts, sizeof(wtopts));
 
-	assert(out && repo && name && worktree);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(repo);
+	GIT_ASSERT_ARG(name);
+	GIT_ASSERT_ARG(worktree);
 
 	*out = NULL;
 
@@ -417,7 +425,7 @@ int git_worktree_lock(git_worktree *wt, const char *reason)
 	git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
 	int error;
 
-	assert(wt);
+	GIT_ASSERT_ARG(wt);
 
 	if ((error = git_worktree_is_locked(NULL, wt)) < 0)
 		goto out;
@@ -448,7 +456,7 @@ int git_worktree_unlock(git_worktree *wt)
 	git_buf path = GIT_BUF_INIT;
 	int error;
 
-	assert(wt);
+	GIT_ASSERT_ARG(wt);
 
 	if ((error = git_worktree_is_locked(NULL, wt)) < 0)
 		return error;
@@ -475,7 +483,7 @@ int git_worktree_is_locked(git_buf *reason, const git_worktree *wt)
 	git_buf path = GIT_BUF_INIT;
 	int error, locked;
 
-	assert(wt);
+	GIT_ASSERT_ARG(wt);
 
 	if (reason)
 		git_buf_clear(reason);
@@ -496,13 +504,13 @@ out:
 
 const char *git_worktree_name(const git_worktree *wt)
 {
-	assert(wt);
+	GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
 	return wt->name;
 }
 
 const char *git_worktree_path(const git_worktree *wt)
 {
-	assert(wt);
+	GIT_ASSERT_ARG_WITH_RETVAL(wt, NULL);
 	return wt->worktree_path;
 }