24
24
#define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
25
25
#define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
26
26
#define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
27
+ #define GRAPH_CHUNKID_BLOOMINDEXES 0x42494458 /* "BIDX" */
28
+ #define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
27
29
#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
28
- #define MAX_NUM_CHUNKS 5
30
+ #define MAX_NUM_CHUNKS 7
29
31
30
32
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
31
33
@@ -319,6 +321,32 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
319
321
chunk_repeated = 1 ;
320
322
else
321
323
graph -> chunk_base_graphs = data + chunk_offset ;
324
+ break ;
325
+
326
+ case GRAPH_CHUNKID_BLOOMINDEXES :
327
+ if (graph -> chunk_bloom_indexes )
328
+ chunk_repeated = 1 ;
329
+ else
330
+ graph -> chunk_bloom_indexes = data + chunk_offset ;
331
+ break ;
332
+
333
+ case GRAPH_CHUNKID_BLOOMDATA :
334
+ if (graph -> chunk_bloom_data )
335
+ chunk_repeated = 1 ;
336
+ else {
337
+ uint32_t hash_version ;
338
+ graph -> chunk_bloom_data = data + chunk_offset ;
339
+ hash_version = get_be32 (data + chunk_offset );
340
+
341
+ if (hash_version != 1 )
342
+ break ;
343
+
344
+ graph -> bloom_filter_settings = xmalloc (sizeof (struct bloom_filter_settings ));
345
+ graph -> bloom_filter_settings -> hash_version = hash_version ;
346
+ graph -> bloom_filter_settings -> num_hashes = get_be32 (data + chunk_offset + 4 );
347
+ graph -> bloom_filter_settings -> bits_per_entry = get_be32 (data + chunk_offset + 8 );
348
+ }
349
+ break ;
322
350
}
323
351
324
352
if (chunk_repeated ) {
@@ -337,6 +365,15 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
337
365
last_chunk_offset = chunk_offset ;
338
366
}
339
367
368
+ if (graph -> chunk_bloom_indexes && graph -> chunk_bloom_data ) {
369
+ init_bloom_filters ();
370
+ } else {
371
+ /* We need both the bloom chunks to exist together. Else ignore the data */
372
+ graph -> chunk_bloom_indexes = NULL ;
373
+ graph -> chunk_bloom_data = NULL ;
374
+ graph -> bloom_filter_settings = NULL ;
375
+ }
376
+
340
377
hashcpy (graph -> oid .hash , graph -> data + graph -> data_len - graph -> hash_len );
341
378
342
379
if (verify_commit_graph_lite (graph )) {
@@ -1034,6 +1071,59 @@ static void write_graph_chunk_extra_edges(struct hashfile *f,
1034
1071
}
1035
1072
}
1036
1073
1074
+ static void write_graph_chunk_bloom_indexes (struct hashfile * f ,
1075
+ struct write_commit_graph_context * ctx )
1076
+ {
1077
+ struct commit * * list = ctx -> commits .list ;
1078
+ struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1079
+ uint32_t cur_pos = 0 ;
1080
+ struct progress * progress = NULL ;
1081
+ int i = 0 ;
1082
+
1083
+ if (ctx -> report_progress )
1084
+ progress = start_delayed_progress (
1085
+ _ ("Writing changed paths Bloom filters index" ),
1086
+ ctx -> commits .nr );
1087
+
1088
+ while (list < last ) {
1089
+ struct bloom_filter * filter = get_bloom_filter (ctx -> r , * list );
1090
+ cur_pos += filter -> len ;
1091
+ display_progress (progress , ++ i );
1092
+ hashwrite_be32 (f , cur_pos );
1093
+ list ++ ;
1094
+ }
1095
+
1096
+ stop_progress (& progress );
1097
+ }
1098
+
1099
+ static void write_graph_chunk_bloom_data (struct hashfile * f ,
1100
+ struct write_commit_graph_context * ctx ,
1101
+ const struct bloom_filter_settings * settings )
1102
+ {
1103
+ struct commit * * list = ctx -> commits .list ;
1104
+ struct commit * * last = ctx -> commits .list + ctx -> commits .nr ;
1105
+ struct progress * progress = NULL ;
1106
+ int i = 0 ;
1107
+
1108
+ if (ctx -> report_progress )
1109
+ progress = start_delayed_progress (
1110
+ _ ("Writing changed paths Bloom filters data" ),
1111
+ ctx -> commits .nr );
1112
+
1113
+ hashwrite_be32 (f , settings -> hash_version );
1114
+ hashwrite_be32 (f , settings -> num_hashes );
1115
+ hashwrite_be32 (f , settings -> bits_per_entry );
1116
+
1117
+ while (list < last ) {
1118
+ struct bloom_filter * filter = get_bloom_filter (ctx -> r , * list );
1119
+ display_progress (progress , ++ i );
1120
+ hashwrite (f , filter -> data , filter -> len * sizeof (unsigned char ));
1121
+ list ++ ;
1122
+ }
1123
+
1124
+ stop_progress (& progress );
1125
+ }
1126
+
1037
1127
static int oid_compare (const void * _a , const void * _b )
1038
1128
{
1039
1129
const struct object_id * a = (const struct object_id * )_a ;
@@ -1438,6 +1528,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1438
1528
struct strbuf progress_title = STRBUF_INIT ;
1439
1529
int num_chunks = 3 ;
1440
1530
struct object_id file_hash ;
1531
+ const struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS ;
1441
1532
1442
1533
if (ctx -> split ) {
1443
1534
struct strbuf tmp_file = STRBUF_INIT ;
@@ -1482,6 +1573,12 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1482
1573
chunk_ids [num_chunks ] = GRAPH_CHUNKID_EXTRAEDGES ;
1483
1574
num_chunks ++ ;
1484
1575
}
1576
+ if (ctx -> changed_paths ) {
1577
+ chunk_ids [num_chunks ] = GRAPH_CHUNKID_BLOOMINDEXES ;
1578
+ num_chunks ++ ;
1579
+ chunk_ids [num_chunks ] = GRAPH_CHUNKID_BLOOMDATA ;
1580
+ num_chunks ++ ;
1581
+ }
1485
1582
if (ctx -> num_commit_graphs_after > 1 ) {
1486
1583
chunk_ids [num_chunks ] = GRAPH_CHUNKID_BASE ;
1487
1584
num_chunks ++ ;
@@ -1500,6 +1597,15 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1500
1597
4 * ctx -> num_extra_edges ;
1501
1598
num_chunks ++ ;
1502
1599
}
1600
+ if (ctx -> changed_paths ) {
1601
+ chunk_offsets [num_chunks + 1 ] = chunk_offsets [num_chunks ] +
1602
+ sizeof (uint32_t ) * ctx -> commits .nr ;
1603
+ num_chunks ++ ;
1604
+
1605
+ chunk_offsets [num_chunks + 1 ] = chunk_offsets [num_chunks ] +
1606
+ sizeof (uint32_t ) * 3 + ctx -> total_bloom_filter_data_size ;
1607
+ num_chunks ++ ;
1608
+ }
1503
1609
if (ctx -> num_commit_graphs_after > 1 ) {
1504
1610
chunk_offsets [num_chunks + 1 ] = chunk_offsets [num_chunks ] +
1505
1611
hashsz * (ctx -> num_commit_graphs_after - 1 );
@@ -1537,6 +1643,10 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1537
1643
write_graph_chunk_data (f , hashsz , ctx );
1538
1644
if (ctx -> num_extra_edges )
1539
1645
write_graph_chunk_extra_edges (f , ctx );
1646
+ if (ctx -> changed_paths ) {
1647
+ write_graph_chunk_bloom_indexes (f , ctx );
1648
+ write_graph_chunk_bloom_data (f , ctx , & bloom_settings );
1649
+ }
1540
1650
if (ctx -> num_commit_graphs_after > 1 &&
1541
1651
write_graph_chunk_base (f , ctx )) {
1542
1652
return -1 ;
@@ -2184,6 +2294,7 @@ void free_commit_graph(struct commit_graph *g)
2184
2294
close (g -> graph_fd );
2185
2295
}
2186
2296
free (g -> filename );
2297
+ free (g -> bloom_filter_settings );
2187
2298
free (g );
2188
2299
}
2189
2300
0 commit comments