1 #include "git-compat-util.h"
6 static struct bloom_filter_settings settings
= DEFAULT_BLOOM_FILTER_SETTINGS
;
8 static void add_string_to_filter(const char *data
, struct bloom_filter
*filter
) {
12 fill_bloom_key(data
, strlen(data
), &key
, &settings
);
14 for (i
= 0; i
< settings
.num_hashes
; i
++){
15 printf("0x%08x|", key
.hashes
[i
]);
18 add_key_to_filter(&key
, filter
, &settings
);
21 static void print_bloom_filter(struct bloom_filter
*filter
) {
25 printf("No filter.\n");
28 printf("Filter_Length:%d\n", (int)filter
->len
);
29 printf("Filter_Data:");
30 for (i
= 0; i
< filter
->len
; i
++) {
31 printf("%02x|", filter
->data
[i
]);
36 static void get_bloom_filter_for_commit(const struct object_id
*commit_oid
)
39 struct bloom_filter
*filter
;
40 setup_git_directory();
41 c
= lookup_commit(the_repository
, commit_oid
);
42 filter
= get_or_compute_bloom_filter(the_repository
, c
, 1,
45 print_bloom_filter(filter
);
48 static const char *bloom_usage
= "\n"
49 " test-tool bloom get_murmur3 <string>\n"
50 " test-tool bloom generate_filter <string> [<string>...]\n"
51 " test-tool get_filter_for_commit <commit-hex>\n";
53 int cmd__bloom(int argc
, const char **argv
)
55 setup_git_directory();
60 if (!strcmp(argv
[1], "get_murmur3")) {
64 hashed
= murmur3_seeded(0, argv
[2], strlen(argv
[2]));
65 printf("Murmur3 Hash with seed=0:0x%08x\n", hashed
);
68 if (!strcmp(argv
[1], "generate_filter")) {
69 struct bloom_filter filter
;
71 filter
.len
= (settings
.bits_per_entry
+ BITS_PER_WORD
- 1) / BITS_PER_WORD
;
72 filter
.data
= xcalloc(filter
.len
, sizeof(unsigned char));
78 add_string_to_filter(argv
[i
], &filter
);
82 print_bloom_filter(&filter
);
85 if (!strcmp(argv
[1], "get_filter_for_commit")) {
90 if (parse_oid_hex(argv
[2], &oid
, &end
))
91 die("cannot parse oid '%s'", argv
[2]);
93 get_bloom_filter_for_commit(&oid
);