@matheusbsbs / matheus-bagliano / commits / f97b9325f6
Fork 0

commit-graph: compute Bloom filters for changed paths

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>

Garima Singh committed Mar 30, 2020 at 00:31 UTC f97b9325f6d7ad2a28bfaf6fab3197d207fcb278
2 files changed +33 -2
commit-graph.c
+31 -1
@@ -16,6 +16,7 @@
16 #include "hashmap.h"
17 #include "replace-object.h"
18 #include "progress.h"
19 +#include "bloom.h"
20
21 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
22 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -789,9 +790,11 @@ struct write_commit_graph_context {
790 unsigned append:1,
791 report_progress:1,
792 split:1,
792 - check_oids:1;
793 + check_oids:1,
794 + changed_paths:1;
795
796 const struct split_commit_graph_opts *split_opts;
797 + size_t total_bloom_filter_data_size;
798 };
799
800 static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1134,6 +1137,28 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1137 stop_progress(&ctx->progress);
1138 }
1139
1140 +static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1141 +{
1142 + int i;
1143 + struct progress *progress = NULL;
1144 +
1145 + init_bloom_filters();
1146 +
1147 + if (ctx->report_progress)
1148 + progress = start_delayed_progress(
1149 + _("Computing commit changed paths Bloom filters"),
1150 + ctx->commits.nr);
1151 +
1152 + for (i = 0; i < ctx->commits.nr; i++) {
1153 + struct commit *c = ctx->commits.list[i];
1154 + struct bloom_filter *filter = get_bloom_filter(ctx->r, c);
1155 + ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
1156 + display_progress(progress, i + 1);
1157 + }
1158 +
1159 + stop_progress(&progress);
1160 +}
1161 +
1162 static int add_ref_to_list(const char *refname,
1163 const struct object_id *oid,
1164 int flags, void *cb_data)
@@ -1776,6 +1801,8 @@ int write_commit_graph(struct object_directory *odb,
1801 ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
1802 ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
1803 ctx->split_opts = split_opts;
1804 + ctx->changed_paths = flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS ? 1 : 0;
1805 + ctx->total_bloom_filter_data_size = 0;
1806
1807 if (ctx->split) {
1808 struct commit_graph *g;
@@ -1870,6 +1897,9 @@ int write_commit_graph(struct object_directory *odb,
1897
1898 compute_generation_numbers(ctx);
1899
1900 + if (ctx->changed_paths)
1901 + compute_bloom_filters(ctx);
1902 +
1903 res = write_commit_graph_file(ctx);
1904
1905 if (ctx->split)
commit-graph.h
+2 -1
@@ -79,7 +79,8 @@ enum commit_graph_write_flags {
79 COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
80 COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
81 /* Make sure that each OID in the input is a valid commit OID. */
82 - COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3)
82 + COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
83 + COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 4),
84 };
85
86 struct split_commit_graph_opts {