Skip to content

Commit c256631

Browse files
committed
Merge branch 'tb/pack-bitmap'
Various improvements to the codepath that writes out pack bitmaps. * tb/pack-bitmap: (24 commits) pack-bitmap-write: better reuse bitmaps pack-bitmap-write: relax unique revwalk condition pack-bitmap-write: use existing bitmaps pack-bitmap: factor out 'add_commit_to_bitmap()' pack-bitmap: factor out 'bitmap_for_commit()' pack-bitmap-write: ignore BITMAP_FLAG_REUSE pack-bitmap-write: build fewer intermediate bitmaps pack-bitmap.c: check reads more aggressively when loading pack-bitmap-write: rename children to reverse_edges t5310: add branch-based checks commit: implement commit_list_contains() bitmap: implement bitmap_is_subset() pack-bitmap-write: fill bitmap with commit history pack-bitmap-write: pass ownership of intermediate bitmaps pack-bitmap-write: reimplement bitmap writing ewah: add bitmap_dup() function ewah: implement bitmap_or() ewah: make bitmap growth less aggressive ewah: factor out bitmap growth rev-list: die when --test-bitmap detects a mismatch ...
2 parents b62bbd3 + f077b0a commit c256631

File tree

10 files changed

+578
-296
lines changed

10 files changed

+578
-296
lines changed

builtin/pack-objects.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,6 @@ static void write_pack_file(void)
11041104
stop_progress(&progress_state);
11051105

11061106
bitmap_writer_show_progress(progress);
1107-
bitmap_writer_reuse_bitmaps(&to_pack);
11081107
bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
11091108
bitmap_writer_build(&to_pack);
11101109
bitmap_writer_finish(written_list, nr_written,

commit.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
544544
return new_list;
545545
}
546546

547+
int commit_list_contains(struct commit *item, struct commit_list *list)
548+
{
549+
while (list) {
550+
if (list->item == item)
551+
return 1;
552+
list = list->next;
553+
}
554+
555+
return 0;
556+
}
557+
547558
unsigned commit_list_count(const struct commit_list *l)
548559
{
549560
unsigned c = 0;

commit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
167167

168168
struct commit_list *commit_list_insert(struct commit *item,
169169
struct commit_list **list);
170+
int commit_list_contains(struct commit *item,
171+
struct commit_list *list);
170172
struct commit_list **commit_list_append(struct commit *commit,
171173
struct commit_list **next);
172174
unsigned commit_list_count(const struct commit_list *l);

ewah/bitmap.c

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,26 @@ struct bitmap *bitmap_new(void)
3535
return bitmap_word_alloc(32);
3636
}
3737

38+
struct bitmap *bitmap_dup(const struct bitmap *src)
39+
{
40+
struct bitmap *dst = bitmap_word_alloc(src->word_alloc);
41+
COPY_ARRAY(dst->words, src->words, src->word_alloc);
42+
return dst;
43+
}
44+
45+
static void bitmap_grow(struct bitmap *self, size_t word_alloc)
46+
{
47+
size_t old_size = self->word_alloc;
48+
ALLOC_GROW(self->words, word_alloc, self->word_alloc);
49+
memset(self->words + old_size, 0x0,
50+
(self->word_alloc - old_size) * sizeof(eword_t));
51+
}
52+
3853
void bitmap_set(struct bitmap *self, size_t pos)
3954
{
4055
size_t block = EWAH_BLOCK(pos);
4156

42-
if (block >= self->word_alloc) {
43-
size_t old_size = self->word_alloc;
44-
self->word_alloc = block ? block * 2 : 1;
45-
REALLOC_ARRAY(self->words, self->word_alloc);
46-
memset(self->words + old_size, 0x0,
47-
(self->word_alloc - old_size) * sizeof(eword_t));
48-
}
49-
57+
bitmap_grow(self, block + 1);
5058
self->words[block] |= EWAH_MASK(pos);
5159
}
5260

@@ -121,6 +129,15 @@ void bitmap_and_not(struct bitmap *self, struct bitmap *other)
121129
self->words[i] &= ~other->words[i];
122130
}
123131

