1
- #define USE_THE_REPOSITORY_VARIABLE
2
1
#define DISABLE_SIGN_COMPARE_WARNINGS
3
2
4
3
#include "git-compat-util.h"
29
28
#include "tree.h"
30
29
#include "chunk-format.h"
31
30
32
- void git_test_write_commit_graph_or_die (void )
31
+ void git_test_write_commit_graph_or_die (struct odb_source * source )
33
32
{
34
33
int flags = 0 ;
35
34
if (!git_env_bool (GIT_TEST_COMMIT_GRAPH , 0 ))
@@ -38,8 +37,7 @@ void git_test_write_commit_graph_or_die(void)
38
37
if (git_env_bool (GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS , 0 ))
39
38
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS ;
40
39
41
- if (write_commit_graph_reachable (the_repository -> objects -> sources ,
42
- flags , NULL ))
40
+ if (write_commit_graph_reachable (source , flags , NULL ))
43
41
die ("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH" );
44
42
}
45
43
@@ -597,7 +595,7 @@ static int add_graph_to_chain(struct commit_graph *g,
597
595
if (!cur_g ||
598
596
!oideq (& oids [n ], & cur_g -> oid ) ||
599
597
!hasheq (oids [n ].hash , g -> chunk_base_graphs + st_mult (g -> hash_algo -> rawsz , n ),
600
- the_repository -> hash_algo )) {
598
+ g -> hash_algo )) {
601
599
warning (_ ("commit-graph chain does not match" ));
602
600
return 0 ;
603
601
}
@@ -666,7 +664,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
666
664
if (strbuf_getline_lf (& line , fp ) == EOF )
667
665
break ;
668
666
669
- if (get_oid_hex (line .buf , & oids [i ])) {
667
+ if (get_oid_hex_algop (line .buf , & oids [i ], r -> hash_algo )) {
670
668
warning (_ ("invalid commit-graph chain: line '%s' not a hash" ),
671
669
line .buf );
672
670
valid = 0 ;
@@ -752,7 +750,7 @@ static void prepare_commit_graph_one(struct repository *r,
752
750
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
753
751
*
754
752
* 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.
756
754
*/
757
755
static int prepare_commit_graph (struct repository * r )
758
756
{
@@ -873,7 +871,7 @@ static void load_oid_from_graph(struct commit_graph *g,
873
871
lex_index = pos - g -> num_commits_in_base ;
874
872
875
873
oidread (oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , lex_index ),
876
- the_repository -> hash_algo );
874
+ g -> hash_algo );
877
875
}
878
876
879
877
static struct commit_list * * insert_parent_or_die (struct repository * r ,
@@ -1116,7 +1114,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
1116
1114
st_mult (graph_data_width (g -> hash_algo ),
1117
1115
graph_pos - g -> num_commits_in_base );
1118
1116
1119
- oidread (& oid , commit_data , the_repository -> hash_algo );
1117
+ oidread (& oid , commit_data , g -> hash_algo );
1120
1118
set_commit_tree (c , lookup_tree (r , & oid ));
1121
1119
1122
1120
return c -> maybe_tree ;
@@ -1543,7 +1541,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1543
1541
1544
1542
if (ctx -> report_progress )
1545
1543
ctx -> progress = start_delayed_progress (
1546
- the_repository ,
1544
+ ctx -> r ,
1547
1545
_ ("Loading known commits in commit graph" ),
1548
1546
ctx -> oids .nr );
1549
1547
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1561,7 +1559,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1561
1559
*/
1562
1560
if (ctx -> report_progress )
1563
1561
ctx -> progress = start_delayed_progress (
1564
- the_repository ,
1562
+ ctx -> r ,
1565
1563
_ ("Expanding reachable commits in commit graph" ),
1566
1564
0 );
1567
1565
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1582,7 +1580,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1582
1580
1583
1581
if (ctx -> report_progress )
1584
1582
ctx -> progress = start_delayed_progress (
1585
- the_repository ,
1583
+ ctx -> r ,
1586
1584
_ ("Clearing commit marks in commit graph" ),
1587
1585
ctx -> oids .nr );
1588
1586
for (i = 0 ; i < ctx -> oids .nr ; i ++ ) {
@@ -1700,7 +1698,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
1700
1698
if (ctx -> report_progress )
1701
1699
info .progress = ctx -> progress
1702
1700
= start_delayed_progress (
1703
- the_repository ,
1701
+ ctx -> r ,
1704
1702
_ ("Computing commit graph topological levels" ),
1705
1703
ctx -> commits .nr );
1706
1704
@@ -1735,7 +1733,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1735
1733
if (ctx -> report_progress )
1736
1734
info .progress = ctx -> progress
1737
1735
= start_delayed_progress (
1738
- the_repository ,
1736
+ ctx -> r ,
1739
1737
_ ("Computing commit graph generation numbers" ),
1740
1738
ctx -> commits .nr );
1741
1739
@@ -1812,7 +1810,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1812
1810
1813
1811
if (ctx -> report_progress )
1814
1812
progress = start_delayed_progress (
1815
- the_repository ,
1813
+ ctx -> r ,
1816
1814
_ ("Computing commit changed paths Bloom filters" ),
1817
1815
ctx -> commits .nr );
1818
1816
@@ -1858,6 +1856,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1858
1856
}
1859
1857
1860
1858
struct refs_cb_data {
1859
+ struct repository * repo ;
1861
1860
struct oidset * commits ;
1862
1861
struct progress * progress ;
1863
1862
};
@@ -1870,9 +1869,9 @@ static int add_ref_to_set(const char *refname UNUSED,
1870
1869
struct object_id peeled ;
1871
1870
struct refs_cb_data * data = (struct refs_cb_data * )cb_data ;
1872
1871
1873
- if (!peel_iterated_oid (the_repository , oid , & peeled ))
1872
+ if (!peel_iterated_oid (data -> repo , oid , & peeled ))
1874
1873
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 )
1876
1875
oidset_insert (data -> commits , oid );
1877
1876
1878
1877
display_progress (data -> progress , oidset_size (data -> commits ));
@@ -1889,13 +1888,15 @@ int write_commit_graph_reachable(struct odb_source *source,
1889
1888
int result ;
1890
1889
1891
1890
memset (& data , 0 , sizeof (data ));
1891
+ data .repo = source -> odb -> repo ;
1892
1892
data .commits = & commits ;
1893
+
1893
1894
if (flags & COMMIT_GRAPH_WRITE_PROGRESS )
1894
1895
data .progress = start_delayed_progress (
1895
- the_repository ,
1896
+ source -> odb -> repo ,
1896
1897
_ ("Collecting referenced commits" ), 0 );
1897
1898
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 ,
1899
1900
& data );
1900
1901
1901
1902
stop_progress (& data .progress );
@@ -1924,7 +1925,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
1924
1925
"Finding commits for commit graph in %" PRIuMAX " packs" ,
1925
1926
pack_indexes -> nr ),
1926
1927
(uintmax_t )pack_indexes -> nr );
1927
- ctx -> progress = start_delayed_progress (the_repository ,
1928
+ ctx -> progress = start_delayed_progress (ctx -> r ,
1928
1929
progress_title .buf , 0 );
1929
1930
ctx -> progress_done = 0 ;
1930
1931
}
@@ -1978,7 +1979,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
1978
1979
{
1979
1980
if (ctx -> report_progress )
1980
1981
ctx -> progress = start_delayed_progress (
1981
- the_repository ,
1982
+ ctx -> r ,
1982
1983
_ ("Finding commits for commit graph among packed objects" ),
1983
1984
ctx -> approx_nr_objects );
1984
1985
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)
1997
1998
ctx -> num_extra_edges = 0 ;
1998
1999
if (ctx -> report_progress )
1999
2000
ctx -> progress = start_delayed_progress (
2000
- the_repository ,
2001
+ ctx -> r ,
2001
2002
_ ("Finding extra edges in commit graph" ),
2002
2003
ctx -> oids .nr );
2003
2004
oid_array_sort (& ctx -> oids );
@@ -2076,7 +2077,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2076
2077
ctx -> graph_name = get_commit_graph_filename (ctx -> odb_source );
2077
2078
}
2078
2079
2079
- if (safe_create_leading_directories (the_repository , ctx -> graph_name )) {
2080
+ if (safe_create_leading_directories (ctx -> r , ctx -> graph_name )) {
2080
2081
error (_ ("unable to create leading directories of %s" ),
2081
2082
ctx -> graph_name );
2082
2083
return -1 ;
@@ -2095,18 +2096,18 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2095
2096
return -1 ;
2096
2097
}
2097
2098
2098
- if (adjust_shared_perm (the_repository , get_tempfile_path (graph_layer ))) {
2099
+ if (adjust_shared_perm (ctx -> r , get_tempfile_path (graph_layer ))) {
2099
2100
error (_ ("unable to adjust shared permissions for '%s'" ),
2100
2101
get_tempfile_path (graph_layer ));
2101
2102
return -1 ;
2102
2103
}
2103
2104
2104
- f = hashfd (the_repository -> hash_algo ,
2105
+ f = hashfd (ctx -> r -> hash_algo ,
2105
2106
get_tempfile_fd (graph_layer ), get_tempfile_path (graph_layer ));
2106
2107
} else {
2107
2108
hold_lock_file_for_update_mode (& lk , ctx -> graph_name ,
2108
2109
LOCK_DIE_ON_ERROR , 0444 );
2109
- f = hashfd (the_repository -> hash_algo ,
2110
+ f = hashfd (ctx -> r -> hash_algo ,
2110
2111
get_lock_file_fd (& lk ), get_lock_file_path (& lk ));
2111
2112
}
2112
2113
@@ -2159,7 +2160,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2159
2160
get_num_chunks (cf )),
2160
2161
get_num_chunks (cf ));
2161
2162
ctx -> progress = start_delayed_progress (
2162
- the_repository ,
2163
+ ctx -> r ,
2163
2164
progress_title .buf ,
2164
2165
st_mult (get_num_chunks (cf ), ctx -> commits .nr ));
2165
2166
}
@@ -2217,7 +2218,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2217
2218
}
2218
2219
2219
2220
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 ));
2221
2223
final_graph_name = get_split_graph_filename (ctx -> odb_source ,
2222
2224
ctx -> commit_graph_hash_after [ctx -> num_commit_graphs_after - 1 ]);
2223
2225
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)
2372
2374
2373
2375
if (ctx -> report_progress )
2374
2376
ctx -> progress = start_delayed_progress (
2375
- the_repository ,
2377
+ ctx -> r ,
2376
2378
_ ("Scanning merged commits" ),
2377
2379
ctx -> commits .nr );
2378
2380
@@ -2417,7 +2419,7 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
2417
2419
current_graph_number -- ;
2418
2420
2419
2421
if (ctx -> report_progress )
2420
- ctx -> progress = start_delayed_progress (the_repository ,
2422
+ ctx -> progress = start_delayed_progress (ctx -> r ,
2421
2423
_ ("Merging commit-graph" ), 0 );
2422
2424
2423
2425
merge_commit_graph (ctx , g );
@@ -2520,7 +2522,7 @@ int write_commit_graph(struct odb_source *source,
2520
2522
enum commit_graph_write_flags flags ,
2521
2523
const struct commit_graph_opts * opts )
2522
2524
{
2523
- struct repository * r = the_repository ;
2525
+ struct repository * r = source -> odb -> repo ;
2524
2526
struct write_commit_graph_context ctx = {
2525
2527
.r = r ,
2526
2528
.odb_source = source ,
@@ -2620,14 +2622,14 @@ int write_commit_graph(struct odb_source *source,
2620
2622
replace = ctx .opts -> split_flags & COMMIT_GRAPH_SPLIT_REPLACE ;
2621
2623
}
2622
2624
2623
- ctx .approx_nr_objects = repo_approximate_object_count (the_repository );
2625
+ ctx .approx_nr_objects = repo_approximate_object_count (r );
2624
2626
2625
2627
if (ctx .append && ctx .r -> objects -> commit_graph ) {
2626
2628
struct commit_graph * g = ctx .r -> objects -> commit_graph ;
2627
2629
for (i = 0 ; i < g -> num_commits ; i ++ ) {
2628
2630
struct object_id oid ;
2629
2631
oidread (& oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2630
- the_repository -> hash_algo );
2632
+ r -> hash_algo );
2631
2633
oid_array_append (& ctx .oids , & oid );
2632
2634
}
2633
2635
}
@@ -2735,7 +2737,7 @@ static void graph_report(const char *fmt, ...)
2735
2737
2736
2738
static int commit_graph_checksum_valid (struct commit_graph * g )
2737
2739
{
2738
- return hashfile_checksum_valid (the_repository -> hash_algo ,
2740
+ return hashfile_checksum_valid (g -> hash_algo ,
2739
2741
g -> data , g -> data_len );
2740
2742
}
2741
2743
@@ -2758,7 +2760,7 @@ static int verify_one_commit_graph(struct repository *r,
2758
2760
struct commit * graph_commit ;
2759
2761
2760
2762
oidread (& cur_oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2761
- the_repository -> hash_algo );
2763
+ g -> hash_algo );
2762
2764
2763
2765
if (i && oidcmp (& prev_oid , & cur_oid ) >= 0 )
2764
2766
graph_report (_ ("commit-graph has incorrect OID order: %s then %s" ),
@@ -2803,7 +2805,7 @@ static int verify_one_commit_graph(struct repository *r,
2803
2805
2804
2806
display_progress (progress , ++ (* seen ));
2805
2807
oidread (& cur_oid , g -> chunk_oid_lookup + st_mult (g -> hash_algo -> rawsz , i ),
2806
- the_repository -> hash_algo );
2808
+ g -> hash_algo );
2807
2809
2808
2810
graph_commit = lookup_commit (r , & cur_oid );
2809
2811
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)
2907
2909
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW ))
2908
2910
total += g -> num_commits_in_base ;
2909
2911
2910
- progress = start_progress (the_repository ,
2912
+ progress = start_progress (r ,
2911
2913
_ ("Verifying commits in commit graph" ),
2912
2914
total );
2913
2915
}
0 commit comments