@@ -735,7 +735,7 @@ struct commit_graph *read_commit_graph_one(struct odb_source *source)
735735 * On the first invocation, this function attempts to load the commit
736736 * graph if the repository is configured to have one.
737737 */
738- static int prepare_commit_graph (struct repository * r )
738+ static struct commit_graph * prepare_commit_graph (struct repository * r )
739739{
740740 struct odb_source * source ;
741741
@@ -747,10 +747,10 @@ static int prepare_commit_graph(struct repository *r)
747747 * we want to disable even an already-loaded graph file.
748748 */
749749 if (!r -> gitdir || r -> commit_graph_disabled )
750- return 0 ;
750+ return NULL ;
751751
752752 if (r -> objects -> commit_graph_attempted )
753- return !! r -> objects -> commit_graph ;
753+ return r -> objects -> commit_graph ;
754754 r -> objects -> commit_graph_attempted = 1 ;
755755
756756 prepare_repo_settings (r );
@@ -763,10 +763,10 @@ static int prepare_commit_graph(struct repository *r)
763763 * so that commit graph loading is not attempted again for this
764764 * repository.)
765765 */
766- return 0 ;
766+ return NULL ;
767767
768768 if (!commit_graph_compatible (r ))
769- return 0 ;
769+ return NULL ;
770770
771771 odb_prepare_alternates (r -> objects );
772772 for (source = r -> objects -> sources ; source ; source = source -> next ) {
@@ -775,20 +775,17 @@ static int prepare_commit_graph(struct repository *r)
775775 break ;
776776 }
777777
778- return !! r -> objects -> commit_graph ;
778+ return r -> objects -> commit_graph ;
779779}
780780
781781int generation_numbers_enabled (struct repository * r )
782782{
783783 uint32_t first_generation ;
784784 struct commit_graph * g ;
785- if (!prepare_commit_graph (r ))
786- return 0 ;
787785
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 ;
792789
793790 first_generation = get_be32 (g -> chunk_commit_data +
794791 g -> hash_algo -> rawsz + 8 ) >> 2 ;
@@ -799,12 +796,9 @@ int generation_numbers_enabled(struct repository *r)
799796int corrected_commit_dates_enabled (struct repository * r )
800797{
801798 struct commit_graph * g ;
802- if (!prepare_commit_graph (r ))
803- return 0 ;
804799
805- g = r -> objects -> commit_graph ;
806-
807- if (!g -> num_commits )
800+ g = prepare_commit_graph (r );
801+ if (!g || !g -> num_commits )
808802 return 0 ;
809803
810804 return g -> read_generation_data ;
@@ -1012,23 +1006,26 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
10121006int repo_find_commit_pos_in_graph (struct repository * r , struct commit * c ,
10131007 uint32_t * pos )
10141008{
1015- if (!prepare_commit_graph (r ))
1009+ struct commit_graph * g = prepare_commit_graph (r );
1010+ if (!g )
10161011 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 );
10181013}
10191014
10201015struct commit * lookup_commit_in_graph (struct repository * repo , const struct object_id * id )
10211016{
10221017 static int commit_graph_paranoia = -1 ;
1018+ struct commit_graph * g ;
10231019 struct commit * commit ;
10241020 uint32_t pos ;
10251021
10261022 if (commit_graph_paranoia == -1 )
10271023 commit_graph_paranoia = git_env_bool (GIT_COMMIT_GRAPH_PARANOIA , 0 );
10281024
1029- if (!prepare_commit_graph (repo ))
1025+ g = prepare_commit_graph (repo );
1026+ if (!g )
10301027 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 ))
10321029 return NULL ;
10331030 if (commit_graph_paranoia && !odb_has_object (repo -> objects , id , 0 ))
10341031 return NULL ;
@@ -1039,7 +1036,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
10391036 if (commit -> object .parsed )
10401037 return commit ;
10411038
1042- if (!fill_commit_in_graph (commit , repo -> objects -> commit_graph , pos ))
1039+ if (!fill_commit_in_graph (commit , g , pos ))
10431040 return NULL ;
10441041
10451042 return commit ;
@@ -1062,16 +1059,18 @@ static int parse_commit_in_graph_one(struct commit_graph *g,
10621059int parse_commit_in_graph (struct repository * r , struct commit * item )
10631060{
10641061 static int checked_env = 0 ;
1062+ struct commit_graph * g ;
10651063
10661064 if (!checked_env &&
10671065 git_env_bool (GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE , 0 ))
10681066 die ("dying as requested by the '%s' variable on commit-graph parse!" ,
10691067 GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE );
10701068 checked_env = 1 ;
10711069
1072- if (!prepare_commit_graph (r ))
1070+ g = prepare_commit_graph (r );
1071+ if (!g )
10731072 return 0 ;
1074- return parse_commit_in_graph_one (r -> objects -> commit_graph , item );
1073+ return parse_commit_in_graph_one (g , item );
10751074}
10761075
10771076void load_commit_graph_info (struct repository * r , struct commit * item )
@@ -2519,6 +2518,7 @@ int write_commit_graph(struct odb_source *source,
25192518 int replace = 0 ;
25202519 struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS ;
25212520 struct topo_level_slab topo_levels ;
2521+ struct commit_graph * g ;
25222522
25232523 prepare_repo_settings (r );
25242524 if (!r -> settings .core_commit_graph ) {
@@ -2547,23 +2547,13 @@ int write_commit_graph(struct odb_source *source,
25472547 init_topo_level_slab (& topo_levels );
25482548 ctx .topo_levels = & topo_levels ;
25492549
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 ;
25592553
25602554 if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS )
25612555 ctx .changed_paths = 1 ;
25622556 if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS )) {
2563- struct commit_graph * g ;
2564-
2565- g = ctx .r -> objects -> commit_graph ;
2566-
25672557 /* We have changed-paths already. Keep them in the next graph */
25682558 if (g && g -> bloom_filter_settings ) {
25692559 ctx .changed_paths = 1 ;
@@ -2580,22 +2570,15 @@ int write_commit_graph(struct odb_source *source,
25802570 bloom_settings .hash_version = bloom_settings .hash_version == 2 ? 2 : 1 ;
25812571
25822572 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 )
25862574 ctx .num_commit_graphs_before ++ ;
2587- g = g -> base_graph ;
2588- }
25892575
25902576 if (ctx .num_commit_graphs_before ) {
25912577 ALLOC_ARRAY (ctx .commit_graph_filenames_before , ctx .num_commit_graphs_before );
25922578 i = ctx .num_commit_graphs_before ;
2593- g = ctx .r -> objects -> commit_graph ;
25942579
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 );
25992582 }
26002583
26012584 if (ctx .opts )
@@ -2604,8 +2587,7 @@ int write_commit_graph(struct odb_source *source,
26042587
26052588 ctx .approx_nr_objects = repo_approximate_object_count (r );
26062589
2607- if (ctx .append && ctx .r -> objects -> commit_graph ) {
2608- struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2590+ if (ctx .append && g ) {
26092591 for (i = 0 ; i < g -> num_commits ; i ++ ) {
26102592 struct object_id oid ;
26112593 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,
26512633 } else
26522634 ctx .num_commit_graphs_after = 1 ;
26532635
2654- ctx .trust_generation_numbers = validate_mixed_generation_chain (ctx . r -> objects -> commit_graph );
2636+ ctx .trust_generation_numbers = validate_mixed_generation_chain (g );
26552637
26562638 compute_topological_levels (& ctx );
26572639 if (ctx .write_generation_data )
0 commit comments