1- #define USE_THE_REPOSITORY_VARIABLE
21#define DISABLE_SIGN_COMPARE_WARNINGS
32
43#include "git-compat-util.h"
2928#include "tree.h"
3029#include "chunk-format.h"
3130
32- void git_test_write_commit_graph_or_die (void )
31+ void git_test_write_commit_graph_or_die (struct odb_source * source )
3332{
3433 int flags = 0 ;
3534 if (!git_env_bool (GIT_TEST_COMMIT_GRAPH , 0 ))
@@ -38,8 +37,7 @@ void git_test_write_commit_graph_or_die(void)
3837 if (git_env_bool (GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS , 0 ))
3938 flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS ;
4039
41- if (write_commit_graph_reachable (the_repository -> objects -> sources ,
42- flags , NULL ))
40+ if (write_commit_graph_reachable (source , flags , NULL ))
4341 die ("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH" );
4442}
4543
@@ -597,7 +595,7 @@ static int add_graph_to_chain(struct commit_graph *g,
597595 if (!cur_g ||
598596 !oideq (& oids [n ], & cur_g -> oid ) ||
599597 !hasheq (oids [n ].hash , g -> chunk_base_graphs + st_mult (g -> hash_algo -> rawsz , n ),
600- the_repository -> hash_algo )) {
598+ g -> hash_algo )) {
601599 warning (_ ("commit-graph chain does not match" ));
602600 return 0 ;
603601 }
@@ -666,7 +664,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
666664 if (strbuf_getline_lf (& line , fp ) == EOF )
667665 break ;
668666
669- if (get_oid_hex (line .buf , & oids [i ])) {
667+ if (get_oid_hex_algop (line .buf , & oids [i ], r -> hash_algo )) {
670668 warning (_ ("invalid commit-graph chain: line '%s' not a hash" ),
671669 line .buf );
672670 valid = 0 ;
@@ -752,7 +750,7 @@ static void prepare_commit_graph_one(struct repository *r,
752750 * Return 1 if commit_graph is non-NULL, and 0 otherwise.
753751 *
754752 * On the first invocation, this function attempts to load the commit
755- * graph if the_repository is configured to have one.
753+ * graph if the repository is configured to have one.
756754 */
757755static int prepare_commit_graph (struct repository * r )
758756{
@@ -873,7 +871,7 @@ static void load_oid_from_graph(struct commit_graph *g,
873871 lex_index = pos - g -> num_commits_in_base ;
874872
875873 oidread (oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , lex_index ),
876- the_repository -> hash_algo );
874+ g -> hash_algo );
877875}
878876
879877static struct commit_list * * insert_parent_or_die (struct repository * r ,
@@ -1116,7 +1114,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
11161114 st_mult (graph_data_width (g -> hash_algo ),
11171115 graph_pos - g -> num_commits_in_base );
11181116
1119- oidread (& oid , commit_data , the_repository -> hash_algo );
1117+ oidread (& oid , commit_data , g -> hash_algo );
11201118 set_commit_tree (c , lookup_tree (r , & oid ));
11211119
11221120 return c -> maybe_tree ;
@@ -1543,7 +1541,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15431541
15441542 if (ctx -> report_progress )
15451543 ctx -> progress = start_delayed_progress (
1546- the_repository ,
1544+ ctx -> r ,
15471545 _ ("Loading known commits in commit graph" ),
15481546 ctx -> oids .nr );
15491547 for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1561,7 +1559,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15611559 */
15621560 if (ctx -> report_progress )
15631561 ctx -> progress = start_delayed_progress (
1564- the_repository ,
1562+ ctx -> r ,
15651563 _ ("Expanding reachable commits in commit graph" ),
15661564 0 );
15671565 for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1582,7 +1580,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15821580
15831581 if (ctx -> report_progress )
15841582 ctx -> progress = start_delayed_progress (
1585- the_repository ,
1583+ ctx -> r ,
15861584 _ ("Clearing commit marks in commit graph" ),
15871585 ctx -> oids .nr );
15881586 for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1700,7 +1698,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
17001698 if (ctx -> report_progress )
17011699 info .progress = ctx -> progress
17021700 = start_delayed_progress (
1703- the_repository ,
1701+ ctx -> r ,
17041702 _ ("Computing commit graph topological levels" ),
17051703 ctx -> commits .nr );
17061704
@@ -1735,7 +1733,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
17351733 if (ctx -> report_progress )
17361734 info .progress = ctx -> progress
17371735 = start_delayed_progress (
1738- the_repository ,
1736+ ctx -> r ,
17391737 _ ("Computing commit graph generation numbers" ),
17401738 ctx -> commits .nr );
17411739
@@ -1812,7 +1810,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
18121810
18131811 if (ctx -> report_progress )
18141812 progress = start_delayed_progress (
1815- the_repository ,
1813+ ctx -> r ,
18161814 _ ("Computing commit changed paths Bloom filters" ),
18171815 ctx -> commits .nr );
18181816
@@ -1858,6 +1856,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
18581856}
18591857
18601858struct refs_cb_data {
1859+ struct repository * repo ;
18611860 struct oidset * commits ;
18621861 struct progress * progress ;
18631862};
@@ -1870,9 +1869,9 @@ static int add_ref_to_set(const char *refname UNUSED,
18701869 struct object_id peeled ;
18711870 struct refs_cb_data * data = (struct refs_cb_data * )cb_data ;
18721871
1873- if (!peel_iterated_oid (the_repository , oid , & peeled ))
1872+ if (!peel_iterated_oid (data -> repo , oid , & peeled ))
18741873 oid = & peeled ;
1875- if (odb_read_object_info (the_repository -> objects , oid , NULL ) == OBJ_COMMIT )
1874+ if (odb_read_object_info (data -> repo -> objects , oid , NULL ) == OBJ_COMMIT )
18761875 oidset_insert (data -> commits , oid );
18771876
18781877 display_progress (data -> progress , oidset_size (data -> commits ));
@@ -1889,13 +1888,15 @@ int write_commit_graph_reachable(struct odb_source *source,
18891888 int result ;
18901889
18911890 memset (& data , 0 , sizeof (data ));
1891+ data .repo = source -> odb -> repo ;
18921892 data .commits = & commits ;
1893+
18931894 if (flags & COMMIT_GRAPH_WRITE_PROGRESS )
18941895 data .progress = start_delayed_progress (
1895- the_repository ,
1896+ source -> odb -> repo ,
18961897 _ ("Collecting referenced commits" ), 0 );
18971898
1898- refs_for_each_ref (get_main_ref_store (the_repository ), add_ref_to_set ,
1899+ refs_for_each_ref (get_main_ref_store (source -> odb -> repo ), add_ref_to_set ,
18991900 & data );
19001901
19011902 stop_progress (& data .progress );
@@ -1924,7 +1925,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
19241925 "Finding commits for commit graph in %" PRIuMAX " packs" ,
19251926 pack_indexes -> nr ),
19261927 (uintmax_t )pack_indexes -> nr );
1927- ctx -> progress = start_delayed_progress (the_repository ,
1928+ ctx -> progress = start_delayed_progress (ctx -> r ,
19281929 progress_title .buf , 0 );
19291930 ctx -> progress_done = 0 ;
19301931 }
@@ -1978,7 +1979,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
19781979{
19791980 if (ctx -> report_progress )
19801981 ctx -> progress = start_delayed_progress (
1981- the_repository ,
1982+ ctx -> r ,
19821983 _ ("Finding commits for commit graph among packed objects" ),
19831984 ctx -> approx_nr_objects );
19841985 for_each_packed_object (ctx -> r , add_packed_commits , ctx ,
@@ -1997,7 +1998,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
19971998 ctx -> num_extra_edges = 0 ;
19981999 if (ctx -> report_progress )
19992000 ctx -> progress = start_delayed_progress (
2000- the_repository ,
2001+ ctx -> r ,
20012002 _ ("Finding extra edges in commit graph" ),
20022003 ctx -> oids .nr );
20032004 oid_array_sort (& ctx -> oids );
@@ -2076,7 +2077,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20762077 ctx -> graph_name = get_commit_graph_filename (ctx -> odb_source );
20772078 }
20782079
2079- if (safe_create_leading_directories (the_repository , ctx -> graph_name )) {
2080+ if (safe_create_leading_directories (ctx -> r , ctx -> graph_name )) {
20802081 error (_ ("unable to create leading directories of %s" ),
20812082 ctx -> graph_name );
20822083 return -1 ;
@@ -2095,18 +2096,18 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20952096 return -1 ;
20962097 }
20972098
2098- if (adjust_shared_perm (the_repository , get_tempfile_path (graph_layer ))) {
2099+ if (adjust_shared_perm (ctx -> r , get_tempfile_path (graph_layer ))) {
20992100 error (_ ("unable to adjust shared permissions for '%s'" ),
21002101 get_tempfile_path (graph_layer ));
21012102 return -1 ;
21022103 }
21032104
2104- f = hashfd (the_repository -> hash_algo ,
2105+ f = hashfd (ctx -> r -> hash_algo ,
21052106 get_tempfile_fd (graph_layer ), get_tempfile_path (graph_layer ));
21062107 } else {
21072108 hold_lock_file_for_update_mode (& lk , ctx -> graph_name ,
21082109 LOCK_DIE_ON_ERROR , 0444 );
2109- f = hashfd (the_repository -> hash_algo ,
2110+ f = hashfd (ctx -> r -> hash_algo ,
21102111 get_lock_file_fd (& lk ), get_lock_file_path (& lk ));
21112112 }
21122113
@@ -2159,7 +2160,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
21592160 get_num_chunks (cf )),
21602161 get_num_chunks (cf ));
21612162 ctx -> progress = start_delayed_progress (
2162- the_repository ,
2163+ ctx -> r ,
21632164 progress_title .buf ,
21642165 st_mult (get_num_chunks (cf ), ctx -> commits .nr ));
21652166 }
@@ -2217,7 +2218,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
22172218 }
22182219
22192220 free (ctx -> commit_graph_hash_after [ctx -> num_commit_graphs_after - 1 ]);
2220- ctx -> commit_graph_hash_after [ctx -> num_commit_graphs_after - 1 ] = xstrdup (hash_to_hex (file_hash ));
2221+ ctx -> commit_graph_hash_after [ctx -> num_commit_graphs_after - 1 ] =
2222+ xstrdup (hash_to_hex_algop (file_hash , ctx -> r -> hash_algo ));
22212223 final_graph_name = get_split_graph_filename (ctx -> odb_source ,
22222224 ctx -> commit_graph_hash_after [ctx -> num_commit_graphs_after - 1 ]);
22232225 free (ctx -> commit_graph_filenames_after [ctx -> num_commit_graphs_after - 1 ]);
@@ -2372,7 +2374,7 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
23722374
23732375 if (ctx -> report_progress )
23742376 ctx -> progress = start_delayed_progress (
2375- the_repository ,
2377+ ctx -> r ,
23762378 _ ("Scanning merged commits" ),
23772379 ctx -> commits .nr );
23782380
@@ -2417,7 +2419,7 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
24172419 current_graph_number -- ;
24182420
24192421 if (ctx -> report_progress )
2420- ctx -> progress = start_delayed_progress (the_repository ,
2422+ ctx -> progress = start_delayed_progress (ctx -> r ,
24212423 _ ("Merging commit-graph" ), 0 );
24222424
24232425 merge_commit_graph (ctx , g );
@@ -2520,7 +2522,7 @@ int write_commit_graph(struct odb_source *source,
25202522 enum commit_graph_write_flags flags ,
25212523 const struct commit_graph_opts * opts )
25222524{
2523- struct repository * r = the_repository ;
2525+ struct repository * r = source -> odb -> repo ;
25242526 struct write_commit_graph_context ctx = {
25252527 .r = r ,
25262528 .odb_source = source ,
@@ -2620,14 +2622,14 @@ int write_commit_graph(struct odb_source *source,
26202622 replace = ctx .opts -> split_flags & COMMIT_GRAPH_SPLIT_REPLACE ;
26212623 }
26222624
2623- ctx .approx_nr_objects = repo_approximate_object_count (the_repository );
2625+ ctx .approx_nr_objects = repo_approximate_object_count (r );
26242626
26252627 if (ctx .append && ctx .r -> objects -> commit_graph ) {
26262628 struct commit_graph * g = ctx .r -> objects -> commit_graph ;
26272629 for (i = 0 ; i < g -> num_commits ; i ++ ) {
26282630 struct object_id oid ;
26292631 oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2630- the_repository -> hash_algo );
2632+ r -> hash_algo );
26312633 oid_array_append (& ctx .oids , & oid );
26322634 }
26332635 }
@@ -2735,7 +2737,7 @@ static void graph_report(const char *fmt, ...)
27352737
27362738static int commit_graph_checksum_valid (struct commit_graph * g )
27372739{
2738- return hashfile_checksum_valid (the_repository -> hash_algo ,
2740+ return hashfile_checksum_valid (g -> hash_algo ,
27392741 g -> data , g -> data_len );
27402742}
27412743
@@ -2758,7 +2760,7 @@ static int verify_one_commit_graph(struct repository *r,
27582760 struct commit * graph_commit ;
27592761
27602762 oidread (& cur_oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2761- the_repository -> hash_algo );
2763+ g -> hash_algo );
27622764
27632765 if (i && oidcmp (& prev_oid , & cur_oid ) >= 0 )
27642766 graph_report (_ ("commit-graph has incorrect OID order: %s then %s" ),
@@ -2803,7 +2805,7 @@ static int verify_one_commit_graph(struct repository *r,
28032805
28042806 display_progress (progress , ++ (* seen ));
28052807 oidread (& cur_oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2806- the_repository -> hash_algo );
2808+ g -> hash_algo );
28072809
28082810 graph_commit = lookup_commit (r , & cur_oid );
28092811 odb_commit = (struct commit * )create_object (r , & cur_oid , alloc_commit_node (r ));
@@ -2907,7 +2909,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
29072909 if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW ))
29082910 total += g -> num_commits_in_base ;
29092911
2910- progress = start_progress (the_repository ,
2912+ progress = start_progress (r ,
29112913 _ ("Verifying commits in commit graph" ),
29122914 total );
29132915 }
0 commit comments