]> git.ipfire.org Git - thirdparty/git.git/blobdiff - bloom.h
Git 2.47-rc0
[thirdparty/git.git] / bloom.h
diff --git a/bloom.h b/bloom.h
index adde6dfe21254f7022051fd6d3c19b722b34f54e..6e46489a20129a42a92aaecf6e724350590d17bd 100644 (file)
--- a/bloom.h
+++ b/bloom.h
@@ -3,19 +3,22 @@
 
 struct commit;
 struct repository;
+struct commit_graph;
 
 struct bloom_filter_settings {
        /*
         * The version of the hashing technique being used.
-        * We currently only support version = 1 which is
+        * The newest version is 2, which is
         * the seeded murmur3 hashing technique implemented
-        * in bloom.c.
+        * in bloom.c. Bloom filters of version 1 were created
+        * with prior versions of Git, which had a bug in the
+        * implementation of the hash function.
         */
        uint32_t hash_version;
 
        /*
         * The number of times a path is hashed, i.e. the
-        * number of bit positions tht cumulatively
+        * number of bit positions that cumulatively
         * determine whether a path is present in the
         * Bloom filter.
         */
@@ -52,6 +55,9 @@ struct bloom_filter_settings {
 struct bloom_filter {
        unsigned char *data;
        size_t len;
+       int version;
+
+       void *to_free;
 };
 
 /*
@@ -68,6 +74,10 @@ struct bloom_key {
        uint32_t *hashes;
 };
 
+int load_bloom_filter_from_graph(struct commit_graph *g,
+                                struct bloom_filter *filter,
+                                uint32_t graph_pos);
+
 /*
  * Calculate the murmur3 32-bit hash value for the given data
  * using the given seed.
@@ -75,7 +85,7 @@ struct bloom_key {
  * Not considered to be cryptographically secure.
  * Implemented as described in https://en.wikipedia.org/wiki/MurmurHash#Algorithm
  */
-uint32_t murmur3_seeded(uint32_t seed, const char *data, size_t len);
+uint32_t murmur3_seeded_v2(uint32_t seed, const char *data, size_t len);
 
 void fill_bloom_key(const char *data,
                    size_t len,
@@ -88,12 +98,14 @@ void add_key_to_filter(const struct bloom_key *key,
                       const struct bloom_filter_settings *settings);
 
 void init_bloom_filters(void);
+void deinit_bloom_filters(void);
 
 enum bloom_filter_computed {
        BLOOM_NOT_COMPUTED = (1 << 0),
        BLOOM_COMPUTED     = (1 << 1),
        BLOOM_TRUNC_LARGE  = (1 << 2),
        BLOOM_TRUNC_EMPTY  = (1 << 3),
+       BLOOM_UPGRADED     = (1 << 4),
 };
 
 struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
@@ -102,8 +114,24 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
                                                 const struct bloom_filter_settings *settings,
                                                 enum bloom_filter_computed *computed);
 
-#define get_bloom_filter(r, c) get_or_compute_bloom_filter( \
-       (r), (c), 0, NULL, NULL)
+/*
+ * Find the Bloom filter associated with the given commit "c".
+ *
+ * If any of the following are true
+ *
+ *   - the repository does not have a commit-graph, or
+ *   - the repository disables reading from the commit-graph, or
+ *   - the given commit does not have a Bloom filter computed, or
+ *   - there is a Bloom filter for commit "c", but it cannot be read
+ *     because the filter uses an incompatible version of murmur3
+ *
+ * , then `get_bloom_filter()` will return NULL. Otherwise, the corresponding
+ * Bloom filter will be returned.
+ *
+ * For callers who wish to inspect Bloom filters with incompatible hash
+ * versions, use get_or_compute_bloom_filter().
+ */
+struct bloom_filter *get_bloom_filter(struct repository *r, struct commit *c);
 
 int bloom_filter_contains(const struct bloom_filter *filter,
                          const struct bloom_key *key,