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