repository: 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
diff --git a/src/repository.c b/src/repository.c
index 28cbf3c..697d6df 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -142,7 +142,7 @@ static void set_index(git_repository *repo, git_index *index)
int git_repository__cleanup(git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
git_repository_submodule_cache_clear(repo);
git_cache_clear(&repo->objects);
@@ -368,7 +368,7 @@ static size_t find_ceiling_dir_offset(
const char *ceil, *sep;
size_t len, max_len = 0, min_len;
- assert(path);
+ GIT_ASSERT_ARG(path);
min_len = (size_t)(git_path_root(path) + 1);
@@ -414,7 +414,8 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
git_buf file = GIT_BUF_INIT;
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
- assert(path_out && file_path);
+ GIT_ASSERT_ARG(path_out);
+ GIT_ASSERT_ARG(file_path);
if (git_futils_readbuffer(&file, file_path) < 0)
return -1;
@@ -901,7 +902,8 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
size_t len;
int err;
- assert(repo_out && wt);
+ GIT_ASSERT_ARG(repo_out);
+ GIT_ASSERT_ARG(wt);
*repo_out = NULL;
len = strlen(wt->gitlink_path);
@@ -947,7 +949,7 @@ int git_repository_discover(
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
int error;
- assert(start_path);
+ GIT_ASSERT_ARG(start_path);
if ((error = git_buf_sanitize(out)) < 0)
return error;
@@ -967,7 +969,7 @@ static int load_config(
git_buf config_path = GIT_BUF_INIT;
git_config *cfg = NULL;
- assert(out);
+ GIT_ASSERT_ARG(out);
if ((error = git_config_new(&cfg)) < 0)
return error;
@@ -1091,7 +1093,9 @@ int git_repository_config_snapshot(git_config **out, git_repository *repo)
int git_repository_set_config(git_repository *repo, git_config *config)
{
- assert(repo && config);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(config);
+
set_config(repo, config);
return 0;
}
@@ -1100,7 +1104,8 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
{
int error = 0;
- assert(repo && out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(out);
if (repo->_odb == NULL) {
git_buf odb_path = GIT_BUF_INIT;
@@ -1143,7 +1148,9 @@ int git_repository_odb(git_odb **out, git_repository *repo)
int git_repository_set_odb(git_repository *repo, git_odb *odb)
{
- assert(repo && odb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(odb);
+
set_odb(repo, odb);
return 0;
}
@@ -1152,7 +1159,8 @@ int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
{
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
if (repo->_refdb == NULL) {
git_refdb *refdb;
@@ -1184,7 +1192,9 @@ int git_repository_refdb(git_refdb **out, git_repository *repo)
int git_repository_set_refdb(git_repository *repo, git_refdb *refdb)
{
- assert(repo && refdb);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refdb);
+
set_refdb(repo, refdb);
return 0;
}
@@ -1193,7 +1203,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
{
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
if (repo->_index == NULL) {
git_buf index_path = GIT_BUF_INIT;
@@ -1234,7 +1245,7 @@ int git_repository_index(git_index **out, git_repository *repo)
int git_repository_set_index(git_repository *repo, git_index *index)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
set_index(repo, index);
return 0;
}
@@ -2132,7 +2143,9 @@ int git_repository_init_ext(
bool is_valid;
int error;
- assert(out && given_repo && opts);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(given_repo);
+ GIT_ASSERT_ARG(opts);
GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
@@ -2208,7 +2221,8 @@ int git_repository_head_detached_for_worktree(git_repository *repo, const char *
git_reference *ref = NULL;
int error;
- assert(repo && name);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
if ((error = git_repository_head_for_worktree(&ref, repo, name)) < 0)
goto out;
@@ -2225,7 +2239,7 @@ int git_repository_head(git_reference **head_out, git_repository *repo)
git_reference *head;
int error;
- assert(head_out);
+ GIT_ASSERT_ARG(head_out);
if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2248,7 +2262,9 @@ int git_repository_head_for_worktree(git_reference **out, git_repository *repo,
git_reference *head = NULL;
int error;
- assert(out && repo && name);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(name);
*out = NULL;
@@ -2462,13 +2478,13 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
const char *git_repository_path(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
return repo->gitdir;
}
const char *git_repository_workdir(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
if (repo->is_bare)
return NULL;
@@ -2478,7 +2494,7 @@ const char *git_repository_workdir(const git_repository *repo)
const char *git_repository_commondir(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
return repo->commondir;
}
@@ -2488,7 +2504,8 @@ int git_repository_set_workdir(
int error = 0;
git_buf path = GIT_BUF_INIT;
- assert(repo && workdir);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(workdir);
if (git_path_prettify_dir(&path, workdir, NULL) < 0)
return -1;
@@ -2528,13 +2545,13 @@ int git_repository_set_workdir(
int git_repository_is_bare(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return repo->is_bare;
}
int git_repository_is_worktree(const git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return repo->is_worktree;
}
@@ -2543,7 +2560,7 @@ int git_repository_set_bare(git_repository *repo)
int error;
git_config *config;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if (repo->is_bare)
return 0;
@@ -2657,7 +2674,10 @@ int git_repository_hashfile(
uint64_t len;
git_buf full_path = GIT_BUF_INIT;
- assert(out && path && repo); /* as_path can be NULL */
+ /* as_path can be NULL */
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(path);
+ GIT_ASSERT_ARG(repo);
/* At some point, it would be nice if repo could be NULL to just
* apply filter rules defined in system and global files, but for
@@ -2742,7 +2762,8 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
git_object *object = NULL, *peeled = NULL;
git_reference *new_head = NULL, *current = NULL;
- assert(repo && id);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(id);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2778,7 +2799,8 @@ int git_repository_set_head(
git_buf log_message = GIT_BUF_INIT;
int error;
- assert(repo && refname);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(refname);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2830,7 +2852,8 @@ int git_repository_set_head_detached_from_annotated(
git_repository *repo,
const git_annotated_commit *commitish)
{
- assert(repo && commitish);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commitish);
return detach(repo, git_annotated_commit_id(commitish), commitish->description);
}
@@ -2842,7 +2865,7 @@ int git_repository_detach_head(git_repository* repo)
git_buf log_message = GIT_BUF_INIT;
int error;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if ((error = git_reference_lookup(¤t, repo, GIT_HEAD_FILE)) < 0)
return error;
@@ -2877,7 +2900,7 @@ int git_repository_state(git_repository *repo)
git_buf repo_path = GIT_BUF_INIT;
int state = GIT_REPOSITORY_STATE_NONE;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if (git_buf_puts(&repo_path, repo->gitdir) < 0)
return -1;
@@ -2954,7 +2977,7 @@ static const char *state_files[] = {
int git_repository_state_cleanup(git_repository *repo)
{
- assert(repo);
+ GIT_ASSERT_ARG(repo);
return git_repository__cleanup_files(repo, state_files, ARRAY_SIZE(state_files));
}
@@ -3033,7 +3056,7 @@ int git_repository_submodule_cache_all(git_repository *repo)
{
int error;
- assert(repo);
+ GIT_ASSERT_ARG(repo);
if ((error = git_strmap_new(&repo->submodule_cache)))
return error;
@@ -3045,7 +3068,9 @@ int git_repository_submodule_cache_all(git_repository *repo)
int git_repository_submodule_cache_clear(git_repository *repo)
{
git_submodule *sm;
- assert(repo);
+
+ GIT_ASSERT_ARG(repo);
+
if (repo->submodule_cache == NULL) {
return 0;
}