summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2023-03-20 16:02:40 -0400
committerJunio C Hamano <gitster@pobox.com>2023-03-20 14:40:13 -0700
commitf8762b1cefcdd8b027d1f89b0c37f9abe27b91c0 (patch)
treecb2c180235841d217d1ff0d82e57467aa84ca52b
parent73876f4861cd3d187a4682290ab75c9dccadbc56 (diff)
downloadgit-f8762b1cefcdd8b027d1f89b0c37f9abe27b91c0.tar.gz
pack-bitmap.c: hide bitmap internals in `read_u8()`
The `read_u8()` helper function internal to pack-bitmap.c was defined in b5007211b6 (pack-bitmap: do not use gcc packed attribute, 2014-11-27). Prior to b5007211b6, callers within pack-bitmap.c would read an individual unsigned integer by doing something like: struct bitmap_disk_entry *e; e = (struct bitmap_disk_entry *)(index->map + index->map_pos); index->map_pos += sizeof(*e); ...which relied on the fact that the `bitmap_disk_entry` struct was defined with `__attribute((packed))`, which b5007211b6 sought to get rid of since the `__attribute__` flag is a noop on some compilers (which makes the above code rely on the absence of padding to be correct). So b5007211b6 got rid of the above convention and replaced it by reading individual fields of that structure with a `read_u8()` helper that reads from the region of memory pointed to by `->map`, and updates the `->map_pos` pointer accordingly. But this forces callers to be intimately aware of `bitmap_git->map` and `bitmap_git->map_pos`. Instead, teach `read_u8()` to take a `struct bitmap_index *` directly, and avoid having callers deal with the internals themselves. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--pack-bitmap.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c
index d2a42abf28..afb3812fb6 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -249,9 +249,9 @@ static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos)
return result;
}
-static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos)
+static inline uint8_t read_u8(struct bitmap_index *bitmap_git)
{
- return buffer[(*pos)++];
+ return bitmap_git->map[bitmap_git->map_pos++];
}
#define MAX_XOR_OFFSET 160
@@ -281,8 +281,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
return error(_("corrupt ewah bitmap: truncated header for entry %d"), i);
commit_idx_pos = read_be32(index->map, &index->map_pos);
- xor_offset = read_u8(index->map, &index->map_pos);
- flags = read_u8(index->map, &index->map_pos);
+ xor_offset = read_u8(index);
+ flags = read_u8(index);
if (nth_bitmap_object_oid(index, &oid, commit_idx_pos) < 0)
return error(_("corrupt ewah bitmap: commit index %u out of range"),
@@ -778,7 +778,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
}
bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t);
- xor_flags = read_u8(bitmap_git->map, &bitmap_git->map_pos);
+ xor_flags = read_u8(bitmap_git);
bitmap = read_bitmap_1(bitmap_git);
if (!bitmap)
@@ -819,7 +819,7 @@ static struct stored_bitmap *lazy_bitmap_for_commit(struct bitmap_index *bitmap_
* ewah bitmap.
*/
bitmap_git->map_pos += sizeof(uint32_t) + sizeof(uint8_t);
- flags = read_u8(bitmap_git->map, &bitmap_git->map_pos);
+ flags = read_u8(bitmap_git);
bitmap = read_bitmap_1(bitmap_git);
if (!bitmap)