Skip to content

Commit

Permalink
pack-bitmap.c: factor out bitmap_index_seek_commit()
Browse files Browse the repository at this point in the history
Factor out a common pattern within `lazy_bitmap_for_commit()` where we
seek to a given position (expecting to read the start of an individual
bitmap entry).

Both spots within `lazy_bitmap_for_commit()` emit a common error, so
factor out the whole routine into its own function to DRY things up a
little.

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr committed Mar 24, 2023
1 parent ba598cc commit 2543dde
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ static void bitmap_index_seek_ahead(struct bitmap_index *bitmap_git,
bitmap_git->map_pos += offset;
}

static int bitmap_index_seek_commit(struct bitmap_index *bitmap_git,
struct object_id *oid,
size_t pos)
{
const int bitmap_header_size = 6;

bitmap_index_seek(bitmap_git, pos, SEEK_SET);

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / win build

pack-bitmap.c:167:9: implicit declaration of function 'bitmap_index_seek'; did you mean 'bitmap_index_seek_set'? [-Wimplicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-clang (ubuntu-latest)

pack-bitmap.c:167:2: implicit declaration of function 'bitmap_index_seek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-asan (ubuntu-latest)

pack-bitmap.c:167:9: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-gcc (ubuntu-20.04)

pack-bitmap.c:167:2: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-leaks (ubuntu-latest)

pack-bitmap.c:167:9: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-gcc-default (ubuntu-latest)

pack-bitmap.c:167:9: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

pack-bitmap.c:167:2: implicit declaration of function 'bitmap_index_seek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-TEST-vars (ubuntu-20.04)

pack-bitmap.c:167:2: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

Check failure on line 167 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-ubsan (ubuntu-latest)

pack-bitmap.c:167:9: implicit declaration of function ‘bitmap_index_seek’; did you mean ‘bitmap_index_seek_set’? [-Werror=implicit-function-declaration]

if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size)
return error(_("corrupt ewah bitmap: truncated header for "
"bitmap of commit \"%s\""),
oid_to_hex(oid));
return 0;
}

/*
* Read a bitmap from the current read position on the mmaped
* index, and increase the read position accordingly
Expand Down Expand Up @@ -739,7 +754,6 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
struct object_id *oid = &commit->object.oid;
struct ewah_bitmap *bitmap;
struct stored_bitmap *xor_bitmap = NULL;
const int bitmap_header_size = 6;
static struct bitmap_lookup_table_xor_item *xor_items = NULL;
static size_t xor_items_nr = 0, xor_items_alloc = 0;
static int is_corrupt = 0;
Expand Down Expand Up @@ -798,13 +812,10 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_

while (xor_items_nr) {
xor_item = &xor_items[xor_items_nr - 1];
bitmap_index_seek(bitmap_git, xor_item->offset, SEEK_SET);

if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) {
error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""),
oid_to_hex(&xor_item->oid));
if (bitmap_index_seek_commit(bitmap_git, &xor_item->oid,
xor_item->offset) < 0)
goto corrupt;
}

bitmap_index_seek(bitmap_git,

Check failure on line 820 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-clang (ubuntu-latest)

pack-bitmap.c:820:3: implicit declaration of function 'bitmap_index_seek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Check failure on line 820 in pack-bitmap.c

View workflow job for this annotation

GitHub Actions / linux-sha256 (ubuntu-latest)

pack-bitmap.c:820:3: implicit declaration of function 'bitmap_index_seek' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
sizeof(uint32_t) + sizeof(uint8_t), SEEK_CUR);
Expand All @@ -818,12 +829,8 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
xor_items_nr--;
}

bitmap_index_seek(bitmap_git, offset, SEEK_SET);
if (bitmap_git->map_size - bitmap_git->map_pos < bitmap_header_size) {
error(_("corrupt ewah bitmap: truncated header for bitmap of commit \"%s\""),
oid_to_hex(oid));
if (bitmap_index_seek_commit(bitmap_git, oid, offset) < 0)
goto corrupt;
}

/*
* Don't bother reading the commit's index position or its xor
Expand Down

0 comments on commit 2543dde

Please sign in to comment.