Skip to content

Commit f97b932

Browse files
garimasi514gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Garima Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e369698 commit f97b932

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

commit-graph.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "hashmap.h"
1717
#include "replace-object.h"
1818
#include "progress.h"
19+
#include "bloom.h"
1920

2021
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
2122
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -789,9 +790,11 @@ struct write_commit_graph_context {
789790
unsigned append:1,
790791
report_progress:1,
791792
split:1,
792-
check_oids:1;
793+
check_oids:1,
794+
changed_paths:1;
793795

794796
const struct split_commit_graph_opts *split_opts;
797+
size_t total_bloom_filter_data_size;
795798
};
796799

797800
static void write_graph_chunk_fanout(struct hashfile *f,
@@ -1134,6 +1137,28 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
11341137
stop_progress(&ctx->progress);
11351138
}
11361139

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+
11371162
static int add_ref_to_list(const char *refname,
11381163
const struct object_id *oid,
11391164
int flags, void *cb_data)
@@ -1776,6 +1801,8 @@ int write_commit_graph(struct object_directory *odb,
17761801
ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
17771802
ctx->check_oids = flags & COMMIT_GRAPH_WRITE_CHECK_OIDS ? 1 : 0;
17781803
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;
17791806

17801807
if (ctx->split) {
17811808
struct commit_graph *g;
@@ -1870,6 +1897,9 @@ int write_commit_graph(struct object_directory *odb,
18701897

18711898
compute_generation_numbers(ctx);
18721899

1900+
if (ctx->changed_paths)
1901+
compute_bloom_filters(ctx);
1902+
18731903
res = write_commit_graph_file(ctx);
18741904

18751905
if (ctx->split)

commit-graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ enum commit_graph_write_flags {
7979
COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
8080
COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
8181
/* 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),
8384
};
8485

8586
struct split_commit_graph_opts {

0 commit comments

Comments
 (0)