commit-graph: stop using `the_repository`
There's still a bunch of uses of `the_repository` in "commit-graph.c", which we want to stop using due to it being a global variable. Refactor the code to stop using `the_repository` in favor of the repository provided via the calling context. This allows us to drop the `USE_THE_REPOSITORY_VARIABLE` macro. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Aug 15, 2025 at 07:49 UTC
ddacfc7466707cbe462594052261647b43868825
4 files changed
+42
-40
builtin/commit.c
+1
-1
@@ -1947,7 +1947,7 @@ int cmd_commit(int argc,
1947
"new index file. Check that disk is not full and quota is\n"
1948
"not exceeded, and then \"git restore --staged :/\" to recover."));
1949
1950
- git_test_write_commit_graph_or_die();
1950
+ git_test_write_commit_graph_or_die(the_repository->objects->sources);
1951
1952
repo_rerere(the_repository, 0);
1953
run_auto_maintenance(quiet);
builtin/merge.c
+1
-1
@@ -1862,7 +1862,7 @@ int cmd_merge(int argc,
1862
if (squash) {
1863
finish(head_commit, remoteheads, NULL, NULL);
1864
1865
- git_test_write_commit_graph_or_die();
1865
+ git_test_write_commit_graph_or_die(the_repository->objects->sources);
1866
} else
1867
write_merge_state(remoteheads);
1868
commit-graph.c
+39
-37
@@ -1,4 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
1
#define DISABLE_SIGN_COMPARE_WARNINGS
2
3
#include "git-compat-util.h"
@@ -29,7 +28,7 @@
28
#include "tree.h"
29
#include "chunk-format.h"
30
32
-void git_test_write_commit_graph_or_die(void)
31
+void git_test_write_commit_graph_or_die(struct odb_source *source)
32
{
33
int flags = 0;
34
if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
@@ -38,8 +37,7 @@ void git_test_write_commit_graph_or_die(void)
37
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
38
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
39
41
- if (write_commit_graph_reachable(the_repository->objects->sources,
42
- flags, NULL))
40
+ if (write_commit_graph_reachable(source, flags, NULL))
41
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
42
}
43
@@ -597,7 +595,7 @@ static int add_graph_to_chain(struct commit_graph *g,
595
if (!cur_g ||
596
!oideq(&oids[n], &cur_g->oid) ||
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)) {
599
warning(_("commit-graph chain does not match"));
600
return 0;
601
}
@@ -666,7 +664,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
664
if (strbuf_getline_lf(&line, fp) == EOF)
665
break;
666
669
- if (get_oid_hex(line.buf, &oids[i])) {
667
+ if (get_oid_hex_algop(line.buf, &oids[i], r->hash_algo)) {
668
warning(_("invalid commit-graph chain: line '%s' not a hash"),
669
line.buf);
670
valid = 0;
@@ -752,7 +750,7 @@ static void prepare_commit_graph_one(struct repository *r,
750
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
751
*
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.
754
*/
755
static int prepare_commit_graph(struct repository *r)
756
{
@@ -873,7 +871,7 @@ static void load_oid_from_graph(struct commit_graph *g,
871
lex_index = pos - g->num_commits_in_base;
872
873
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, lex_index),
876
- the_repository->hash_algo);
874
+ g->hash_algo);
875
}
876
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,
1114
st_mult(graph_data_width(g->hash_algo),
1115
graph_pos - g->num_commits_in_base);
1116
1119
- oidread(&oid, commit_data, the_repository->hash_algo);
1117
+ oidread(&oid, commit_data, g->hash_algo);
1118
set_commit_tree(c, lookup_tree(r, &oid));
1119
1120
return c->maybe_tree;
@@ -1543,7 +1541,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1541
1542
if (ctx->report_progress)
1543
ctx->progress = start_delayed_progress(
1546
- the_repository,
1544
+ ctx->r,
1545
_("Loading known commits in commit graph"),
1546
ctx->oids.nr);
1547
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1561,7 +1559,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1559
*/
1560
if (ctx->report_progress)
1561
ctx->progress = start_delayed_progress(
1564
- the_repository,
1562
+ ctx->r,
1563
_("Expanding reachable commits in commit graph"),
1564
0);
1565
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1582,7 +1580,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
1580
1581
if (ctx->report_progress)
1582
ctx->progress = start_delayed_progress(
1585
- the_repository,
1583
+ ctx->r,
1584
_("Clearing commit marks in commit graph"),
1585
ctx->oids.nr);
1586
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1700,7 +1698,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
1698
if (ctx->report_progress)
1699
info.progress = ctx->progress
1700
= start_delayed_progress(
1703
- the_repository,
1701
+ ctx->r,
1702
_("Computing commit graph topological levels"),
1703
ctx->commits.nr);
1704
@@ -1735,7 +1733,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1733
if (ctx->report_progress)
1734
info.progress = ctx->progress
1735
= start_delayed_progress(
1738
- the_repository,
1736
+ ctx->r,
1737
_("Computing commit graph generation numbers"),
1738
ctx->commits.nr);
1739
@@ -1812,7 +1810,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1810
1811
if (ctx->report_progress)
1812
progress = start_delayed_progress(
1815
- the_repository,
1813
+ ctx->r,
1814
_("Computing commit changed paths Bloom filters"),
1815
ctx->commits.nr);
1816
@@ -1858,6 +1856,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1856
}
1857
1858
struct refs_cb_data {
1859
+ struct repository *repo;
1860
struct oidset *commits;
1861
struct progress *progress;
1862
};
@@ -1870,9 +1869,9 @@ static int add_ref_to_set(const char *refname UNUSED,
1869
struct object_id peeled;
1870
struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
1871
1873
- if (!peel_iterated_oid(the_repository, oid, &peeled))
1872
+ if (!peel_iterated_oid(data->repo, oid, &peeled))
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)
1875
oidset_insert(data->commits, oid);
1876
1877
display_progress(data->progress, oidset_size(data->commits));
@@ -1889,13 +1888,15 @@ int write_commit_graph_reachable(struct odb_source *source,
1888
int result;
1889
1890
memset(&data, 0, sizeof(data));
1891
+ data.repo = source->odb->repo;
1892
data.commits = &commits;
1893
+
1894
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
1895
data.progress = start_delayed_progress(
1895
- the_repository,
1896
+ source->odb->repo,
1897
_("Collecting referenced commits"), 0);
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,
1900
&data);
1901
1902
stop_progress(&data.progress);
@@ -1924,7 +1925,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
1925
"Finding commits for commit graph in %"PRIuMAX" packs",
1926
pack_indexes->nr),
1927
(uintmax_t)pack_indexes->nr);
1927
- ctx->progress = start_delayed_progress(the_repository,
1928
+ ctx->progress = start_delayed_progress(ctx->r,
1929
progress_title.buf, 0);
1930
ctx->progress_done = 0;
1931
}
@@ -1978,7 +1979,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
1979
{
1980
if (ctx->report_progress)
1981
ctx->progress = start_delayed_progress(
1981
- the_repository,
1982
+ ctx->r,
1983
_("Finding commits for commit graph among packed objects"),
1984
ctx->approx_nr_objects);
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)
1998
ctx->num_extra_edges = 0;
1999
if (ctx->report_progress)
2000
ctx->progress = start_delayed_progress(
2000
- the_repository,
2001
+ ctx->r,
2002
_("Finding extra edges in commit graph"),
2003
ctx->oids.nr);
2004
oid_array_sort(&ctx->oids);
@@ -2076,7 +2077,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2077
ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
2078
}
2079
2079
- if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
2080
+ if (safe_create_leading_directories(ctx->r, ctx->graph_name)) {
2081
error(_("unable to create leading directories of %s"),
2082
ctx->graph_name);
2083
return -1;
@@ -2095,18 +2096,18 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2096
return -1;
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))) {
2100
error(_("unable to adjust shared permissions for '%s'"),
2101
get_tempfile_path(graph_layer));
2102
return -1;
2103
}
2104
2104
- f = hashfd(the_repository->hash_algo,
2105
+ f = hashfd(ctx->r->hash_algo,
2106
get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
2107
} else {
2108
hold_lock_file_for_update_mode(&lk, ctx->graph_name,
2109
LOCK_DIE_ON_ERROR, 0444);
2109
- f = hashfd(the_repository->hash_algo,
2110
+ f = hashfd(ctx->r->hash_algo,
2111
get_lock_file_fd(&lk), get_lock_file_path(&lk));
2112
}
2113
@@ -2159,7 +2160,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2160
get_num_chunks(cf)),
2161
get_num_chunks(cf));
2162
ctx->progress = start_delayed_progress(
2162
- the_repository,
2163
+ ctx->r,
2164
progress_title.buf,
2165
st_mult(get_num_chunks(cf), ctx->commits.nr));
2166
}
@@ -2217,7 +2218,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2218
}
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));
2223
final_graph_name = get_split_graph_filename(ctx->odb_source,
2224
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
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)
2374
2375
if (ctx->report_progress)
2376
ctx->progress = start_delayed_progress(
2375
- the_repository,
2377
+ ctx->r,
2378
_("Scanning merged commits"),
2379
ctx->commits.nr);
2380
@@ -2417,7 +2419,7 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
2419
current_graph_number--;
2420
2421
if (ctx->report_progress)
2420
- ctx->progress = start_delayed_progress(the_repository,
2422
+ ctx->progress = start_delayed_progress(ctx->r,
2423
_("Merging commit-graph"), 0);
2424
2425
merge_commit_graph(ctx, g);
@@ -2520,7 +2522,7 @@ int write_commit_graph(struct odb_source *source,
2522
enum commit_graph_write_flags flags,
2523
const struct commit_graph_opts *opts)
2524
{
2523
- struct repository *r = the_repository;
2525
+ struct repository *r = source->odb->repo;
2526
struct write_commit_graph_context ctx = {
2527
.r = r,
2528
.odb_source = source,
@@ -2620,14 +2622,14 @@ int write_commit_graph(struct odb_source *source,
2622
replace = ctx.opts->split_flags & COMMIT_GRAPH_SPLIT_REPLACE;
2623
}
2624
2623
- ctx.approx_nr_objects = repo_approximate_object_count(the_repository);
2625
+ ctx.approx_nr_objects = repo_approximate_object_count(r);
2626
2627
if (ctx.append && ctx.r->objects->commit_graph) {
2628
struct commit_graph *g = ctx.r->objects->commit_graph;
2629
for (i = 0; i < g->num_commits; i++) {
2630
struct object_id oid;
2631
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2630
- the_repository->hash_algo);
2632
+ r->hash_algo);
2633
oid_array_append(&ctx.oids, &oid);
2634
}
2635
}
@@ -2735,7 +2737,7 @@ static void graph_report(const char *fmt, ...)
2737
2738
static int commit_graph_checksum_valid(struct commit_graph *g)
2739
{
2738
- return hashfile_checksum_valid(the_repository->hash_algo,
2740
+ return hashfile_checksum_valid(g->hash_algo,
2741
g->data, g->data_len);
2742
}
2743
@@ -2758,7 +2760,7 @@ static int verify_one_commit_graph(struct repository *r,
2760
struct commit *graph_commit;
2761
2762
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2761
- the_repository->hash_algo);
2763
+ g->hash_algo);
2764
2765
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
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,
2805
2806
display_progress(progress, ++(*seen));
2807
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2806
- the_repository->hash_algo);
2808
+ g->hash_algo);
2809
2810
graph_commit = lookup_commit(r, &cur_oid);
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)
2909
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
2910
total += g->num_commits_in_base;
2911
2910
- progress = start_progress(the_repository,
2912
+ progress = start_progress(r,
2913
_("Verifying commits in commit graph"),
2914
total);
2915
}
commit-graph.h
+1
-1
@@ -21,7 +21,7 @@
21
* call this method oustide of a builtin, and only if you know what
22
* you are doing!
23
*/
24
-void git_test_write_commit_graph_or_die(void);
24
+void git_test_write_commit_graph_or_die(struct odb_source *source);
25
26
struct commit;
27
struct bloom_filter_settings;