Merge branch 'jk/pack-bitmap'
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2014 22:31:41 +0000 (14:31 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Dec 2014 22:31:42 +0000 (14:31 -0800)
* jk/pack-bitmap:
pack-bitmap: do not use gcc packed attribute

1  2 
csum-file.h
pack-bitmap-write.c
pack-bitmap.c
diff --combined csum-file.h
index bb543d52f108cf1e976ee644e337f5ccec983790,da612c59c1bccab839e0a91aa0f37ed292ce59a0..7530927d774562f82636aa773481ae93600c1756
@@@ -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 8029ae35619fbff7e9e595b20ea25c379c698016,5d353ad6a7ebd3ee236f590f84fca5ec32acd6b2..c05d1386af7210e75a1012f3772745315ecc3592
@@@ -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);
                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 a1f3c0d34f8958c08310aa9fc77e764885b76008,9f8b9098113dc189217c3f133857cff34645173d..6a818419ca46f8d66adbeb0027da49e6bab1bfa3
@@@ -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));
  
                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;