@@ -2511,7 +2511,17 @@ int write_commit_graph(struct object_directory *odb,
2511
2511
const struct commit_graph_opts * opts )
2512
2512
{
2513
2513
struct repository * r = the_repository ;
2514
- struct write_commit_graph_context * ctx ;
2514
+ struct write_commit_graph_context ctx = {
2515
+ .r = r ,
2516
+ .odb = odb ,
2517
+ .append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0 ,
2518
+ .report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0 ,
2519
+ .split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0 ,
2520
+ .opts = opts ,
2521
+ .total_bloom_filter_data_size = 0 ,
2522
+ .write_generation_data = (get_configured_generation_version (r ) == 2 ),
2523
+ .num_generation_data_overflows = 0 ,
2524
+ };
2515
2525
uint32_t i ;
2516
2526
int res = 0 ;
2517
2527
int replace = 0 ;
@@ -2533,32 +2543,21 @@ int write_commit_graph(struct object_directory *odb,
2533
2543
return 0 ;
2534
2544
}
2535
2545
2536
- CALLOC_ARRAY (ctx , 1 );
2537
- ctx -> r = r ;
2538
- ctx -> odb = odb ;
2539
- ctx -> append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0 ;
2540
- ctx -> report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0 ;
2541
- ctx -> split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0 ;
2542
- ctx -> opts = opts ;
2543
- ctx -> total_bloom_filter_data_size = 0 ;
2544
- ctx -> write_generation_data = (get_configured_generation_version (r ) == 2 );
2545
- ctx -> num_generation_data_overflows = 0 ;
2546
-
2547
2546
bloom_settings .hash_version = r -> settings .commit_graph_changed_paths_version ;
2548
2547
bloom_settings .bits_per_entry = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY" ,
2549
2548
bloom_settings .bits_per_entry );
2550
2549
bloom_settings .num_hashes = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES" ,
2551
2550
bloom_settings .num_hashes );
2552
2551
bloom_settings .max_changed_paths = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS" ,
2553
2552
bloom_settings .max_changed_paths );
2554
- ctx -> bloom_settings = & bloom_settings ;
2553
+ ctx . bloom_settings = & bloom_settings ;
2555
2554
2556
2555
init_topo_level_slab (& topo_levels );
2557
- ctx -> topo_levels = & topo_levels ;
2556
+ ctx . topo_levels = & topo_levels ;
2558
2557
2559
- prepare_commit_graph (ctx -> r );
2560
- if (ctx -> r -> objects -> commit_graph ) {
2561
- struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2558
+ prepare_commit_graph (ctx . r );
2559
+ if (ctx . r -> objects -> commit_graph ) {
2560
+ struct commit_graph * g = ctx . r -> objects -> commit_graph ;
2562
2561
2563
2562
while (g ) {
2564
2563
g -> topo_levels = & topo_levels ;
@@ -2567,15 +2566,15 @@ int write_commit_graph(struct object_directory *odb,
2567
2566
}
2568
2567
2569
2568
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS )
2570
- ctx -> changed_paths = 1 ;
2569
+ ctx . changed_paths = 1 ;
2571
2570
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
2572
2571
struct commit_graph * g ;
2573
2572
2574
- g = ctx -> r -> objects -> commit_graph ;
2573
+ g = ctx . r -> objects -> commit_graph ;
2575
2574
2576
2575
/* We have changed-paths already. Keep them in the next graph */
2577
2576
if (g && g -> bloom_filter_settings ) {
2578
- ctx -> changed_paths = 1 ;
2577
+ ctx . changed_paths = 1 ;
2579
2578
2580
2579
/* don't propagate the hash_version unless unspecified */
2581
2580
if (bloom_settings .hash_version == -1 )
@@ -2588,116 +2587,123 @@ int write_commit_graph(struct object_directory *odb,
2588
2587
2589
2588
bloom_settings .hash_version = bloom_settings .hash_version == 2 ? 2 : 1 ;
2590
2589
2591
- if (ctx -> split ) {
2592
- struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2590
+ if (ctx . split ) {
2591
+ struct commit_graph * g = ctx . r -> objects -> commit_graph ;
2593
2592
2594
2593
while (g ) {
2595
- ctx -> num_commit_graphs_before ++ ;
2594
+ ctx . num_commit_graphs_before ++ ;
2596
2595
g = g -> base_graph ;
2597
2596
}
2598
2597
2599
- if (ctx -> num_commit_graphs_before ) {
2600
- ALLOC_ARRAY (ctx -> commit_graph_filenames_before , ctx -> num_commit_graphs_before );
2601
- i = ctx -> num_commit_graphs_before ;
2602
- g = ctx -> r -> objects -> commit_graph ;
2598
+ if (ctx . num_commit_graphs_before ) {
2599
+ ALLOC_ARRAY (ctx . commit_graph_filenames_before , ctx . num_commit_graphs_before );
2600
+ i = ctx . num_commit_graphs_before ;
2601
+ g = ctx . r -> objects -> commit_graph ;
2603
2602
2604
2603
while (g ) {
2605
- ctx -> commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
2604
+ ctx . commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
2606
2605
g = g -> base_graph ;
2607
2606
}
2608
2607
}
2609
2608
2610
- if (ctx -> opts )
2611
- replace = ctx -> opts -> split_flags & COMMIT_GRAPH_SPLIT_REPLACE ;
2609
+ if (ctx . opts )
2610
+ replace = ctx . opts -> split_flags & COMMIT_GRAPH_SPLIT_REPLACE ;
2612
2611
}
2613
2612
2614
- ctx -> approx_nr_objects = repo_approximate_object_count (the_repository );
2613
+ ctx . approx_nr_objects = repo_approximate_object_count (the_repository );
2615
2614
2616
- if (ctx -> append && ctx -> r -> objects -> commit_graph ) {
2617
- struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2615
+ if (ctx . append && ctx . r -> objects -> commit_graph ) {
2616
+ struct commit_graph * g = ctx . r -> objects -> commit_graph ;
2618
2617
for (i = 0 ; i < g -> num_commits ; i ++ ) {
2619
2618
struct object_id oid ;
2620
2619
oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_len , i ),
2621
2620
the_repository -> hash_algo );
2622
- oid_array_append (& ctx -> oids , & oid );
2621
+ oid_array_append (& ctx . oids , & oid );
2623
2622
}
2624
2623
}
2625
2624
2626
2625
if (pack_indexes ) {
2627
- ctx -> order_by_pack = 1 ;
2628
- if ((res = fill_oids_from_packs (ctx , pack_indexes )))
2626
+ ctx . order_by_pack = 1 ;
2627
+ if ((res = fill_oids_from_packs (& ctx , pack_indexes )))
2629
2628
goto cleanup ;
2630
2629
}
2631
2630
2632
2631
if (commits ) {
2633
- if ((res = fill_oids_from_commits (ctx , commits )))
2632
+ if ((res = fill_oids_from_commits (& ctx , commits )))
2634
2633
goto cleanup ;
2635
2634
}
2636
2635
2637
2636
if (!pack_indexes && !commits ) {
2638
- ctx -> order_by_pack = 1 ;
2639
- fill_oids_from_all_packs (ctx );
2637
+ ctx . order_by_pack = 1 ;
2638
+ fill_oids_from_all_packs (& ctx );
2640
2639
}
2641
2640
2642
- close_reachable (ctx );
2641
+ close_reachable (& ctx );
2643
2642
2644
- copy_oids_to_commits (ctx );
2643
+ copy_oids_to_commits (& ctx );
2645
2644
2646
- if (ctx -> commits .nr >= GRAPH_EDGE_LAST_MASK ) {
2645
+ if (ctx . commits .nr >= GRAPH_EDGE_LAST_MASK ) {
2647
2646
error (_ ("too many commits to write graph" ));
2648
2647
res = -1 ;
2649
2648
goto cleanup ;
2650
2649
}
2651
2650
2652
- if (!ctx -> commits .nr && !replace )
2651
+ if (!ctx . commits .nr && !replace )
2653
2652
goto cleanup ;
2654
2653
2655
- if (ctx -> split ) {
2656
- split_graph_merge_strategy (ctx );
2654
+ if (ctx . split ) {
2655
+ split_graph_merge_strategy (& ctx );
2657
2656
2658
2657
if (!replace )
2659
- merge_commit_graphs (ctx );
2658
+ merge_commit_graphs (& ctx );
2660
2659
} else
2661
- ctx -> num_commit_graphs_after = 1 ;
2660
+ ctx . num_commit_graphs_after = 1 ;
2662
2661
2663
- ctx -> trust_generation_numbers = validate_mixed_generation_chain (ctx -> r -> objects -> commit_graph );
2662
+ ctx . trust_generation_numbers = validate_mixed_generation_chain (ctx . r -> objects -> commit_graph );
2664
2663
2665
- compute_topological_levels (ctx );
2666
- if (ctx -> write_generation_data )
2667
- compute_generation_numbers (ctx );
2664
+ compute_topological_levels (& ctx );
2665
+ if (ctx . write_generation_data )
2666
+ compute_generation_numbers (& ctx );
2668
2667
2669
- if (ctx -> changed_paths )
2670
- compute_bloom_filters (ctx );
2668
+ if (ctx . changed_paths )
2669
+ compute_bloom_filters (& ctx );
2671
2670
2672
- res = write_commit_graph_file (ctx );
2671
+ res = write_commit_graph_file (& ctx );
2673
2672
2674
- if (ctx -> changed_paths )
2673
+ if (ctx . changed_paths )
2675
2674
deinit_bloom_filters ();
2676
2675
2677
- if (ctx -> split )
2678
- mark_commit_graphs (ctx );
2676
+ if (ctx . split )
2677
+ mark_commit_graphs (& ctx );
2679
2678
2680
- expire_commit_graphs (ctx );
2679
+ expire_commit_graphs (& ctx );
2681
2680
2682
2681
cleanup :
2683
- free (ctx -> graph_name );
2684
- free (ctx -> base_graph_name );
2685
- free (ctx -> commits .list );
2686
- oid_array_clear (& ctx -> oids );
2682
+ free (ctx . graph_name );
2683
+ free (ctx . base_graph_name );
2684
+ free (ctx . commits .list );
2685
+ oid_array_clear (& ctx . oids );
2687
2686
clear_topo_level_slab (& topo_levels );
2688
2687
2689
- for (i = 0 ; i < ctx -> num_commit_graphs_before ; i ++ )
2690
- free (ctx -> commit_graph_filenames_before [i ]);
2691
- free (ctx -> commit_graph_filenames_before );
2688
+ if (ctx .r -> objects -> commit_graph ) {
2689
+ struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2692
2690
2693
- for (i = 0 ; i < ctx -> num_commit_graphs_after ; i ++ ) {
2694
- free (ctx -> commit_graph_filenames_after [i ]);
2695
- free (ctx -> commit_graph_hash_after [i ]);
2691
+ while (g ) {
2692
+ g -> topo_levels = NULL ;
2693
+ g = g -> base_graph ;
2694
+ }
2696
2695
}
2697
- free (ctx -> commit_graph_filenames_after );
2698
- free (ctx -> commit_graph_hash_after );
2699
2696
2700
- free (ctx );
2697
+ for (i = 0 ; i < ctx .num_commit_graphs_before ; i ++ )
2698
+ free (ctx .commit_graph_filenames_before [i ]);
2699
+ free (ctx .commit_graph_filenames_before );
2700
+
2701
+ for (i = 0 ; i < ctx .num_commit_graphs_after ; i ++ ) {
2702
+ free (ctx .commit_graph_filenames_after [i ]);
2703
+ free (ctx .commit_graph_hash_after [i ]);
2704
+ }
2705
+ free (ctx .commit_graph_filenames_after );
2706
+ free (ctx .commit_graph_hash_after );
2701
2707
2702
2708
return res ;
2703
2709
}
0 commit comments