Skip to content

Commit 4b1e5e5

Browse files
committed
Merge branch 'ds/bloom-cleanup'
Code cleanup and typofixes * ds/bloom-cleanup: completion: offer '--(no-)patch' among 'git log' options bloom: use num_changes not nr for limit detection bloom: de-duplicate directory entries Documentation: changed-path Bloom filters use byte words bloom: parse commit before computing filters test-bloom: fix usage typo bloom: fix whitespace around tab length
2 parents 0498840 + b928e48 commit 4b1e5e5

File tree

6 files changed

+49
-28
lines changed

6 files changed

+49
-28
lines changed

Documentation/technical/commit-graph-format.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ CHUNK DATA:
9797
bit on. The other bits correspond to the position of the last parent.
9898

9999
Bloom Filter Index (ID: {'B', 'I', 'D', 'X'}) (N * 4 bytes) [Optional]
100-
* The ith entry, BIDX[i], stores the number of 8-byte word blocks in all
101-
Bloom filters from commit 0 to commit i (inclusive) in lexicographic
102-
order. The Bloom filter for the i-th commit spans from BIDX[i-1] to
103-
BIDX[i] (plus header length), where BIDX[-1] is 0.
100+
* The ith entry, BIDX[i], stores the number of bytes in all Bloom filters
101+
from commit 0 to commit i (inclusive) in lexicographic order. The Bloom
102+
filter for the i-th commit spans from BIDX[i-1] to BIDX[i] (plus header
103+
length), where BIDX[-1] is 0.
104104
* The BIDX chunk is ignored if the BDAT chunk is not present.
105105

106106
Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional]

bloom.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static inline unsigned char get_bitmask(uint32_t pos)
2929
}
3030

3131
static int load_bloom_filter_from_graph(struct commit_graph *g,
32-
struct bloom_filter *filter,
33-
struct commit *c)
32+
struct bloom_filter *filter,
33+
struct commit *c)
3434
{
3535
uint32_t lex_pos, start_index, end_index;
3636

@@ -123,9 +123,9 @@ uint32_t murmur3_seeded(uint32_t seed, const char *data, size_t len)
123123
}
124124

125125
void fill_bloom_key(const char *data,
126-
size_t len,
127-
struct bloom_key *key,
128-
const struct bloom_filter_settings *settings)
126+
size_t len,
127+
struct bloom_key *key,
128+
const struct bloom_filter_settings *settings)
129129
{
130130
int i;
131131
const uint32_t seed0 = 0x293ae76f;
@@ -139,8 +139,8 @@ void fill_bloom_key(const char *data,
139139
}
140140

141141
void add_key_to_filter(const struct bloom_key *key,
142-
struct bloom_filter *filter,
143-
const struct bloom_filter_settings *settings)
142+
struct bloom_filter *filter,
143+
const struct bloom_filter_settings *settings)
144144
{
145145
int i;
146146
uint64_t mod = filter->len * BITS_PER_WORD;
@@ -158,9 +158,22 @@ void init_bloom_filters(void)
158158
init_bloom_filter_slab(&bloom_filters);
159159
}
160160

