Skip to content

Commit 7cd0bf6

Browse files
committed
pack: use GIT_ASSERT
1 parent 87d3789 commit 7cd0bf6

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/indexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,8 @@ static int inject_object(git_indexer *idx, git_oid *id)
900900
entry->crc = crc32(0L, Z_NULL, 0);
901901

902902
/* Write out the object header */
903-
hdr_len = git_packfile__object_header(hdr, len, git_odb_object_type(obj));
904-
if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
903+
if ((error = git_packfile__object_header(&hdr_len, hdr, len, git_odb_object_type(obj))) < 0 ||
904+
(error = append_to_pack(idx, hdr, hdr_len)) < 0)
905905
goto cleanup;
906906

907907
idx->pack->mwf.size += hdr_len;

src/pack-objects.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,9 @@ static int write_object(
347347
}
348348

349349
/* Write header */
350-
hdr_len = git_packfile__object_header(hdr, data_len, type);
351-
352-
if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
353-
(error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
350+
if ((error = git_packfile__object_header(&hdr_len, hdr, data_len, type)) < 0 ||
351+
(error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
352+
(error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
354353
goto done;
355354

356355
if (type == GIT_OBJECT_REF_DELTA) {

src/pack.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ static void free_cache_object(void *o)
6767
git_pack_cache_entry *e = (git_pack_cache_entry *)o;
6868

6969
if (e != NULL) {
70-
assert(e->refcount.val == 0);
7170
git__free(e->raw.data);
7271
git__free(e);
7372
}
@@ -311,8 +310,9 @@ static int pack_index_open(struct git_pack_file *p)
311310
if (p->index_version > -1)
312311
return 0;
313312

313+
/* checked by git_pack_file alloc */
314314
name_len = strlen(p->pack_name);
315-
assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
315+
GIT_ASSERT(name_len > strlen(".pack"));
316316

317317
if (git_buf_init(&idx_name, name_len) < 0)
318318
return -1;
@@ -372,12 +372,12 @@ static unsigned char *pack_window_open(
372372
* - each byte afterwards: low seven bits are size continuation,
373373
* with the high bit being "size continues"
374374
*/
375-
size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type)
375+
int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type)
376376
{
377377
unsigned char *hdr_base;
378378
unsigned char c;
379379

380-
assert(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
380+
GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
381381

382382
/* TODO: add support for chunked objects; see git.git 6c0d19b1 */
383383

@@ -392,7 +392,8 @@ size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t
392392
}
393393
*hdr++ = c;
394394

395-
return (hdr - hdr_base);
395+
*out = (hdr - hdr_base);
396+
return 0;
396397
}
397398

398399

@@ -899,7 +900,7 @@ int get_delta_base(
899900
off64_t base_offset;
900901
git_oid unused;
901902

902-
assert(delta_base_out);
903+
GIT_ASSERT_ARG(delta_base_out);
903904

904905
base_info = pack_window_open(p, w_curs, *curpos, &left);
905906
/* Assumption: the only reason this would fail is because the file is too small */
@@ -1211,8 +1212,7 @@ int git_pack_foreach_entry(
12111212
if ((error = pack_index_open(p)) < 0)
12121213
return error;
12131214

1214-
assert(p->index_map.data);
1215-
1215+
GIT_ASSERT(p->index_map.data);
12161216
index = p->index_map.data;
12171217
}
12181218

@@ -1299,7 +1299,8 @@ static int pack_entry_find_offset(
12991299

13001300
if ((error = pack_index_open(p)) < 0)
13011301
return error;
1302-
assert(p->index_map.data);
1302+
1303+
GIT_ASSERT(p->index_map.data);
13031304
}
13041305

13051306
index = p->index_map.data;
@@ -1388,7 +1389,7 @@ int git_pack_entry_find(
13881389
git_oid found_oid;
13891390
int error;
13901391

1391-
assert(p);
1392+
GIT_ASSERT_ARG(p);
13921393

13931394
if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
13941395
unsigned i;

src/pack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ typedef struct git_packfile_stream {
133133
git_mwindow *mw;
134134
} git_packfile_stream;
135135

136-
size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type);
136+
int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type);
137137

138138
int git_packfile__name(char **out, const char *path);
139139

0 commit comments

Comments
 (0)