]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: compute Bloom filters for changed paths
authorGarima Singh <garima.singh@microsoft.com>
Mon, 30 Mar 2020 00:31:28 +0000 (00:31 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Mar 2020 16:59:53 +0000 (09:59 -0700)
Add new COMMIT_GRAPH_WRITE_CHANGED_PATHS flag that makes Git compute
Bloom filters for the paths that changed between a commit and it's
first parent, for each commit in the commit-graph.  This computation
is done on a commit-by-commit basis.

We will write these Bloom filters to the commit-graph file, to store
this data on disk, in the next change in this series.

Helped-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Garima Singh <garima.singh@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
commit-graph.h

index e4f1a5b2f1aecf5217a9c3606fee4e625ec83862..862a00d67ed6372dc9c97953ff39ebca0550a011 100644 (file)
@@ -16,6 +16,7 @@
 #include "hashmap.h"
 #include "replace-object.h"
 #include "progress.h"
+#include "bloom.h"
 
 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -789,9 +790,11 @@ struct write_commit_graph_context {
        unsigned append:1,
                 report_progress:1,
                 split:1,
-                check_oids:1;
+                check_oids:1,
+                changed_paths:1;
 
        const struct split_commit_graph_opts *split_opts;
+       size_t total_bloom_filter_data_size;
 };
 
 static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1134,6 +1137,28 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
        stop_progress(&ctx->progress);
 }
 
+static void compute_bloom_filters(struct write_commit_graph_context *ctx)
+{
+       int i;
+       struct progress *progress = NULL;
+
+       init_bloom_filters();
+
+       if (ctx->report_progress)
+               progress = start_delayed_progress(
+                       _("Computing commit changed paths Bloom filters"),
+                       ctx->commits.nr);
+
+       for (i = 0; i < ctx->commits.nr; i++) {
+               struct commit *c = ctx->commits.list[i];
+               struct bloom_filter *filter = get_bloom_filter(ctx->r, c);
+               ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
+               display_progress(progress, i + 1);
+       }
+
+       stop_progress(&progress);
+}
+
 static int add_ref_to_list(const char *refname,
                           const struct object_id *oid,
                           int flags, void *cb_data)
@@ -1776,6 +1801,8 @@ int write_commit_graph(struct object_directory *odb,
        ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
        ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
        ctx->split_opts = split_opts;
+       ctx->changed_paths = flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS ? 1 : 0;
+       ctx->total_bloom_filter_data_size = 0;
 
        if (ctx->split) {
                struct commit_graph *g;
@@ -1870,6 +1897,9 @@ int write_commit_graph(struct object_directory *odb,
 
        compute_generation_numbers(ctx);
 
+       if (ctx->changed_paths)
+               compute_bloom_filters(ctx);
+
        res = write_commit_graph_file(ctx);
 
        if (ctx->split)
index e87a6f636000d68137fe3ec437b02e439a8171a5..86be81219da44a9a18e3d1be561d0dc6e4cff07d 100644 (file)
@@ -79,7 +79,8 @@ enum commit_graph_write_flags {
        COMMIT_GRAPH_WRITE_PROGRESS   = (1 << 1),
        COMMIT_GRAPH_WRITE_SPLIT      = (1 << 2),
        /* Make sure that each OID in the input is a valid commit OID. */
-       COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
+       COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
+       COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 4),
 };
 
 struct split_commit_graph_opts {