@@ -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
785
788
- g = r -> objects -> commit_graph ;
789
-
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
799
805
- g = r -> objects -> commit_graph ;
806
-
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 ;
@@ -1012,23 +1006,26 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
1012
1006
int repo_find_commit_pos_in_graph (struct repository * r , struct commit * c ,
1013
1007
uint32_t * pos )
1014
1008
{
1015
- if (!prepare_commit_graph (r ))
1009
+ struct commit_graph * g = prepare_commit_graph (r );
1010
+ if (!g )
1016
1011
return 0 ;
1017
- return find_commit_pos_in_graph (c , r -> objects -> commit_graph , pos );
1012
+ return find_commit_pos_in_graph (c , g , pos );
1018
1013
}
1019
1014
1020
1015
struct commit * lookup_commit_in_graph (struct repository * repo , const struct object_id * id )
1021
1016
{
1022
1017
static int commit_graph_paranoia = -1 ;
1018
+ struct commit_graph * g ;
1023
1019
struct commit * commit ;
1024
1020
uint32_t pos ;
1025
1021
1026
1022
if (commit_graph_paranoia == -1 )
1027
1023
commit_graph_paranoia = git_env_bool (GIT_COMMIT_GRAPH_PARANOIA , 0 );
1028
1024
1029
- if (!prepare_commit_graph (repo ))
1025
+ g = prepare_commit_graph (repo );
1026
+ if (!g )
1030
1027
return NULL ;
1031
- if (!search_commit_pos_in_graph (id , repo -> objects -> commit_graph , & pos ))
1028
+ if (!search_commit_pos_in_graph (id , g , & pos ))
1032
1029
return NULL ;
1033
1030
if (commit_graph_paranoia && !odb_has_object (repo -> objects , id , 0 ))
1034
1031
return NULL ;
@@ -1039,7 +1036,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
1039
1036
if (commit -> object .parsed )
1040
1037
return commit ;
1041
1038
1042
- if (!fill_commit_in_graph (commit , repo -> objects -> commit_graph , pos ))
1039
+ if (!fill_commit_in_graph (commit , g , pos ))
1043
1040
return NULL ;
1044
1041
1045
1042
return commit ;
@@ -1062,16 +1059,18 @@ static int parse_commit_in_graph_one(struct commit_graph *g,
1062
1059
int parse_commit_in_graph (struct repository * r , struct commit * item )
1063
1060
{
1064
1061
static int checked_env = 0 ;
1062
+ struct commit_graph * g ;
1065
1063
1066
1064
if (!checked_env &&
1067
1065
git_env_bool (GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE , 0 ))
1068
1066
die ("dying as requested by the '%s' variable on commit-graph parse!" ,
1069
1067
GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE );
1070
1068
checked_env = 1 ;
1071
1069
1072
- if (!prepare_commit_graph (r ))
1070
+ g = prepare_commit_graph (r );
1071
+ if (!g )
1073
1072
return 0 ;
1074
- return parse_commit_in_graph_one (r -> objects -> commit_graph , item );
1073
+ return parse_commit_in_graph_one (g , item );
1075
1074
}
1076
1075
1077
1076
void load_commit_graph_info (struct repository * r , struct commit * item )
@@ -2519,6 +2518,7 @@ int write_commit_graph(struct odb_source *source,
2519
2518
int replace = 0 ;
2520
2519
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS ;
2521
2520
struct topo_level_slab topo_levels ;
2521
+ struct commit_graph * g ;
2522
2522
2523
2523
prepare_repo_settings (r );
2524
2524
if (!r -> settings .core_commit_graph ) {
@@ -2547,23 +2547,13 @@ int write_commit_graph(struct odb_source *source,
2547
2547
init_topo_level_slab (& topo_levels );
2548
2548
ctx .topo_levels = & topo_levels ;
2549
2549
2550
- prepare_commit_graph (ctx .r );
2551
- if (ctx .r -> objects -> commit_graph ) {
2552
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2553
-
2554
- while (g ) {
2555
- g -> topo_levels = & topo_levels ;
2556
- g = g -> base_graph ;
2557
- }
2558
- }
2550
+ g = prepare_commit_graph (ctx .r );
2551
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2552
+ g -> topo_levels = & topo_levels ;
2559
2553
2560
2554
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS )
2561
2555
ctx .changed_paths = 1 ;
2562
2556
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
2563
- struct commit_graph * g ;
2564
-
2565
- g = ctx .r -> objects -> commit_graph ;
2566
-
2567
2557
/* We have changed-paths already. Keep them in the next graph */
2568
2558
if (g && g -> bloom_filter_settings ) {
2569
2559
ctx .changed_paths = 1 ;
@@ -2580,22 +2570,15 @@ int write_commit_graph(struct odb_source *source,
2580
2570
bloom_settings .hash_version = bloom_settings .hash_version == 2 ? 2 : 1 ;
2581
2571
2582
2572
if (ctx .split ) {
2583
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2584
-
2585
- while (g ) {
2573
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2586
2574
ctx .num_commit_graphs_before ++ ;
2587
- g = g -> base_graph ;
2588
- }
2589
2575
2590
2576
if (ctx .num_commit_graphs_before ) {
2591
2577
ALLOC_ARRAY (ctx .commit_graph_filenames_before , ctx .num_commit_graphs_before );
2592
2578
i = ctx .num_commit_graphs_before ;
2593
- g = ctx .r -> objects -> commit_graph ;
2594
2579
2595
- while (g ) {
2596
- ctx .commit_graph_filenames_before [-- i ] = xstrdup (g -> filename );
2597
- g = g -> base_graph ;
2598
- }
2580
+ for (struct commit_graph * chain = g ; chain ; chain = chain -> base_graph )
2581
+ ctx .commit_graph_filenames_before [-- i ] = xstrdup (chain -> filename );
2599
2582
}
2600
2583
2601
2584
if (ctx .opts )
@@ -2604,8 +2587,7 @@ int write_commit_graph(struct odb_source *source,
2604
2587
2605
2588
ctx .approx_nr_objects = repo_approximate_object_count (r );
2606
2589
2607
- if (ctx .append && ctx .r -> objects -> commit_graph ) {
2608
- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2590
+ if (ctx .append && g ) {
2609
2591
for (i = 0 ; i < g -> num_commits ; i ++ ) {
2610
2592
struct object_id oid ;
2611
2593
oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
@@ -2651,7 +2633,7 @@ int write_commit_graph(struct odb_source *source,
2651
2633
} else
2652
2634
ctx .num_commit_graphs_after = 1 ;
2653
2635
2654
- ctx .trust_generation_numbers = validate_mixed_generation_chain (ctx . r -> objects -> commit_graph );
2636
+ ctx .trust_generation_numbers = validate_mixed_generation_chain (g );
2655
2637
2656
2638
compute_topological_levels (& ctx );
2657
2639
if (ctx .write_generation_data )
0 commit comments