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
This commit is contained in:
Junio C Hamano
2020-05-14 14:39:44 -07:00
6 changed files with 49 additions and 28 deletions

View File

@@ -97,10 +97,10 @@ CHUNK DATA:
bit on. The other bits correspond to the position of the last parent. bit on. The other bits correspond to the position of the last parent.
Bloom Filter Index (ID: {'B', 'I', 'D', 'X'}) (N * 4 bytes) [Optional] Bloom Filter Index (ID: {'B', 'I', 'D', 'X'}) (N * 4 bytes) [Optional]
* The ith entry, BIDX[i], stores the number of 8-byte word blocks in all * The ith entry, BIDX[i], stores the number of bytes in all Bloom filters
Bloom filters from commit 0 to commit i (inclusive) in lexicographic from commit 0 to commit i (inclusive) in lexicographic order. The Bloom
order. The Bloom filter for the i-th commit spans from BIDX[i-1] to filter for the i-th commit spans from BIDX[i-1] to BIDX[i] (plus header
BIDX[i] (plus header length), where BIDX[-1] is 0. length), where BIDX[-1] is 0.
* The BIDX chunk is ignored if the BDAT chunk is not present. * The BIDX chunk is ignored if the BDAT chunk is not present.
Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional] Bloom Filter Data (ID: {'B', 'D', 'A', 'T'}) [Optional]

24
bloom.c
View File

@@ -158,6 +158,19 @@ void init_bloom_filters(void)
init_bloom_filter_slab(&bloom_filters); init_bloom_filter_slab(&bloom_filters);
} }
static int pathmap_cmp(const void *hashmap_cmp_fn_data,
const struct hashmap_entry *eptr,
const struct hashmap_entry *entry_or_key,
const void *keydata)
{
const struct pathmap_hash_entry *e1, *e2;
e1 = container_of(eptr, const struct pathmap_hash_entry, entry);
e2 = container_of(entry_or_key, const struct pathmap_hash_entry, entry);
return strcmp(e1->path, e2->path);
}
struct bloom_filter *get_bloom_filter(struct repository *r, struct bloom_filter *get_bloom_filter(struct repository *r,
struct commit *c, struct commit *c,
int compute_if_not_present) int compute_if_not_present)
@@ -193,17 +206,20 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
diffopt.max_changes = max_changes; diffopt.max_changes = max_changes;
diff_setup_done(&diffopt); diff_setup_done(&diffopt);
/* ensure commit is parsed so we have parent information */
repo_parse_commit(r, c);
if (c->parents) if (c->parents)
diff_tree_oid(&c->parents->item->object.oid, &c->object.oid, "", &diffopt); diff_tree_oid(&c->parents->item->object.oid, &c->object.oid, "", &diffopt);
else else
diff_tree_oid(NULL, &c->object.oid, "", &diffopt); diff_tree_oid(NULL, &c->object.oid, "", &diffopt);
diffcore_std(&diffopt); diffcore_std(&diffopt);
if (diff_queued_diff.nr <= max_changes) { if (diffopt.num_changes <= max_changes) {
struct hashmap pathmap; struct hashmap pathmap;
struct pathmap_hash_entry *e; struct pathmap_hash_entry *e;
struct hashmap_iter iter; struct hashmap_iter iter;
hashmap_init(&pathmap, NULL, NULL, 0); hashmap_init(&pathmap, pathmap_cmp, NULL, 0);
for (i = 0; i < diff_queued_diff.nr; i++) { for (i = 0; i < diff_queued_diff.nr; i++) {
const char *path = diff_queued_diff.queue[i]->two->path; const char *path = diff_queued_diff.queue[i]->two->path;
@@ -221,7 +237,11 @@ struct bloom_filter *get_bloom_filter(struct repository *r,
FLEX_ALLOC_STR(e, path, path); FLEX_ALLOC_STR(e, path, path);
hashmap_entry_init(&e->entry, strhash(path)); hashmap_entry_init(&e->entry, strhash(path));
if (!hashmap_get(&pathmap, &e->entry, NULL))
hashmap_add(&pathmap, &e->entry); hashmap_add(&pathmap, &e->entry);
else
free(e);
if (!last_slash) if (!last_slash)
last_slash = (char*)path; last_slash = (char*)path;

View File

@@ -1860,6 +1860,7 @@ _git_log ()
$merge $merge
$__git_diff_common_options $__git_diff_common_options
--pickaxe-all --pickaxe-regex --pickaxe-all --pickaxe-regex
--patch --no-patch
" "
return return
;; ;;

View File

@@ -44,7 +44,7 @@ static void get_bloom_filter_for_commit(const struct object_id *commit_oid)
} }
static const char *bloom_usage = "\n" static const char *bloom_usage = "\n"
" test-tool bloom get_murmer3 <string>\n" " test-tool bloom get_murmur3 <string>\n"
" test-tool bloom generate_filter <string> [<string>...]\n" " test-tool bloom generate_filter <string> [<string>...]\n"
" test-tool get_filter_for_commit <commit-hex>\n"; " test-tool get_filter_for_commit <commit-hex>\n";

View File

@@ -89,8 +89,8 @@ test_expect_success 'get bloom filter for commit with 10 changes' '
git add smallDir && git add smallDir &&
git commit -m "commit with 10 changes" && git commit -m "commit with 10 changes" &&
cat >expect <<-\EOF && cat >expect <<-\EOF &&
Filter_Length:25 Filter_Length:14
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| Filter_Data:02|b3|c4|a0|34|e7|fe|eb|cb|47|fe|a0|e8|72|
EOF EOF
test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual && test-tool bloom get_filter_for_commit "$(git rev-parse HEAD)" >actual &&
test_cmp expect actual test_cmp expect actual
@@ -100,7 +100,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' '
rm actual && rm actual &&
rm expect && rm expect &&
mkdir bigDir && mkdir bigDir &&
for i in $(test_seq 0 512) for i in $(test_seq 0 511)
do do
echo $i >bigDir/$i echo $i >bigDir/$i
done && done &&