161+
static int pathmap_cmp(const void *hashmap_cmp_fn_data,
162+
const struct hashmap_entry *eptr,
163+
const struct hashmap_entry *entry_or_key,
164+
const void *keydata)
165+
{
166+
const struct pathmap_hash_entry *e1, *e2;
167+
168+
e1 = container_of(eptr, const struct pathmap_hash_entry, entry);
169+
e2 = container_of(entry_or_key, const struct pathmap_hash_entry, entry);
170+
171+
return strcmp(e1->path, e2->path);
172+
}
173+
161174
struct bloom_filter *get_bloom_filter(struct repository *r,
162175
struct commit *c,
163-
int compute_if_not_present)
176+
int compute_if_not_present)
164177
{
165178
struct bloom_filter *filter;
166179
struct bloom_filter_settings settings = DEFAULT_BLOOM_FILTER_SETTINGS;
@@ -193,35 +206,42 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
193206
diffopt.max_changes = max_changes;
194207
diff_setup_done(&diffopt);
195208

209+
/* ensure commit is parsed so we have parent information */
210+
repo_parse_commit(r, c);
211+
196212
if (c->parents)
197213
diff_tree_oid(&c->parents->item->object.oid, &c->object.oid, "", &diffopt);
198214
else
199215
diff_tree_oid(NULL, &c->object.oid, "", &diffopt);
200216
diffcore_std(&diffopt);
201217

202-
if (diff_queued_diff.nr <= max_changes) {
218+
if (diffopt.num_changes <= max_changes) {
203219
struct hashmap pathmap;
204220
struct pathmap_hash_entry *e;
205221
struct hashmap_iter iter;
206-
hashmap_init(&pathmap, NULL, NULL, 0);
222+
hashmap_init(&pathmap, pathmap_cmp, NULL, 0);
207223

208224
for (i = 0; i < diff_queued_diff.nr; i++) {
209225
const char *path = diff_queued_diff.queue[i]->two->path;
210226

211227
/*
212-
* Add each leading directory of the changed file, i.e. for
213-
* 'dir/subdir/file' add 'dir' and 'dir/subdir' as well, so
214-
* the Bloom filter could be used to speed up commands like
215-
* 'git log dir/subdir', too.
216-
*
217-
* Note that directories are added without the trailing '/'.
218-
*/
228+
* Add each leading directory of the changed file, i.e. for
229+
* 'dir/subdir/file' add 'dir' and 'dir/subdir' as well, so
230+
* the Bloom filter could be used to speed up commands like
231+
* 'git log dir/subdir', too.
232+
*
233+
* Note that directories are added without the trailing '/'.
234+
*/
219235
do {
220236
char *last_slash = strrchr(path, '/');
221237

222238
FLEX_ALLOC_STR(e, path, path);
223239
hashmap_entry_init(&e->entry, strhash(path));
224-
hashmap_add(&pathmap, &e->entry);
240+
241+
if (!hashmap_get(&pathmap, &e->entry, NULL))
242+
hashmap_add(&pathmap, &e->entry);
243+
else
244+
free(e);
225245

226246
if (!last_slash)
227247
last_slash = (char*)path;

bloom.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void fill_bloom_key(const char *data,
7474
const struct bloom_filter_settings *settings);
7575

7676
void add_key_to_filter(const struct bloom_key *key,
77-
struct bloom_filter *filter,
78-
const struct bloom_filter_settings *settings);
77+
struct bloom_filter *filter,
78+
const struct bloom_filter_settings *settings);
7979

8080
void init_bloom_filters(void);
8181

contrib/completion/git-completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ _git_log ()
18601860
$merge
18611861
$__git_diff_common_options
18621862
--pickaxe-all --pickaxe-regex
1863+
--patch --no-patch
18631864
"
18641865
return
18651866
;;

t/helper/test-bloom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid)
4444
}
4545

4646
static const char *bloom_usage = "\n"
47-
" test-tool bloom get_murmer3 <string>\n"
47+
" test-tool bloom get_murmur3 <string>\n"
4848
" test-tool bloom generate_filter <string> [<string>...]\n"
4949
" test-tool get_filter_for_commit <commit-hex>\n";
5050

t/t0095-bloom.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ test_expect_success 'get bloom filter for commit with 10 changes' '
8989
git add smallDir &&
9090
git commit -m "commit with 10 changes" &&
9191
cat >expect <<-\EOF &&
92-
Filter_Length:25
93-
Filter_Data:82|a0|65|47|0c|92|90|c0|a1|40|02|a0|e2|40|e0|04|0a|9a|66|cf|80|19|85|42|23|
92+
Filter_Length:14
93+
Filter_Data:02|b3|c4|a0|34|e7|fe|eb|cb|47|fe|a0|e8|72|
9494
EOF
9595
test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual &&
9696
test_cmp expect actual
@@ -100,7 +100,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
100100
rm actual &&
101101
rm expect &&
102102
mkdir bigDir &&
103-
for i in $(test_seq 0 512)
103+
for i in $(test_seq 0 511)
104104
do
105105
echo $i >bigDir/$i
106106
done &&

0 commit comments

Comments
 (0)