refdb_fs: 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
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 7e04819..aef5ab2 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -331,7 +331,7 @@ static int refdb_fs_backend__exists(
git_buf ref_path = GIT_BUF_INIT;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
*exists = 0;
@@ -472,7 +472,7 @@ static int refdb_fs_backend__lookup(
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if (!(error = loose_lookup(out, backend, ref_name)))
return 0;
@@ -678,7 +678,7 @@ static int refdb_fs_backend__iterator(
refdb_fs_iter *iter = NULL;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
iter = git__calloc(1, sizeof(refdb_fs_iter));
GIT_ERROR_CHECK_ALLOC(iter);
@@ -783,7 +783,9 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
git_buf ref_path = GIT_BUF_INIT;
const char *basedir;
- assert(file && backend && name);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(name);
if (!git_path_isvalid(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
@@ -819,7 +821,8 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
static int loose_commit(git_filebuf *file, const git_reference *ref)
{
- assert(file && ref);
+ GIT_ASSERT_ARG(file);
+ GIT_ASSERT_ARG(ref);
if (ref->type == GIT_REFERENCE_DIRECT) {
char oid[GIT_OID_HEXSZ + 1];
@@ -829,7 +832,7 @@ static int loose_commit(git_filebuf *file, const git_reference *ref)
} else if (ref->type == GIT_REFERENCE_SYMBOLIC) {
git_filebuf_printf(file, GIT_SYMREF "%s\n", ref->target.symbolic);
} else {
- assert(0); /* don't let this happen */
+ GIT_ASSERT(0);
}
return git_filebuf_commit(file);
@@ -1066,7 +1069,7 @@ static int packed_write(refdb_fs_backend *backend)
for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
struct packref *ref = git_sortedcache_entry(refcache, i);
- assert(ref);
+ GIT_ASSERT(ref);
if ((error = packed_find_peel(backend, ref)) < 0)
goto fail;
@@ -1219,7 +1222,7 @@ static int refdb_fs_backend__write(
git_filebuf file = GIT_FILEBUF_INIT;
int error = 0;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = reference_path_available(backend, ref->name, NULL, force)) < 0)
return error;
@@ -1292,7 +1295,7 @@ on_error:
return error;
}
-static void refdb_fs_backend__prune_refs(
+static int refdb_fs_backend__prune_refs(
refdb_fs_backend *backend,
const char *ref_name,
const char *prefix)
@@ -1300,10 +1303,12 @@ static void refdb_fs_backend__prune_refs(
git_buf relative_path = GIT_BUF_INIT;
git_buf base_path = GIT_BUF_INIT;
size_t commonlen;
+ int error;
- assert(backend && ref_name);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(ref_name);
- if (git_buf_sets(&relative_path, ref_name) < 0)
+ if ((error = git_buf_sets(&relative_path, ref_name)) < 0)
goto cleanup;
git_path_squash_slashes(&relative_path);
@@ -1313,20 +1318,30 @@ static void refdb_fs_backend__prune_refs(
git_buf_truncate(&relative_path, commonlen);
- if (prefix) {
- if (git_buf_join3(&base_path, '/', backend->commonpath, prefix, git_buf_cstr(&relative_path)) < 0)
- goto cleanup;
- } else {
- if (git_buf_joinpath(&base_path, backend->commonpath, git_buf_cstr(&relative_path)) < 0)
- goto cleanup;
- }
+ if (prefix)
+ error = git_buf_join3(&base_path, '/',
+ backend->commonpath, prefix,
+ git_buf_cstr(&relative_path));
+ else
+ error = git_buf_joinpath(&base_path,
+ backend->commonpath,
+ git_buf_cstr(&relative_path));
+
+ if (error < 0)
+ goto cleanup;
+
+ error = git_futils_rmdir_r(ref_name + commonlen,
+ git_buf_cstr(&base_path),
+ GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
- git_futils_rmdir_r(ref_name + commonlen, git_buf_cstr(&base_path), GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
+ if (error == GIT_ENOTFOUND)
+ error = 0;
}
cleanup:
git_buf_dispose(&relative_path);
git_buf_dispose(&base_path);
+ return error;
}
static int refdb_fs_backend__delete(
@@ -1338,7 +1353,8 @@ static int refdb_fs_backend__delete(
git_filebuf file = GIT_FILEBUF_INIT;
int error = 0;
- assert(backend && ref_name);
+ GIT_ASSERT_ARG(backend);
+ GIT_ASSERT_ARG(ref_name);
if ((error = loose_lock(&file, backend, ref_name)) < 0)
return error;
@@ -1424,7 +1440,7 @@ static int refdb_fs_backend__delete_tail(
cleanup:
git_filebuf_cleanup(file);
if (error == 0)
- refdb_fs_backend__prune_refs(backend, ref_name, "");
+ error = refdb_fs_backend__prune_refs(backend, ref_name, "");
return error;
}
@@ -1444,7 +1460,7 @@ static int refdb_fs_backend__rename(
git_filebuf file = GIT_FILEBUF_INIT;
int error;
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = reference_path_available(
backend, new_name, old_name, force)) < 0 ||
@@ -1497,7 +1513,7 @@ static int refdb_fs_backend__compress(git_refdb_backend *_backend)
int error;
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- assert(backend);
+ GIT_ASSERT_ARG(backend);
if ((error = packed_reload(backend)) < 0 || /* load the existing packfile */
(error = packed_loadloose(backend)) < 0 || /* add all the loose refs */
@@ -1511,7 +1527,8 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
{
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
- assert(backend);
+ if (!backend)
+ return;
git_sortedcache_free(backend->refcache);
git__free(backend->gitpath);
@@ -1672,7 +1689,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
git_buf path = GIT_BUF_INIT;
int error;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend && name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo;
@@ -1705,7 +1722,8 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
{
refdb_fs_backend *backend;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
@@ -1721,7 +1739,9 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
git_repository *repo;
refdb_fs_backend *backend;
- assert(out && _backend && name);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo;
@@ -1838,7 +1858,8 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
git_buf log = GIT_BUF_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
- assert(_backend && reflog);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(reflog);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
@@ -1960,7 +1981,9 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
git_repository *repo;
refdb_fs_backend *backend;
- assert(_backend && old_name && new_name);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(old_name);
+ GIT_ASSERT_ARG(new_name);
backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo;
@@ -2037,7 +2060,8 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
git_buf path = GIT_BUF_INIT;
int error;
- assert(_backend && name);
+ GIT_ASSERT_ARG(_backend);
+ GIT_ASSERT_ARG(name);
if ((error = retrieve_reflog_path(&path, backend->repo, name)) < 0)
goto out;
@@ -2048,7 +2072,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
if ((error = p_unlink(path.ptr)) < 0)
goto out;
- refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
+ error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
out:
git_buf_dispose(&path);