@@ -2511,7 +2511,17 @@ int write_commit_graph(struct object_directory *odb,
25112511 const struct commit_graph_opts * opts )
25122512{
25132513 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+ };
25152525 uint32_t i ;
25162526 int res = 0 ;
25172527 int replace = 0 ;
@@ -2533,32 +2543,21 @@ int write_commit_graph(struct object_directory *odb,
25332543 return 0 ;
25342544 }
25352545
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-
25472546 bloom_settings .hash_version = r -> settings .commit_graph_changed_paths_version ;
25482547 bloom_settings .bits_per_entry = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY" ,
25492548 bloom_settings .bits_per_entry );
25502549 bloom_settings .num_hashes = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES" ,
25512550 bloom_settings .num_hashes );
25522551 bloom_settings .max_changed_paths = git_env_ulong ("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS" ,
25532552 bloom_settings .max_changed_paths );
2554- ctx -> bloom_settings = & bloom_settings ;
2553+ ctx . bloom_settings = & bloom_settings ;
25552554
25562555 init_topo_level_slab (& topo_levels );
2557- ctx -> topo_levels = & topo_levels ;
2556+ ctx . topo_levels = & topo_levels ;
25582557
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 ;
25622561
25632562 while (g ) {
25642563 g -> topo_levels = & topo_levels ;
@@ -2567,15 +2566,15 @@ int write_commit_graph(struct object_directory *odb,
25672566 }
25682567
25692568 if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS )
2570- ctx -> changed_paths = 1 ;
2569+ ctx . changed_paths = 1 ;
25712570 if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
25722571 struct commit_graph * g ;
25732572
2574- g = ctx -> r -> objects -> commit_graph ;
2573+ g = ctx . r -> objects -> commit_graph ;
25752574
25762575 /* We have changed-paths already. Keep them in the next graph */
25772576 if (g && g -> bloom_filter_settings ) {
2578- ctx -> changed_paths = 1 ;
2577+ ctx . changed_paths = 1 ;
25792578
25802579 /* don't propagate the hash_version unless unspecified */
25812580 if (bloom_settings .hash_version == -1 )
@@ -2588,116 +2587,123 @@ int write_commit_graph(struct object_directory *odb,
25882587
25892588 bloom_settings .hash_version = bloom_settings .hash_version == 2 ? 2 : 1 ;
25902589
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 ;
25932592
25942593 while (g ) {
2595- ctx -> num_commit_graphs_before ++ ;
2594+ ctx . num_commit_graphs_before ++ ;
25962595 g = g -> base_graph ;
25972596 }
25982597
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 ;
26032602
26042603 while (g ) {
2605- ctx -> commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
2604+ ctx . commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
26062605 g = g -> base_graph ;
26072606 }
26082607 }
26092608
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 ;
26122611 }
26132612
2614- ctx -> approx_nr_objects = repo_approximate_object_count (the_repository );
2613+ ctx . approx_nr_objects = repo_approximate_object_count (the_repository );
26152614
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 ;
26182617 for (i = 0 ; i < g -> num_commits ; i ++ ) {
26192618 struct object_id oid ;
26202619 oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_len , i ),
26212620 the_repository -> hash_algo );
2622- oid_array_append (& ctx -> oids , & oid );
2621+ oid_array_append (& ctx . oids , & oid );
26232622 }
26242623 }
26252624
26262625 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 )))
26292628 goto cleanup ;
26302629 }
26312630
26322631 if (commits ) {
2633- if ((res = fill_oids_from_commits (ctx , commits )))
2632+ if ((res = fill_oids_from_commits (& ctx , commits )))
26342633 goto cleanup ;
26352634 }
26362635
26372636 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 );
26402639 }
26412640
2642- close_reachable (ctx );
2641+ close_reachable (& ctx );
26432642
2644- copy_oids_to_commits (ctx );
2643+ copy_oids_to_commits (& ctx );
26452644
2646- if (ctx -> commits .nr >= GRAPH_EDGE_LAST_MASK ) {
2645+ if (ctx . commits .nr >= GRAPH_EDGE_LAST_MASK ) {
26472646 error (_ ("too many commits to write graph" ));
26482647 res = -1 ;
26492648 goto cleanup ;
26502649 }
26512650
2652- if (!ctx -> commits .nr && !replace )
2651+ if (!ctx . commits .nr && !replace )
26532652 goto cleanup ;
26542653
2655- if (ctx -> split ) {
2656- split_graph_merge_strategy (ctx );
2654+ if (ctx . split ) {
2655+ split_graph_merge_strategy (& ctx );
26572656
26582657 if (!replace )
2659- merge_commit_graphs (ctx );
2658+ merge_commit_graphs (& ctx );
26602659 } else
2661- ctx -> num_commit_graphs_after = 1 ;
2660+ ctx . num_commit_graphs_after = 1 ;
26622661
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 );
26642663
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 );
26682667
2669- if (ctx -> changed_paths )
2670- compute_bloom_filters (ctx );
2668+ if (ctx . changed_paths )
2669+ compute_bloom_filters (& ctx );
26712670
2672- res = write_commit_graph_file (ctx );
2671+ res = write_commit_graph_file (& ctx );
26732672
2674- if (ctx -> changed_paths )
2673+ if (ctx . changed_paths )
26752674 deinit_bloom_filters ();
26762675
2677- if (ctx -> split )
2678- mark_commit_graphs (ctx );
2676+ if (ctx . split )
2677+ mark_commit_graphs (& ctx );
26792678
2680- expire_commit_graphs (ctx );
2679+ expire_commit_graphs (& ctx );
26812680
26822681cleanup :
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 );
26872686 clear_topo_level_slab (& topo_levels );
26882687
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 ;
26922690
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+ }
26962695 }
2697- free (ctx -> commit_graph_filenames_after );
2698- free (ctx -> commit_graph_hash_after );
26992696
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 );
27012707
27022708 return res ;
27032709}
0 commit comments