@@ -614,19 +614,29 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
614
614
return graph_chain ;
615
615
}
616
616
617
- static void validate_mixed_generation_chain (struct commit_graph * g )
617
+ /*
618
+ * returns 1 if and only if all graphs in the chain have
619
+ * corrected commit dates stored in the generation_data chunk.
620
+ */
621
+ static int validate_mixed_generation_chain (struct commit_graph * g )
618
622
{
619
- int read_generation_data ;
623
+ int read_generation_data = 1 ;
624
+ struct commit_graph * p = g ;
620
625
621
- if (!g )
622
- return ;
626
+ while (read_generation_data && p ) {
627
+ read_generation_data = p -> read_generation_data ;
628
+ p = p -> base_graph ;
629
+ }
623
630
624
- read_generation_data = !!g -> chunk_generation_data ;
631
+ if (read_generation_data )
632
+ return 1 ;
625
633
626
634
while (g ) {
627
- g -> read_generation_data = read_generation_data ;
635
+ g -> read_generation_data = 0 ;
628
636
g = g -> base_graph ;
629
637
}
638
+
639
+ return 0 ;
630
640
}
631
641
632
642
struct commit_graph * read_commit_graph_one (struct repository * r ,
@@ -1026,7 +1036,8 @@ struct write_commit_graph_context {
1026
1036
split :1 ,
1027
1037
changed_paths :1 ,
1028
1038
order_by_pack :1 ,
1029
- write_generation_data :1 ;
1039
+ write_generation_data :1 ,
1040
+ trust_generation_numbers :1 ;
1030
1041
1031
1042
struct topo_level_slab * topo_levels ;
1032
1043
const struct commit_graph_opts * opts ;
@@ -1098,7 +1109,7 @@ static int write_graph_chunk_data(struct hashfile *f,
1098
1109
uint32_t packedDate [2 ];
1099
1110
display_progress (ctx -> progress , ++ ctx -> progress_cnt );
1100
1111
1101
- if (parse_commit_no_graph ( * list ))
1112
+ if (repo_parse_commit_no_graph ( ctx -> r , * list ))
1102
1113
die (_ ("unable to parse commit %s" ),
1103
1114
oid_to_hex (& (* list )-> object .oid ));
1104
1115
tree = get_commit_tree_oid (* list );
@@ -1193,7 +1204,9 @@ static int write_graph_chunk_generation_data(struct hashfile *f,
1193
1204
1194
1205
for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1195
1206
struct commit * c = ctx -> commits .list [i ];
1196
- timestamp_t offset = commit_graph_data_at (c )-> generation - c -> date ;
1207
+ timestamp_t offset ;
1208
+ repo_parse_commit (ctx -> r , c );
1209
+ offset = commit_graph_data_at (c )-> generation - c -> date ;
1197
1210
display_progress (ctx -> progress , ++ ctx -> progress_cnt );
1198
1211
1199
1212
if (offset > GENERATION_NUMBER_V2_OFFSET_MAX ) {
@@ -1411,11 +1424,11 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1411
1424
if (!commit )
1412
1425
continue ;
1413
1426
if (ctx -> split ) {
1414
- if ((!parse_commit ( commit ) &&
1427
+ if ((!repo_parse_commit ( ctx -> r , commit ) &&
1415
1428
commit_graph_position (commit ) == COMMIT_NOT_FROM_GRAPH ) ||
1416
1429
flags == COMMIT_GRAPH_SPLIT_REPLACE )
1417
1430
add_missing_parents (ctx , commit );
1418
- } else if (!parse_commit_no_graph ( commit ))
1431
+ } else if (!repo_parse_commit_no_graph ( ctx -> r , commit ))
1419
1432
add_missing_parents (ctx , commit );
1420
1433
}
1421
1434
stop_progress (& ctx -> progress );
@@ -1434,48 +1447,45 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1434
1447
stop_progress (& ctx -> progress );
1435
1448
}
1436
1449
1437
- static void compute_generation_numbers (struct write_commit_graph_context * ctx )
1450
+ static void compute_topological_levels (struct write_commit_graph_context * ctx )
1438
1451
{
1439
1452
int i ;
1440
1453
struct commit_list * list = NULL ;
1441
1454
1442
1455
if (ctx -> report_progress )
1443
1456
ctx -> progress = start_delayed_progress (
1444
- _ ("Computing commit graph generation numbers " ),
1457
+ _ ("Computing commit graph topological levels " ),
1445
1458
ctx -> commits .nr );
1446
1459
for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1447
- uint32_t level = * topo_level_slab_at (ctx -> topo_levels , ctx -> commits .list [i ]);
1448
- timestamp_t corrected_commit_date = commit_graph_data_at (ctx -> commits .list [i ])-> generation ;
1460
+ struct commit * c = ctx -> commits .list [i ];
1461
+ uint32_t level ;
1462
+
1463
+ repo_parse_commit (ctx -> r , c );
1464
+ level = * topo_level_slab_at (ctx -> topo_levels , c );
1449
1465
1450
1466
display_progress (ctx -> progress , i + 1 );
1451
- if (level != GENERATION_NUMBER_ZERO &&
1452
- corrected_commit_date != GENERATION_NUMBER_ZERO )
1467
+ if (level != GENERATION_NUMBER_ZERO )
1453
1468
continue ;
1454
1469
1455
- commit_list_insert (ctx -> commits . list [ i ] , & list );
1470
+ commit_list_insert (c , & list );
1456
1471
while (list ) {
1457
1472
struct commit * current = list -> item ;
1458
1473
struct commit_list * parent ;
1459
1474
int all_parents_computed = 1 ;
1460
1475
uint32_t max_level = 0 ;
1461
- timestamp_t max_corrected_commit_date = 0 ;
1462
1476
1463
1477
for (parent = current -> parents ; parent ; parent = parent -> next ) {
1478
+ repo_parse_commit (ctx -> r , parent -> item );
1464
1479
level = * topo_level_slab_at (ctx -> topo_levels , parent -> item );
1465
- corrected_commit_date = commit_graph_data_at (parent -> item )-> generation ;
1466
1480
1467
- if (level == GENERATION_NUMBER_ZERO ||
1468
- corrected_commit_date == GENERATION_NUMBER_ZERO ) {
1481
+ if (level == GENERATION_NUMBER_ZERO ) {
1469
1482
all_parents_computed = 0 ;
1470
1483
commit_list_insert (parent -> item , & list );
1471
1484
break ;
1472
1485
}
1473
1486
1474
1487
if (level > max_level )
1475
1488
max_level = level ;
1476
-
1477
- if (corrected_commit_date > max_corrected_commit_date )
1478
- max_corrected_commit_date = corrected_commit_date ;
1479
1489
}
1480
1490
1481
1491
if (all_parents_computed ) {
@@ -1484,6 +1494,64 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1484
1494
if (max_level > GENERATION_NUMBER_V1_MAX - 1 )
1485
1495
max_level = GENERATION_NUMBER_V1_MAX - 1 ;
1486
1496
* topo_level_slab_at (ctx -> topo_levels , current ) = max_level + 1 ;
1497
+ }
1498
+ }
1499
+ }
1500
+ stop_progress (& ctx -> progress );
1501
+ }
1502
+
1503
+ static void compute_generation_numbers (struct write_commit_graph_context * ctx )
1504
+ {
1505
+ int i ;
1506
+ struct commit_list * list = NULL ;
1507
+
1508
+ if (ctx -> report_progress )
1509
+ ctx -> progress = start_delayed_progress (
1510
+ _ ("Computing commit graph generation numbers" ),
1511
+ ctx -> commits .nr );
1512
+
1513
+ if (!ctx -> trust_generation_numbers ) {
1514
+ for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1515
+ struct commit * c = ctx -> commits .list [i ];
1516
+ repo_parse_commit (ctx -> r , c );
1517
+ commit_graph_data_at (c )-> generation = GENERATION_NUMBER_ZERO ;
1518
+ }
1519
+ }
1520
+
1521
+ for (i = 0 ; i < ctx -> commits .nr ; i ++ ) {
1522
+ struct commit * c = ctx -> commits .list [i ];
1523
+ timestamp_t corrected_commit_date ;
1524
+
1525
+ repo_parse_commit (ctx -> r , c );
1526
+ corrected_commit_date = commit_graph_data_at (c )-> generation ;
1527
+
1528
+ display_progress (ctx -> progress , i + 1 );
1529
+ if (corrected_commit_date != GENERATION_NUMBER_ZERO )
1530
+ continue ;
1531
+
1532
+ commit_list_insert (c , & list );
1533
+ while (list ) {
1534
+ struct commit * current = list -> item ;
1535
+ struct commit_list * parent ;
1536
+ int all_parents_computed = 1 ;
1537
+ timestamp_t max_corrected_commit_date = 0 ;
1538
+
1539
+ for (parent = current -> parents ; parent ; parent = parent -> next ) {
1540
+ repo_parse_commit (ctx -> r , parent -> item );
1541
+ corrected_commit_date = commit_graph_data_at (parent -> item )-> generation ;
1542
+
1543
+ if (corrected_commit_date == GENERATION_NUMBER_ZERO ) {
1544
+ all_parents_computed = 0 ;
1545
+ commit_list_insert (parent -> item , & list );
1546
+ break ;
1547
+ }
1548
+
1549
+ if (corrected_commit_date > max_corrected_commit_date )
1550
+ max_corrected_commit_date = corrected_commit_date ;
1551
+ }
1552
+
1553
+ if (all_parents_computed ) {
1554
+ pop_commit (& list );
1487
1555
1488
1556
if (current -> date && current -> date > max_corrected_commit_date )
1489
1557
max_corrected_commit_date = current -> date - 1 ;
@@ -1710,9 +1778,9 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
1710
1778
continue ;
1711
1779
1712
1780
if (ctx -> split && flags == COMMIT_GRAPH_SPLIT_REPLACE )
1713
- parse_commit ( ctx -> commits .list [ctx -> commits .nr ]);
1781
+ repo_parse_commit ( ctx -> r , ctx -> commits .list [ctx -> commits .nr ]);
1714
1782
else
1715
- parse_commit_no_graph ( ctx -> commits .list [ctx -> commits .nr ]);
1783
+ repo_parse_commit_no_graph ( ctx -> r , ctx -> commits .list [ctx -> commits .nr ]);
1716
1784
1717
1785
num_parents = commit_list_count (ctx -> commits .list [ctx -> commits .nr ]-> parents );
1718
1786
if (num_parents > 2 )
@@ -2280,6 +2348,7 @@ int write_commit_graph(struct object_directory *odb,
2280
2348
init_topo_level_slab (& topo_levels );
2281
2349
ctx -> topo_levels = & topo_levels ;
2282
2350
2351
+ prepare_commit_graph (ctx -> r );
2283
2352
if (ctx -> r -> objects -> commit_graph ) {
2284
2353
struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2285
2354
@@ -2293,7 +2362,6 @@ int write_commit_graph(struct object_directory *odb,
2293
2362
ctx -> changed_paths = 1 ;
2294
2363
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
2295
2364
struct commit_graph * g ;
2296
- prepare_commit_graph_one (ctx -> r , ctx -> odb );
2297
2365
2298
2366
g = ctx -> r -> objects -> commit_graph ;
2299
2367
@@ -2305,10 +2373,7 @@ int write_commit_graph(struct object_directory *odb,
2305
2373
}
2306
2374
2307
2375
if (ctx -> split ) {
2308
- struct commit_graph * g ;
2309
- prepare_commit_graph (ctx -> r );
2310
-
2311
- g = ctx -> r -> objects -> commit_graph ;
2376
+ struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2312
2377
2313
2378
while (g ) {
2314
2379
ctx -> num_commit_graphs_before ++ ;
@@ -2332,9 +2397,6 @@ int write_commit_graph(struct object_directory *odb,
2332
2397
2333
2398
ctx -> approx_nr_objects = approximate_object_count ();
2334
2399
2335
- if (ctx -> append )
2336
- prepare_commit_graph_one (ctx -> r , ctx -> odb );
2337
-
2338
2400
if (ctx -> append && ctx -> r -> objects -> commit_graph ) {
2339
2401
struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2340
2402
for (i = 0 ; i < g -> num_commits ; i ++ ) {
@@ -2381,9 +2443,11 @@ int write_commit_graph(struct object_directory *odb,
2381
2443
} else
2382
2444
ctx -> num_commit_graphs_after = 1 ;
2383
2445
2384
- validate_mixed_generation_chain (ctx -> r -> objects -> commit_graph );
2446
+ ctx -> trust_generation_numbers = validate_mixed_generation_chain (ctx -> r -> objects -> commit_graph );
2385
2447
2386
- compute_generation_numbers (ctx );
2448
+ compute_topological_levels (ctx );
2449
+ if (ctx -> write_generation_data )
2450
+ compute_generation_numbers (ctx );
2387
2451
2388
2452
if (ctx -> changed_paths )
2389
2453
compute_bloom_filters (ctx );
0 commit comments