diff options
Diffstat (limited to 'pack-bitmap.c')
-rw-r--r-- | pack-bitmap.c | 109 |
1 files changed, 47 insertions, 62 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c index 2b3ff23797..3f2dab340f 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -9,6 +9,9 @@ #include "pack-bitmap.h" #include "pack-revindex.h" #include "pack-objects.h" +#include "packfile.h" +#include "repository.h" +#include "object-store.h" /* * An entry on the bitmap index, representing the bitmap for a given @@ -33,9 +36,6 @@ static struct bitmap_index { /* Packfile to which this bitmap index belongs to */ struct packed_git *pack; - /* reverse index for the packfile */ - struct pack_revindex *reverse_index; - /* * Mark the first `reuse_objects` in the packfile as reused: * they will be sent as-is without using them for repacking @@ -252,16 +252,11 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) static char *pack_bitmap_filename(struct packed_git *p) { - char *idx_name; - int len; - - len = strlen(p->pack_name) - strlen(".pack"); - idx_name = xmalloc(len + strlen(".bitmap") + 1); + size_t len; - memcpy(idx_name, p->pack_name, len); - memcpy(idx_name + len, ".bitmap", strlen(".bitmap") + 1); - - return idx_name; + if (!strip_suffix(p->pack_name, ".pack", &len)) + die("BUG: pack_name does not end in .pack"); + return xstrfmt("%.*s.bitmap", (int)len, p->pack_name); } static int open_pack_bitmap_1(struct packed_git *packfile) @@ -274,7 +269,7 @@ static int open_pack_bitmap_1(struct packed_git *packfile) return -1; idx_name = pack_bitmap_filename(packfile); - fd = git_open_noatime(idx_name); + fd = git_open(idx_name); free(idx_name); if (fd < 0) @@ -313,7 +308,7 @@ static int load_pack_bitmap(void) bitmap_git.bitmaps = kh_init_sha1(); bitmap_git.ext_index.positions = kh_init_sha1_pos(); - bitmap_git.reverse_index = revindex_for_pack(bitmap_git.pack); + load_pack_revindex(bitmap_git.pack); if (!(bitmap_git.commits = read_bitmap_1(&bitmap_git)) || !(bitmap_git.trees = read_bitmap_1(&bitmap_git)) || @@ -341,8 +336,7 @@ static int open_pack_bitmap(void) assert(!bitmap_git.map && !bitmap_git.loaded); - prepare_packed_git(); - for (p = packed_git; p; p = p->next) { + for (p = get_packed_git(the_repository); p; p = p->next) { if (open_pack_bitmap_1(p) == 0) ret = 0; } @@ -385,7 +379,7 @@ static inline int bitmap_position_packfile(const unsigned char *sha1) if (!offset) return -1; - return find_revindex_position(bitmap_git.reverse_index, offset); + return find_revindex_position(bitmap_git.pack, offset); } static int bitmap_position(const unsigned char *sha1) @@ -402,7 +396,7 @@ static int ext_index_add_object(struct object *object, const char *name) int hash_ret; int bitmap_pos; - hash_pos = kh_put_sha1_pos(eindex->positions, object->sha1, &hash_ret); + hash_pos = kh_put_sha1_pos(eindex->positions, object->oid.hash, &hash_ret); if (hash_ret > 0) { if (eindex->count >= eindex->alloc) { eindex->alloc = (eindex->alloc + 16) * 3 / 2; @@ -422,19 +416,15 @@ static int ext_index_add_object(struct object *object, const char *name) return bitmap_pos + bitmap_git.pack->num_objects; } -static void show_object(struct object *object, const struct name_path *path, - const char *last, void *data) +static void show_object(struct object *object, const char *name, void *data) { struct bitmap *base = data; int bitmap_pos; - bitmap_pos = bitmap_position(object->sha1); + bitmap_pos = bitmap_position(object->oid.hash); - if (bitmap_pos < 0) { - char *name = path_name(path, last); + if (bitmap_pos < 0) bitmap_pos = ext_index_add_object(object, name); - free(name); - } bitmap_set(base, bitmap_pos); } @@ -471,11 +461,11 @@ static int should_include(struct commit *commit, void *_data) struct include_data *data = _data; int bitmap_pos; - bitmap_pos = bitmap_position(commit->object.sha1); + bitmap_pos = bitmap_position(commit->object.oid.hash); if (bitmap_pos < 0) bitmap_pos = ext_index_add_object((struct object *)commit, NULL); - if (!add_to_include_set(data, commit->object.sha1, bitmap_pos)) { + if (!add_to_include_set(data, commit->object.oid.hash, bitmap_pos)) { struct commit_list *parent = commit->parents; while (parent) { @@ -511,7 +501,7 @@ static struct bitmap *find_objects(struct rev_info *revs, roots = roots->next; if (object->type == OBJ_COMMIT) { - khiter_t pos = kh_get_sha1(bitmap_git.bitmaps, object->sha1); + khiter_t pos = kh_get_sha1(bitmap_git.bitmaps, object->oid.hash); if (pos < kh_end(bitmap_git.bitmaps)) { struct stored_bitmap *st = kh_value(bitmap_git.bitmaps, pos); @@ -553,7 +543,7 @@ static struct bitmap *find_objects(struct rev_info *revs, int pos; roots = roots->next; - pos = bitmap_position(object->sha1); + pos = bitmap_position(object->oid.hash); if (pos < 0 || base == NULL || !bitmap_get(base, pos)) { object->flags &= ~UNINTERESTING; @@ -598,7 +588,7 @@ static void show_extended_objects(struct bitmap *objects, continue; obj = eindex->objects[i]; - show_reach(obj->sha1, obj->type, 0, eindex->hashes[i], NULL, 0); + show_reach(&obj->oid, obj->type, 0, eindex->hashes[i], NULL, 0); } } @@ -622,8 +612,8 @@ static void show_objects_for_type( while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) { eword_t word = objects->words[i] & filter; - for (offset = 0; offset < BITS_IN_WORD; ++offset) { - const unsigned char *sha1; + for (offset = 0; offset < BITS_IN_EWORD; ++offset) { + struct object_id oid; struct revindex_entry *entry; uint32_t hash = 0; @@ -635,16 +625,16 @@ static void show_objects_for_type( if (pos + offset < bitmap_git.reuse_objects) continue; - entry = &bitmap_git.reverse_index->revindex[pos + offset]; - sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr); + entry = &bitmap_git.pack->revindex[pos + offset]; + nth_packed_object_oid(&oid, bitmap_git.pack, entry->nr); if (bitmap_git.hashes) - hash = ntohl(bitmap_git.hashes[entry->nr]); + hash = get_be32(bitmap_git.hashes + entry->nr); - show_reach(sha1, object_type, 0, hash, bitmap_git.pack, entry->offset); + show_reach(&oid, object_type, 0, hash, bitmap_git.pack, entry->offset); } - pos += BITS_IN_WORD; + pos += BITS_IN_EWORD; i++; } } @@ -655,7 +645,7 @@ static int in_bitmapped_pack(struct object_list *roots) struct object *object = roots->item; roots = roots->next; - if (find_pack_entry_one(object->sha1, bitmap_git.pack) > 0) + if (find_pack_entry_one(object->oid.hash, bitmap_git.pack) > 0) return 1; } @@ -665,8 +655,6 @@ static int in_bitmapped_pack(struct object_list *roots) int prepare_bitmap_walk(struct rev_info *revs) { unsigned int i; - unsigned int pending_nr = revs->pending.nr; - struct object_array_entry *pending_e = revs->pending.objects; struct object_list *wants = NULL; struct object_list *haves = NULL; @@ -681,11 +669,11 @@ int prepare_bitmap_walk(struct rev_info *revs) return -1; } - for (i = 0; i < pending_nr; ++i) { - struct object *object = pending_e[i].item; + for (i = 0; i < revs->pending.nr; ++i) { + struct object *object = revs->pending.objects[i].item; if (object->type == OBJ_NONE) - parse_object_or_die(object->sha1, NULL); + parse_object_or_die(&object->oid, NULL); while (object->type == OBJ_TAG) { struct tag *tag = (struct tag *) object; @@ -697,7 +685,7 @@ int prepare_bitmap_walk(struct rev_info *revs) if (!tag->tagged) die("bad tag"); - object = parse_object_or_die(tag->tagged->sha1, NULL); + object = parse_object_or_die(&tag->tagged->oid, NULL); } if (object->flags & UNINTERESTING) @@ -726,9 +714,7 @@ int prepare_bitmap_walk(struct rev_info *revs) if (!bitmap_git.loaded && load_pack_bitmap() < 0) return -1; - revs->pending.nr = 0; - revs->pending.alloc = 0; - revs->pending.objects = NULL; + object_array_clear(&revs->pending); if (haves) { revs->ignore_missing_links = 1; @@ -776,7 +762,7 @@ int reuse_partial_packfile_from_bitmap(struct packed_git **packfile, break; } - reuse_objects += BITS_IN_WORD; + reuse_objects += BITS_IN_EWORD; } #ifdef GIT_BITMAP_DEBUG @@ -809,7 +795,7 @@ int reuse_partial_packfile_from_bitmap(struct packed_git **packfile, return -1; bitmap_git.reuse_objects = *entries = reuse_objects; - *up_to = bitmap_git.reverse_index->revindex[reuse_objects].offset; + *up_to = bitmap_git.pack->revindex[reuse_objects].offset; *packfile = bitmap_git.pack; return 0; @@ -902,16 +888,15 @@ struct bitmap_test_data { size_t seen; }; -static void test_show_object(struct object *object, - const struct name_path *path, - const char *last, void *data) +static void test_show_object(struct object *object, const char *name, + void *data) { struct bitmap_test_data *tdata = data; int bitmap_pos; - bitmap_pos = bitmap_position(object->sha1); + bitmap_pos = bitmap_position(object->oid.hash); if (bitmap_pos < 0) - die("Object not in bitmap: %s\n", sha1_to_hex(object->sha1)); + die("Object not in bitmap: %s\n", oid_to_hex(&object->oid)); bitmap_set(tdata->base, bitmap_pos); display_progress(tdata->prg, ++tdata->seen); @@ -922,9 +907,9 @@ static void test_show_commit(struct commit *commit, void *data) struct bitmap_test_data *tdata = data; int bitmap_pos; - bitmap_pos = bitmap_position(commit->object.sha1); + bitmap_pos = bitmap_position(commit->object.oid.hash); if (bitmap_pos < 0) - die("Object not in bitmap: %s\n", sha1_to_hex(commit->object.sha1)); + die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid)); bitmap_set(tdata->base, bitmap_pos); display_progress(tdata->prg, ++tdata->seen); @@ -948,20 +933,20 @@ void test_bitmap_walk(struct rev_info *revs) bitmap_git.version, bitmap_git.entry_count); root = revs->pending.objects[0].item; - pos = kh_get_sha1(bitmap_git.bitmaps, root->sha1); + pos = kh_get_sha1(bitmap_git.bitmaps, root->oid.hash); if (pos < kh_end(bitmap_git.bitmaps)) { struct stored_bitmap *st = kh_value(bitmap_git.bitmaps, pos); struct ewah_bitmap *bm = lookup_stored_bitmap(st); fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n", - sha1_to_hex(root->sha1), (int)bm->bit_size, ewah_checksum(bm)); + oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm)); result = ewah_to_bitmap(bm); } if (result == NULL) - die("Commit %s doesn't have an indexed bitmap", sha1_to_hex(root->sha1)); + die("Commit %s doesn't have an indexed bitmap", oid_to_hex(&root->oid)); revs->tag_objects = 1; revs->tree_objects = 1; @@ -1001,7 +986,7 @@ static int rebuild_bitmap(uint32_t *reposition, while (ewah_iterator_next(&word, &it)) { uint32_t offset, bit_pos; - for (offset = 0; offset < BITS_IN_WORD; ++offset) { + for (offset = 0; offset < BITS_IN_EWORD; ++offset) { if ((word >> offset) == 0) break; @@ -1014,7 +999,7 @@ static int rebuild_bitmap(uint32_t *reposition, return -1; } - pos += BITS_IN_WORD; + pos += BITS_IN_EWORD; } return 0; } @@ -1043,7 +1028,7 @@ int rebuild_existing_bitmaps(struct packing_data *mapping, struct revindex_entry *entry; struct object_entry *oe; - entry = &bitmap_git.reverse_index->revindex[i]; + entry = &bitmap_git.pack->revindex[i]; sha1 = nth_packed_object_sha1(bitmap_git.pack, entry->nr); oe = packlist_find(mapping, sha1, NULL); |