Skip to content

Commit 4dba930

Browse files
committed
pack-objects: use GIT_ASSERT
1 parent 7cd0bf6 commit 4dba930

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/pack-objects.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,10 @@ struct walk_object {
4848
};
4949

5050
#ifdef GIT_THREADS
51-
52-
#define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) do { \
53-
int result = git_mutex_##op(&(pb)->mtx); \
54-
assert(!result); \
55-
GIT_UNUSED(result); \
56-
} while (0)
57-
51+
# define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) git_mutex_##op(&(pb)->mtx)
5852
#else
59-
60-
#define GIT_PACKBUILDER__MUTEX_OP(pb,mtx,op) GIT_UNUSED(pb)
61-
62-
#endif /* GIT_THREADS */
53+
# define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) GIT_UNUSED(pb)
54+
#endif
6355

6456
#define git_packbuilder__cache_lock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, cache_mutex, lock)
6557
#define git_packbuilder__cache_unlock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, cache_mutex, unlock)
@@ -177,13 +169,13 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
177169

178170
unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
179171
{
180-
assert(pb);
172+
GIT_ASSERT_ARG(pb);
181173

182174
#ifdef GIT_THREADS
183175
pb->nr_threads = n;
184176
#else
185177
GIT_UNUSED(n);
186-
assert(1 == pb->nr_threads);
178+
GIT_ASSERT(pb->nr_threads == 1);
187179
#endif
188180

189181
return pb->nr_threads;
@@ -211,7 +203,8 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
211203
size_t newsize;
212204
int ret;
213205

214-
assert(pb && oid);
206+
GIT_ASSERT_ARG(pb);
207+
GIT_ASSERT_ARG(oid);
215208

216209
/* If the object already exists in the hash table, then we don't
217210
* have any work to do */
@@ -851,18 +844,19 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
851844
}
852845
}
853846

854-
git_packbuilder__cache_lock(pb);
847+
GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
848+
855849
if (trg_object->delta_data) {
856850
git__free(trg_object->delta_data);
857-
assert(pb->delta_cache_size >= trg_object->delta_size);
851+
GIT_ASSERT(pb->delta_cache_size >= trg_object->delta_size);
858852
pb->delta_cache_size -= trg_object->delta_size;
859853
trg_object->delta_data = NULL;
860854
}
861855
if (delta_cacheable(pb, src_size, trg_size, delta_size)) {
862856
bool overflow = git__add_sizet_overflow(
863857
&pb->delta_cache_size, pb->delta_cache_size, delta_size);
864858

865-
git_packbuilder__cache_unlock(pb);
859+
GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
866860

867861
if (overflow) {
868862
git__free(delta_buf);
@@ -873,7 +867,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
873867
GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
874868
} else {
875869
/* create delta when writing the pack */
876-
git_packbuilder__cache_unlock(pb);
870+
GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
877871
git__free(delta_buf);
878872
}
879873

@@ -961,9 +955,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
961955
struct unpacked *n = array + idx;
962956
size_t max_depth, j, best_base = SIZE_MAX;
963957

964-
git_packbuilder__progress_lock(pb);
958+
GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
965959
if (!*list_size) {
966-
git_packbuilder__progress_unlock(pb);
960+
GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
967961
break;
968962
}
969963

@@ -972,7 +966,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
972966

973967
po = *list++;
974968
(*list_size)--;
975-
git_packbuilder__progress_unlock(pb);
969+
GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
976970

977971
mem_usage -= free_unpacked(n);
978972
n->object = po;
@@ -1047,10 +1041,10 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
10471041
po->z_delta_size = zbuf.size;
10481042
git_buf_clear(&zbuf);
10491043

1050-
git_packbuilder__cache_lock(pb);
1044+
GIT_ASSERT(git_packbuilder__cache_lock(pb) == 0);
10511045
pb->delta_cache_size -= po->delta_size;
10521046
pb->delta_cache_size += po->z_delta_size;
1053-
git_packbuilder__cache_unlock(pb);
1047+
GIT_ASSERT(git_packbuilder__cache_unlock(pb) == 0);
10541048
}
10551049

10561050
/*
@@ -1128,10 +1122,10 @@ static void *threaded_find_deltas(void *arg)
11281122
; /* TODO */
11291123
}
11301124

1131-
git_packbuilder__progress_lock(me->pb);
1125+
GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_lock(me->pb) == 0, NULL);
11321126
me->working = 0;
11331127
git_cond_signal(&me->pb->progress_cond);
1134-
git_packbuilder__progress_unlock(me->pb);
1128+
GIT_ASSERT_WITH_RETVAL(git_packbuilder__progress_unlock(me->pb) == 0, NULL);
11351129

11361130
if (git_mutex_lock(&me->mutex)) {
11371131
git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
@@ -1236,7 +1230,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
12361230
* 'working' flag from 1 -> 0. This indicates that it is
12371231
* ready to receive more work using our work-stealing
12381232
* algorithm. */
1239-
git_packbuilder__progress_lock(pb);
1233+
GIT_ASSERT(git_packbuilder__progress_lock(pb) == 0);
12401234
for (;;) {
12411235
for (i = 0; !target && i < pb->nr_threads; i++)
12421236
if (!p[i].working)
@@ -1279,7 +1273,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
12791273
target->list_size = sub_size;
12801274
target->remaining = sub_size;
12811275
target->working = 1;
1282-
git_packbuilder__progress_unlock(pb);
1276+
GIT_ASSERT(git_packbuilder__progress_unlock(pb) == 0);
12831277

12841278
if (git_mutex_lock(&target->mutex)) {
12851279
git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
@@ -1490,7 +1484,8 @@ int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const c
14901484
git_object *obj;
14911485
int error;
14921486

1493-
assert(pb && id);
1487+
GIT_ASSERT_ARG(pb);
1488+
GIT_ASSERT_ARG(id);
14941489

14951490
if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
14961491
return error;
@@ -1731,7 +1726,8 @@ int git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk)
17311726
git_oid id;
17321727
struct walk_object *obj;
17331728

1734-
assert(pb && walk);
1729+
GIT_ASSERT_ARG(pb);
1730+
GIT_ASSERT_ARG(walk);
17351731

17361732
if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
17371733
return error;

0 commit comments

Comments
 (0)