From: Junio C Hamano Date: Fri, 12 Dec 2014 22:31:41 +0000 (-0800) Subject: Merge branch 'jk/pack-bitmap' X-Git-Tag: v2.3.0-rc0~81 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3889e7a60c65031f0c5381d8060cefb4294d932e?ds=inline;hp=-c Merge branch 'jk/pack-bitmap' * jk/pack-bitmap: pack-bitmap: do not use gcc packed attribute --- 3889e7a60c65031f0c5381d8060cefb4294d932e diff --combined csum-file.h index bb543d52f1,da612c59c1..7530927d77 --- a/csum-file.h +++ b/csum-file.h @@@ -34,9 -34,20 +34,20 @@@ extern struct sha1file *sha1fd(int fd, extern struct sha1file *sha1fd_check(const char *name); extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp); extern int sha1close(struct sha1file *, unsigned char *, unsigned int); -extern int sha1write(struct sha1file *, const void *, unsigned int); +extern void sha1write(struct sha1file *, const void *, unsigned int); extern void sha1flush(struct sha1file *f); extern void crc32_begin(struct sha1file *); extern uint32_t crc32_end(struct sha1file *); + static inline void sha1write_u8(struct sha1file *f, uint8_t data) + { + sha1write(f, &data, sizeof(data)); + } + + static inline void sha1write_be32(struct sha1file *f, uint32_t data) + { + data = htonl(data); + sha1write(f, &data, sizeof(data)); + } + #endif diff --combined pack-bitmap-write.c index 8029ae3561,5d353ad6a7..c05d1386af --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@@ -111,7 -111,8 +111,7 @@@ static inline void push_bitmapped_commi { if (writer.selected_nr >= writer.selected_alloc) { writer.selected_alloc = (writer.selected_alloc + 32) * 2; - writer.selected = xrealloc(writer.selected, - writer.selected_alloc * sizeof(struct bitmapped_commit)); + REALLOC_ARRAY(writer.selected, writer.selected_alloc); } writer.selected[writer.selected_nr].commit = commit; @@@ -472,7 -473,6 +472,6 @@@ static void write_selected_commits_v1(s for (i = 0; i < writer.selected_nr; ++i) { struct bitmapped_commit *stored = &writer.selected[i]; - struct bitmap_disk_entry on_disk; int commit_pos = sha1_pos(stored->commit->object.sha1, index, index_nr, sha1_access); @@@ -480,11 -480,10 +479,10 @@@ if (commit_pos < 0) die("BUG: trying to write commit not in index"); - on_disk.object_pos = htonl(commit_pos); - on_disk.xor_offset = stored->xor_offset; - on_disk.flags = stored->flags; + sha1write_be32(f, commit_pos); + sha1write_u8(f, stored->xor_offset); + sha1write_u8(f, stored->flags); - sha1write(f, &on_disk, sizeof(on_disk)); dump_bitmap(f, stored->write_as); } } @@@ -529,7 -528,7 +527,7 @@@ void bitmap_writer_finish(struct pack_i header.version = htons(default_version); header.options = htons(flags | options); header.entry_count = htonl(writer.selected_nr); - memcpy(header.checksum, writer.pack_checksum, 20); + hashcpy(header.checksum, writer.pack_checksum); sha1write(f, &header, sizeof(header)); dump_bitmap(f, writer.commits); diff --combined pack-bitmap.c index a1f3c0d34f,9f8b909811..6a818419ca --- a/pack-bitmap.c +++ b/pack-bitmap.c @@@ -197,13 -197,24 +197,24 @@@ static struct stored_bitmap *store_bitm return stored; } + static inline uint32_t read_be32(const unsigned char *buffer, size_t *pos) + { + uint32_t result = get_be32(buffer + *pos); + (*pos) += sizeof(result); + return result; + } + + static inline uint8_t read_u8(const unsigned char *buffer, size_t *pos) + { + return buffer[(*pos)++]; + } + static int load_bitmap_entries_v1(struct bitmap_index *index) { static const size_t MAX_XOR_OFFSET = 160; uint32_t i; struct stored_bitmap **recent_bitmaps; - struct bitmap_disk_entry *entry; recent_bitmaps = xcalloc(MAX_XOR_OFFSET, sizeof(struct stored_bitmap)); @@@ -214,15 -225,12 +225,12 @@@ uint32_t commit_idx_pos; const unsigned char *sha1; - entry = (struct bitmap_disk_entry *)(index->map + index->map_pos); - index->map_pos += sizeof(struct bitmap_disk_entry); + 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); - commit_idx_pos = ntohl(entry->object_pos); sha1 = nth_packed_object_sha1(index->pack, commit_idx_pos); - xor_offset = (int)entry->xor_offset; - flags = (int)entry->flags; - bitmap = read_bitmap_1(index); if (!bitmap) return -1; @@@ -400,8 -408,10 +408,8 @@@ static int ext_index_add_object(struct if (hash_ret > 0) { if (eindex->count >= eindex->alloc) { eindex->alloc = (eindex->alloc + 16) * 3 / 2; - eindex->objects = xrealloc(eindex->objects, - eindex->alloc * sizeof(struct object *)); - eindex->hashes = xrealloc(eindex->hashes, - eindex->alloc * sizeof(uint32_t)); + REALLOC_ARRAY(eindex->objects, eindex->alloc); + REALLOC_ARRAY(eindex->hashes, eindex->alloc); } bitmap_pos = eindex->count;