Skip to content

Commit 3889e7a

Browse files
committed
Merge branch 'jk/pack-bitmap'
* jk/pack-bitmap: pack-bitmap: do not use gcc packed attribute
2 parents 23c0956 + b500721 commit 3889e7a

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

csum-file.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ extern void sha1flush(struct sha1file *f);
3939
extern void crc32_begin(struct sha1file *);
4040
extern uint32_t crc32_end(struct sha1file *);
4141

42+
static inline void sha1write_u8(struct sha1file *f, uint8_t data)
43+
{
44+
sha1write(f, &data, sizeof(data));
45+
}
46+
47+
static inline void sha1write_be32(struct sha1file *f, uint32_t data)
48+
{
49+
data = htonl(data);
50+
sha1write(f, &data, sizeof(data));
51+
}
52+
4253
#endif

pack-bitmap-write.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,17 @@ static void write_selected_commits_v1(struct sha1file *f,
472472

473473
for (i = 0; i < writer.selected_nr; ++i) {
474474
struct bitmapped_commit *stored = &writer.selected[i];
475-
struct bitmap_disk_entry on_disk;
476475

477476
int commit_pos =
478477
sha1_pos(stored->commit->object.sha1, index, index_nr, sha1_access);
479478

480479
if (commit_pos < 0)
481480
die("BUG: trying to write commit not in index");
482481

483-
on_disk.object_pos = htonl(commit_pos);
484-
on_disk.xor_offset = stored->xor_offset;
485-
on_disk.flags = stored->flags;
482+
sha1write_be32(f, commit_pos);
483+
sha1write_u8(f, stored->xor_offset);
484+
sha1write_u8(f, stored->flags);
486485

487-
sha1write(f, &on_disk, sizeof(on_disk));
488486
dump_bitmap(f, stored->write_as);
489487
}
490488
}

pack-bitmap.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,24 @@ static struct stored_bitmap *store_bitmap(struct bitmap_index *index,
197197
return stored;
198198
}
199199

200+
static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos)
201+
{
202+
uint32_t result = get_be32(buffer + *pos);
203+
(*pos) += sizeof(result);
204+
return result;
205+
}
206+
207+
static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos)
208+
{
209+
return buffer[(*pos)++];
210+
}
211+
200212
static int load_bitmap_entries_v1(struct bitmap_index *index)
201213
{
202214
static const size_t MAX_XOR_OFFSET = 160;
203215

204216
uint32_t i;
205217
struct stored_bitmap **recent_bitmaps;
206-
struct bitmap_disk_entry *entry;
207218

208219
recent_bitmaps = xcalloc(MAX_XOR_OFFSET, sizeof(struct stored_bitmap));
209220

@@ -214,15 +225,12 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
214225
uint32_t commit_idx_pos;
215226
const unsigned char *sha1;
216227

217-
entry = (struct bitmap_disk_entry *)(index->map + index->map_pos);
218-
index->map_pos += sizeof(struct bitmap_disk_entry);
228+
commit_idx_pos = read_be32(index->map, &index->map_pos);
229+
xor_offset = read_u8(index->map, &index->map_pos);
230+
flags = read_u8(index->map, &index->map_pos);
219231

220-
commit_idx_pos = ntohl(entry->object_pos);
221232
sha1 = nth_packed_object_sha1(index->pack, commit_idx_pos);
222233

223-
xor_offset = (int)entry->xor_offset;
224-
flags = (int)entry->flags;
225-
226234
bitmap = read_bitmap_1(index);
227235
if (!bitmap)
228236
return -1;

pack-bitmap.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
#include "khash.h"
66
#include "pack-objects.h"
77

8-
struct bitmap_disk_entry {
9-
uint32_t object_pos;
10-
uint8_t xor_offset;
11-
uint8_t flags;
12-
} __attribute__((packed));
13-
148
struct bitmap_disk_header {
159
char magic[4];
1610
uint16_t version;

0 commit comments

Comments
 (0)