@@ -735,7 +735,7 @@ struct commit_graph *read_commit_graph_one(struct odb_source *source)
735
735
* On the first invocation, this function attempts to load the commit
736
736
* graph if the repository is configured to have one.
737
737
*/
738
- static int prepare_commit_graph (struct repository * r )
738
+ static struct commit_graph * prepare_commit_graph (struct repository * r )
739
739
{
740
740
struct odb_source * source ;
741
741
@@ -747,10 +747,10 @@ static int prepare_commit_graph(struct repository *r)
747
747
* we want to disable even an already-loaded graph file.
748
748
*/
749
749
if (!r -> gitdir || r -> commit_graph_disabled )
750
- return 0 ;
750
+ return NULL ;
751
751
752
752
if (r -> objects -> commit_graph_attempted )
753
- return !! r -> objects -> commit_graph ;
753
+ return r -> objects -> commit_graph ;
754
754
r -> objects -> commit_graph_attempted = 1 ;
755
755
756
756
prepare_repo_settings (r );
@@ -763,10 +763,10 @@ static int prepare_commit_graph(struct repository *r)
763
763
* so that commit graph loading is not attempted again for this
764
764
* repository.)
765
765
*/
766
- return 0 ;
766
+ return NULL ;
767
767
768
768
if (!commit_graph_compatible (r ))
769
- return 0 ;
769
+ return NULL ;
770
770
771
771
odb_prepare_alternates (r -> objects );
772
772
for (source = r -> objects -> sources ; source ; source = source -> next ) {
@@ -775,20 +775,17 @@ static int prepare_commit_graph(struct repository *r)
775
775
break ;
776
776
}
777
777
778
- return !! r -> objects -> commit_graph ;
778
+ return r -> objects -> commit_graph ;
779
779
}
780
780
781
781
int generation_numbers_enabled (struct repository * r )
782
782
{
783
783
uint32_t first_generation ;
784
784
struct commit_graph * g ;
785
- if (!prepare_commit_graph (r ))
786
- return 0 ;
787
-
788
- g = r -> objects -> commit_graph ;
789
785
790
- if (!g -> num_commits )
791
- return 0 ;
786
+ g = prepare_commit_graph (r );
787
+ if (!g || !g -> num_commits )
788
+ return 0 ;
792
789
793
790
first_generation = get_be32 (g -> chunk_commit_data +
794
791
g -> hash_algo -> rawsz + 8 ) >> 2 ;
@@ -799,12 +796,9 @@ int generation_numbers_enabled(struct repository *r)
799
796
int corrected_commit_dates_enabled (struct repository * r )
800
797
{
801
798
struct commit_graph * g ;
802
- if (!prepare_commit_graph (r ))
803
- return 0 ;
804
-
805
- g = r -> objects -> commit_graph ;
806
799
807
- if (!g -> num_commits )
800
+ g = prepare_commit_graph (r );
801
+ if (!g || !g -> num_commits )
808
802
return 0 ;
809
803
810
804
return g -> read_generation_data ;
@@ -1014,26 +1008,32 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
1014
1008
}
1015
1009
}
1016
1010
1017
- int repo_find_commit_pos_in_graph (struct repository * r , struct commit * c ,
1018
- uint32_t * pos )
1011
+ struct commit_graph * repo_find_commit_pos_in_graph (struct repository * r ,
1012
+ struct commit * c ,
1013
+ uint32_t * pos )
1019
1014
{
1020
- if (!prepare_commit_graph (r ))
1021
- return 0 ;
1022
- return find_commit_pos_in_graph (c , r -> objects -> commit_graph , pos );
1015
+ struct commit_graph * g = prepare_commit_graph (r );
1016
+ if (!g )
1017
+ return NULL ;
1018
+ if (!find_commit_pos_in_graph (c , g , pos ))
1019
+ return NULL ;
1020
+ return g ;
1023
1021
}
1024
1022
1025
1023
struct commit * lookup_commit_in_graph (struct repository * repo , const struct object_id * id )
1026
1024
{
1027
1025
static int commit_graph_paranoia = -1 ;
1026
+ struct commit_graph * g ;
1028
1027
struct commit * commit ;
1029
1028
uint32_t pos ;
1030
1029
1031
1030
if (commit_graph_paranoia == -1 )
1032
1031
commit_graph_paranoia = git_env_bool (GIT_COMMIT_GRAPH_PARANOIA , 0 );
1033
1032
1034
- if (!prepare_commit_graph (repo ))
1033
+ g = prepare_commit_graph (repo );
1034
+ if (!g )
1035
1035
return NULL ;
1036
- if (!search_commit_pos_in_graph (id , repo -> objects -> commit_graph , & pos ))
1036
+ if (!search_commit_pos_in_graph (id , g , & pos ))
1037
1037
return NULL ;
1038
1038
if (commit_graph_paranoia && !odb_has_object (repo -> objects , id , 0 ))
1039
1039
return NULL ;
@@ -1044,7 +1044,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
1044
1044
if (commit -> object .parsed )
1045
1045
return commit ;
1046
1046
1047
- if (!fill_commit_in_graph (commit , repo -> objects -> commit_graph , pos ))
1047
+ if (!fill_commit_in_graph (commit , g , pos ))
1048
1048
return NULL ;
1049
1049
1050
1050
return commit ;
@@ -1067,23 +1067,28 @@ static int parse_commit_in_graph_one(struct commit_graph *g,
1067
1067
int parse_commit_in_graph (struct repository * r , struct commit * item )
1068
1068
{
1069
1069
static int checked_env = 0 ;
1070
+ struct commit_graph * g ;
1070
1071
1071
1072
if (!checked_env &&
1072
1073
git_env_bool (GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE , 0 ))
1073
1074
die ("dying as requested by the '%s' variable on commit-graph parse!" ,
1074
1075
GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE );
1075
1076
checked_env = 1 ;
1076
1077
1077
- if (!prepare_commit_graph (r ))
1078
+ g = prepare_commit_graph (r );
1079
+ if (!g )
1078
1080
return 0 ;
1079
- return parse_commit_in_graph_one (r -> objects -> commit_graph , item );
1081
+ return parse_commit_in_graph_one (g , item );
1080
1082
}
1081
1083
1082
1084
void load_commit_graph_info (struct repository * r , struct commit * item )
1083
1085
{
1086
+ struct commit_graph * g ;
1084
1087
uint32_t pos ;
1085
- if (repo_find_commit_pos_in_graph (r , item , & pos ))
1086
- fill_commit_graph_info (item , r -> objects -> commit_graph , pos );
1088
+
1089
+ g = repo_find_commit_pos_in_graph (r , item , & pos );
1090
+ if (g )
1091
+ fill_commit_graph_info (item , g , pos );
1087
1092
}
1088
1093
1089
1094
static struct tree * load_tree_for_commit (struct commit_graph * g ,
@@ -2226,7 +2231,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2226
2231
return 0 ;
2227
2232
}
2228
2233
2229
- static void split_graph_merge_strategy (struct write_commit_graph_context * ctx )
2234
+ static void split_graph_merge_strategy (struct write_commit_graph_context * ctx ,
2235
+ struct commit_graph * graph_to_merge )
2230
2236
{
2231
2237
struct commit_graph * g ;
2232
2238
uint32_t num_commits ;
@@ -2245,7 +2251,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2245
2251
flags = ctx -> opts -> split_flags ;
2246
2252
}
2247
2253
2248
- g = ctx -> r -> objects -> commit_graph ;
2254
+ g = graph_to_merge ;
2249
2255
num_commits = ctx -> commits .nr ;
2250
2256
if (flags == COMMIT_GRAPH_SPLIT_REPLACE )
2251
2257
ctx -> num_commit_graphs_after = 1 ;
@@ -2297,7 +2303,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2297
2303
ctx -> commit_graph_filenames_after [i ] = xstrdup (ctx -> commit_graph_filenames_before [i ]);
2298
2304
2299
2305
i = ctx -> num_commit_graphs_before - 1 ;
2300
- g = ctx -> r -> objects -> commit_graph ;
2306
+ g = graph_to_merge ;
2301
2307
2302
2308
while (g ) {
2303
2309
if (i < ctx -> num_commit_graphs_after )
@@ -2395,9 +2401,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
2395
2401
stop_progress (& ctx -> progress );
2396
2402
}
2397
2403
2398
- static void merge_commit_graphs (struct write_commit_graph_context * ctx )
2404
+ static void merge_commit_graphs (struct write_commit_graph_context * ctx ,
2405
+ struct commit_graph * g )
2399
2406
{
2400
- struct commit_graph * g = ctx -> r -> objects -> commit_graph ;
2401
2407
uint32_t current_graph_number = ctx -> num_commit_graphs_before ;
2402
2408
2403
2409
while (g && current_graph_number >= ctx -> num_commit_graphs_after ) {
@@ -2524,6 +2530,7 @@ int write_commit_graph(struct odb_source *source,
2524
2530
int replace = 0 ;
2525
2531
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS ;
2526
2532
struct topo_level_slab topo_levels ;
2533
+ struct commit_graph * g ;
2527
2534
2528
2535
prepare_repo_settings (r );
2529
2536
if (!r -> settings .core_commit_graph ) {
@@ -2552,23 +2559,13 @@ int write_commit_graph(struct odb_source *source,
2552
2559
init_topo_level_slab (& topo_levels );
2553
2560
ctx .topo_levels = & topo_levels ;
2554
2561
2555
- prepare_commit_graph (ctx .r );
2556
- if (ctx .r -> objects -> commit_graph ) {
2557
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2558
-
2559
- while (g ) {
2560
- g -> topo_levels = & topo_levels ;
2561
- g = g -> base_graph ;
2562
- }
2563
- }
2562
+ g = prepare_commit_graph (ctx .r );
2563
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2564
+ g -> topo_levels = & topo_levels ;
2564
2565
2565
2566
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS )
2566
2567
ctx .changed_paths = 1 ;
2567
2568
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
2568
- struct commit_graph * g ;
2569
-
2570
- g = ctx .r -> objects -> commit_graph ;
2571
-
2572
2569
/* We have changed-paths already. Keep them in the next graph */
2573
2570
if (g && g -> bloom_filter_settings ) {
2574
2571
ctx .changed_paths = 1 ;
@@ -2585,22 +2582,15 @@ int write_commit_graph(struct odb_source *source,
2585
2582
bloom_settings .hash_version = bloom_settings .hash_version == 2 ? 2 : 1 ;
2586
2583
2587
2584
if (ctx .split ) {
2588
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2589
-
2590
- while (g ) {
2585
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2591
2586
ctx .num_commit_graphs_before ++ ;
2592
- g = g -> base_graph ;
2593
- }
2594
2587
2595
2588
if (ctx .num_commit_graphs_before ) {
2596
2589
ALLOC_ARRAY (ctx .commit_graph_filenames_before , ctx .num_commit_graphs_before );
2597
2590
i = ctx .num_commit_graphs_before ;
2598
- g = ctx .r -> objects -> commit_graph ;
2599
2591
2600
- while (g ) {
2601
- ctx .commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
2602
- g = g -> base_graph ;
2603
- }
2592
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2593
+ ctx .commit_graph_filenames_before [-- i ] = xstrdup (chain -> filename );
2604
2594
}
2605
2595
2606
2596
if (ctx .opts )
@@ -2609,8 +2599,7 @@ int write_commit_graph(struct odb_source *source,
2609
2599
2610
2600
ctx .approx_nr_objects = repo_approximate_object_count (r );
2611
2601
2612
- if (ctx .append && ctx .r -> objects -> commit_graph ) {
2613
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2602
+ if (ctx .append && g ) {
2614
2603
for (i = 0 ; i < g -> num_commits ; i ++ ) {
2615
2604
struct object_id oid ;
2616
2605
oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
@@ -2649,14 +2638,15 @@ int write_commit_graph(struct odb_source *source,
2649
2638
goto cleanup ;
2650
2639
2651
2640
if (ctx .split ) {
2652
- split_graph_merge_strategy (& ctx );
2641
+ split_graph_merge_strategy (& ctx , g );
2653
2642
2654
2643
if (!replace )
2655
- merge_commit_graphs (& ctx );
2656
- } else
2644
+ merge_commit_graphs (& ctx , g );
2645
+ } else {
2657
2646
ctx .num_commit_graphs_after = 1 ;
2647
+ }
2658
2648
2659
- ctx .trust_generation_numbers = validate_mixed_generation_chain (ctx . r -> objects -> commit_graph );
2649
+ ctx .trust_generation_numbers = validate_mixed_generation_chain (g );
2660
2650
2661
2651
compute_topological_levels (& ctx );
2662
2652
if (ctx .write_generation_data )
0 commit comments