Skip to content

Commit 79621f3

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap: extract read_bitmap() function
The pack-bitmap machinery uses the `read_bitmap_1()` function to read a bitmap from within the mmap'd region corresponding to the .bitmap file. As as side-effect of calling this function, `read_bitmap_1()` increments the `index->map_pos` variable to reflect the number of bytes read. Extract the core of this routine to a separate function (that operates over a `const unsigned char *`, a `size_t` and a `size_t *` pointer) instead of a `struct bitmap_index *` pointer. This function (called `read_bitmap()`) is part of the pack-bitmap.h API so that it can be used within the upcoming portion of the implementation in pseduo-merge.ch. Rewrite the existing function, `read_bitmap_1()`, in terms of its more generic counterpart. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53ea3ec commit 79621f3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pack-bitmap.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,34 @@ static struct ewah_bitmap *lookup_stored_bitmap(struct stored_bitmap *st)
129129
return composed;
130130
}
131131

132-
/*
133-
* Read a bitmap from the current read position on the mmaped
134-
* index, and increase the read position accordingly
135-
*/
136-
static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
132+
struct ewah_bitmap *read_bitmap(const unsigned char *map,
133+
size_t map_size, size_t *map_pos)
137134
{
138135
struct ewah_bitmap *b = ewah_pool_new();
139136

140-
ssize_t bitmap_size = ewah_read_mmap(b,
141-
index->map + index->map_pos,
142-
index->map_size - index->map_pos);
137+
ssize_t bitmap_size = ewah_read_mmap(b, map + *map_pos,
138+
map_size - *map_pos);
143139

144140
if (bitmap_size < 0) {
145141
error(_("failed to load bitmap index (corrupted?)"));
146142
ewah_pool_free(b);
147143
return NULL;
148144
}
149145

150-
index->map_pos += bitmap_size;
146+
*map_pos += bitmap_size;
147+
151148
return b;
152149
}
153150

151+
/*
152+
* Read a bitmap from the current read position on the mmaped
153+
* index, and increase the read position accordingly
154+
*/
155+
static struct ewah_bitmap *read_bitmap_1(struct bitmap_index *index)
156+
{
157+
return read_bitmap(index->map, index->map_size, &index->map_pos);
158+
}
159+
154160
static uint32_t bitmap_num_objects(struct bitmap_index *index)
155161
{
156162
if (index->midx)

pack-bitmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,6 @@ int bitmap_is_preferred_refname(struct repository *r, const char *refname);
160160

161161
int verify_bitmap_files(struct repository *r);
162162

163+
struct ewah_bitmap *read_bitmap(const unsigned char *map,
164+
size_t map_size, size_t *map_pos);
163165
#endif

0 commit comments

Comments
 (0)