worktree: use GIT_ASSERT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
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;
}