/** * Build the initial type index for the packfile */ void bitmap_writer_build_type_index(struct packing_data *to_pack, struct pack_idx_entry **index, uint32_t index_nr) { uint32_t i; writer.commits = ewah_new(); writer.trees = ewah_new(); writer.blobs = ewah_new(); writer.tags = ewah_new(); ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects); for (i = 0; i < index_nr; ++i) { struct object_entry *entry = (struct object_entry *)index[i]; enum object_type real_type; oe_set_in_pack_pos(to_pack, entry, i); switch (oe_type(entry)) { case OBJ_COMMIT: case OBJ_TREE: case OBJ_BLOB: case OBJ_TAG: real_type = oe_type(entry); break; default: real_type = oid_object_info(to_pack->repo, &entry->idx.oid, NULL); break; } switch (real_type) { case OBJ_COMMIT: ewah_set(writer.commits, i); break; case OBJ_TREE: ewah_set(writer.trees, i); break; case OBJ_BLOB: ewah_set(writer.blobs, i); break; case OBJ_TAG: ewah_set(writer.tags, i); break; default: die("Missing type information for %s (%d/%d)", oid_to_hex(&entry->idx.oid), real_type, oe_type(entry)); } } }
/** * Build the initial type index for the packfile */ void bitmap_writer_build_type_index(struct pack_idx_entry **index, uint32_t index_nr) { uint32_t i; writer.commits = ewah_new(); writer.trees = ewah_new(); writer.blobs = ewah_new(); writer.tags = ewah_new(); for (i = 0; i < index_nr; ++i) { struct object_entry *entry = (struct object_entry *)index[i]; enum object_type real_type; entry->in_pack_pos = i; switch (entry->type) { case OBJ_COMMIT: case OBJ_TREE: case OBJ_BLOB: case OBJ_TAG: real_type = entry->type; break; default: real_type = sha1_object_info(entry->idx.sha1, NULL); break; } switch (real_type) { case OBJ_COMMIT: ewah_set(writer.commits, i); break; case OBJ_TREE: ewah_set(writer.trees, i); break; case OBJ_BLOB: ewah_set(writer.blobs, i); break; case OBJ_TAG: ewah_set(writer.tags, i); break; default: die("Missing type information for %s (%d/%d)", sha1_to_hex(entry->idx.sha1), real_type, entry->type); } } }
int read_fsmonitor_extension(struct index_state *istate, const void *data, unsigned long sz) { const char *index = data; uint32_t hdr_version; uint32_t ewah_size; struct ewah_bitmap *fsmonitor_dirty; int ret; if (sz < sizeof(uint32_t) + sizeof(uint64_t) + sizeof(uint32_t)) return error("corrupt fsmonitor extension (too short)"); hdr_version = get_be32(index); index += sizeof(uint32_t); if (hdr_version != INDEX_EXTENSION_VERSION) return error("bad fsmonitor version %d", hdr_version); istate->fsmonitor_last_update = get_be64(index); index += sizeof(uint64_t); ewah_size = get_be32(index); index += sizeof(uint32_t); fsmonitor_dirty = ewah_new(); ret = ewah_read_mmap(fsmonitor_dirty, index, ewah_size); if (ret != ewah_size) { ewah_free(fsmonitor_dirty); return error("failed to parse ewah bitmap reading fsmonitor index extension"); } istate->fsmonitor_dirty = fsmonitor_dirty; trace_printf_key(&trace_fsmonitor, "read fsmonitor extension successful"); return 0; }
struct ewah_bitmap *bitmap_compress(struct bitmap *bitmap) { struct ewah_bitmap *ewah = ewah_new(); size_t i, running_empty_words = 0; eword_t last_word = 0; for (i = 0; i < bitmap->word_alloc; ++i) { if (bitmap->words[i] == 0) { running_empty_words++; continue; } if (last_word != 0) { ewah_add(ewah, last_word); } if (running_empty_words > 0) { ewah_add_empty_words(ewah, false, running_empty_words); running_empty_words = 0; } last_word = bitmap->words[i]; } ewah_add(ewah, last_word); return ewah; }
struct ewah_bitmap *ewah_pool_new(void) { if (bitmap_pool_size) return bitmap_pool[--bitmap_pool_size]; return ewah_new(); }
static void test_for_size(size_t size) { struct ewah_bitmap *a = generate_bitmap(size); struct ewah_bitmap *b = generate_bitmap(size); struct ewah_bitmap *result = ewah_new(); size_t i; struct { const char *name; void (*generate)(struct ewah_bitmap *, struct ewah_bitmap *, struct ewah_bitmap *); size_t (*check)(size_t, size_t); } tests[] = { {"or", &ewah_or, &op_or}, {"xor", &ewah_xor, &op_xor}, {"and", &ewah_and, &op_and}, {"and-not", &ewah_and_not, &op_andnot} }; for (i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) { fprintf(stderr, "'%s' in %zu bits... ", tests[i].name, size); tests[i].generate(a, b, result); if (verify_operation(a, b, result, tests[i].check)) fprintf(stderr, "OK\n"); ewah_clear(result); } ewah_free(a); ewah_free(b); ewah_free(result); }
void fill_fsmonitor_bitmap(struct index_state *istate) { int i; istate->fsmonitor_dirty = ewah_new(); for (i = 0; i < istate->cache_nr; i++) if (!(istate->cache[i]->ce_flags & CE_FSMONITOR_VALID)) ewah_set(istate->fsmonitor_dirty, i); }
static struct ewah_bitmap *generate_bitmap(size_t max_size) { static const size_t BIT_CHANCE = 50; struct ewah_bitmap *bitmap = ewah_new(); size_t i; for (i = 0; i < max_size; ++i) { if (rand() % 100 <= BIT_CHANCE) ewah_set(bitmap, i); } return bitmap; }