132+
void bitmap_or(struct bitmap *self, const struct bitmap *other)
133+
{
134+
size_t i;
135+
136+
bitmap_grow(self, other->word_alloc);
137+
for (i = 0; i < other->word_alloc; i++)
138+
self->words[i] |= other->words[i];
139+
}
140+
124141
void bitmap_or_ewah(struct bitmap *self, struct ewah_bitmap *other)
125142
{
126143
size_t original_size = self->word_alloc;
@@ -178,6 +195,27 @@ int bitmap_equals(struct bitmap *self, struct bitmap *other)
178195
return 1;
179196
}
180197

198+
int bitmap_is_subset(struct bitmap *self, struct bitmap *other)
199+
{
200+
size_t common_size, i;
201+
202+
if (self->word_alloc < other->word_alloc)
203+
common_size = self->word_alloc;
204+
else {
205+
common_size = other->word_alloc;
206+
for (i = common_size; i < self->word_alloc; i++) {
207+
if (self->words[i])
208+
return 1;
209+
}
210+
}
211+
212+
for (i = 0; i < common_size; i++) {
213+
if (self->words[i] & ~other->words[i])
214+
return 1;
215+
}
216+
return 0;
217+
}
218+
181219
void bitmap_reset(struct bitmap *bitmap)
182220
{
183221
memset(bitmap->words, 0x0, bitmap->word_alloc * sizeof(eword_t));

ewah/ewah_bitmap.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "git-compat-util.h"
2020
#include "ewok.h"
2121
#include "ewok_rlw.h"
22+
#include "cache.h"
2223

2324
static inline size_t min_size(size_t a, size_t b)
2425
{
@@ -33,20 +34,13 @@ static inline size_t max_size(size_t a, size_t b)
3334
static inline void buffer_grow(struct ewah_bitmap *self, size_t new_size)
3435
{
3536
size_t rlw_offset = (uint8_t *)self->rlw - (uint8_t *)self->buffer;
36-
37-
if (self->alloc_size >= new_size)
38-
return;
39-
40-
self->alloc_size = new_size;
41-
REALLOC_ARRAY(self->buffer, self->alloc_size);
37+
ALLOC_GROW(self->buffer, new_size, self->alloc_size);
4238
self->rlw = self->buffer + (rlw_offset / sizeof(eword_t));
4339
}
4440

4541
static inline void buffer_push(struct ewah_bitmap *self, eword_t value)
4642
{
47-
if (self->buffer_size + 1 >= self->alloc_size)
48-
buffer_grow(self, self->buffer_size * 3 / 2);
49-
43+
buffer_grow(self, self->buffer_size + 1);
5044
self->buffer[self->buffer_size++] = value;
5145
}
5246

@@ -137,8 +131,7 @@ void ewah_add_dirty_words(
137131

138132
rlw_set_literal_words(self->rlw, literals + can_add);
139133

140-
if (self->buffer_size + can_add >= self->alloc_size)
141-
buffer_grow(self, (self->buffer_size + can_add) * 3 / 2);
134+
buffer_grow(self, self->buffer_size + can_add);
142135

143136
if (negate) {
144137
size_t i;

ewah/ewok.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ struct bitmap {
173173

174174
struct bitmap *bitmap_new(void);
175175
struct bitmap *bitmap_word_alloc(size_t word_alloc);
176+
struct bitmap *bitmap_dup(const struct bitmap *src);
176177
void bitmap_set(struct bitmap *self, size_t pos);
177178
void bitmap_unset(struct bitmap *self, size_t pos);
178179
int bitmap_get(struct bitmap *self, size_t pos);
179180
void bitmap_reset(struct bitmap *self);
180181
void bitmap_free(struct bitmap *self);
181182
int bitmap_equals(struct bitmap *self, struct bitmap *other);
182-
int bitmap_is_subset(struct bitmap *self, struct bitmap *super);
183+
int bitmap_is_subset(struct bitmap *self, struct bitmap *other);
183184

184185
struct ewah_bitmap * bitmap_to_ewah(struct bitmap *bitmap);
185186
struct bitmap *ewah_to_bitmap(struct ewah_bitmap *ewah);

0 commit comments

Comments
 (0)