Skip to content

Commit 238b369

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d20c6db commit 238b369

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@ int cmd_commit(int argc,
19471947
"new index file. Check that disk is not full and quota is\n"
19481948
"not exceeded, and then \"git restore --staged :/\" to recover."));
19491949

1950-
git_test_write_commit_graph_or_die();
1950+
git_test_write_commit_graph_or_die(the_repository->objects->sources);
19511951

19521952
repo_rerere(the_repository, 0);
19531953
run_auto_maintenance(quiet);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ int cmd_merge(int argc,
18621862
if (squash) {
18631863
finish(head_commit, remoteheads, NULL, NULL);
18641864

1865-
git_test_write_commit_graph_or_die();
1865+
git_test_write_commit_graph_or_die(the_repository->objects->sources);
18661866
} else
18671867
write_merge_state(remoteheads);
18681868

commit-graph.c

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "config.h"
53
#include "csum-file.h"
@@ -28,7 +26,7 @@
2826
#include "tree.h"
2927
#include "chunk-format.h"
3028

31-
void git_test_write_commit_graph_or_die(void)
29+
void git_test_write_commit_graph_or_die(struct odb_source *source)
3230
{
3331
int flags = 0;
3432
if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
@@ -37,8 +35,7 @@ void git_test_write_commit_graph_or_die(void)
3735
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
3836
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
3937

40-
if (write_commit_graph_reachable(the_repository->objects->sources,
41-
flags, NULL))
38+
if (write_commit_graph_reachable(source, flags, NULL))
4239
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
4340
}
4441

@@ -596,7 +593,7 @@ static int add_graph_to_chain(struct commit_graph *g,
596593
if (!cur_g ||
597594
!oideq(&oids[n], &cur_g->oid) ||
598595
!hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n),
599-
the_repository->hash_algo)) {
596+
g->hash_algo)) {
600597
warning(_("commit-graph chain does not match"));
601598
return 0;
602599
}
@@ -666,7 +663,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
666663
if (strbuf_getline_lf(&line, fp) == EOF)
667664
break;
668665

669-
if (get_oid_hex(line.buf, &oids[i])) {
666+
if (get_oid_hex_algop(line.buf, &oids[i], r->hash_algo)) {
670667
warning(_("invalid commit-graph chain: line '%s' not a hash"),
671668
line.buf);
672669
valid = 0;
@@ -752,7 +749,7 @@ static void prepare_commit_graph_one(struct repository *r,
752749
* Return 1 if commit_graph is non-NULL, and 0 otherwise.
753750
*
754751
* 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.
756753
*/
757754
static int prepare_commit_graph(struct repository *r)
758755
{
@@ -873,7 +870,7 @@ static void load_oid_from_graph(struct commit_graph *g,
873870
lex_index = pos - g->num_commits_in_base;
874871

875872
oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, lex_index),
876-
the_repository->hash_algo);
873+
g->hash_algo);
877874
}
878875

879876
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,
11161113
st_mult(graph_data_width(g->hash_algo),
11171114
graph_pos - g->num_commits_in_base);
11181115

1119-
oidread(&oid, commit_data, the_repository->hash_algo);
1116+
oidread(&oid, commit_data, g->hash_algo);
11201117
set_commit_tree(c, lookup_tree(r, &oid));
11211118

11221119
return c->maybe_tree;
@@ -1544,7 +1541,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15441541

15451542
if (ctx->report_progress)
15461543
ctx->progress = start_delayed_progress(
1547-
the_repository,
1544+
ctx->r,
15481545
_("Loading known commits in commit graph"),
15491546
ctx->oids.nr);
15501547
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1562,7 +1559,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15621559
*/
15631560
if (ctx->report_progress)
15641561
ctx->progress = start_delayed_progress(
1565-
the_repository,
1562+
ctx->r,
15661563
_("Expanding reachable commits in commit graph"),
15671564
0);
15681565
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1583,7 +1580,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
15831580

15841581
if (ctx->report_progress)
15851582
ctx->progress = start_delayed_progress(
1586-
the_repository,
1583+
ctx->r,
15871584
_("Clearing commit marks in commit graph"),
15881585
ctx->oids.nr);
15891586
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1700,7 +1697,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
17001697
if (ctx->report_progress)
17011698
info.progress = ctx->progress
17021699
= start_delayed_progress(
1703-
the_repository,
1700+
ctx->r,
17041701
_("Computing commit graph topological levels"),
17051702
ctx->commits.nr);
17061703

@@ -1735,7 +1732,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
17351732
if (ctx->report_progress)
17361733
info.progress = ctx->progress
17371734
= start_delayed_progress(
1738-
the_repository,
1735+
ctx->r,
17391736
_("Computing commit graph generation numbers"),
17401737
ctx->commits.nr);
17411738

@@ -1812,7 +1809,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
18121809

18131810
if (ctx->report_progress)
18141811
progress = start_delayed_progress(
1815-
the_repository,
1812+
ctx->r,
18161813
_("Computing commit changed paths Bloom filters"),
18171814
ctx->commits.nr);
18181815

@@ -1858,6 +1855,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
18581855
}
18591856

18601857
struct refs_cb_data {
1858+
struct repository *repo;
18611859
struct oidset *commits;
18621860
struct progress *progress;
18631861
};
@@ -1870,9 +1868,9 @@ static int add_ref_to_set(const char *refname UNUSED,
18701868
struct object_id peeled;
18711869
struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
18721870

1873-
if (!peel_iterated_oid(the_repository, oid, &peeled))
1871+
if (!peel_iterated_oid(data->repo, oid, &peeled))
18741872
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)
18761874
oidset_insert(data->commits, oid);
18771875

18781876
display_progress(data->progress, oidset_size(data->commits));
@@ -1889,13 +1887,15 @@ int write_commit_graph_reachable(struct odb_source *source,
18891887
int result;
18901888

18911889
memset(&data, 0, sizeof(data));
1890+
data.repo = source->odb->repo;
18921891
data.commits = &commits;
1892+
18931893
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
18941894
data.progress = start_delayed_progress(
1895-
the_repository,
1895+
source->odb->repo,
18961896
_("Collecting referenced commits"), 0);
18971897

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,
18991899
&data);
19001900

19011901
stop_progress(&data.progress);
@@ -1924,7 +1924,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
19241924
"Finding commits for commit graph in %"PRIuMAX" packs",
19251925
pack_indexes->nr),
19261926
(uintmax_t)pack_indexes->nr);
1927-
ctx->progress = start_delayed_progress(the_repository,
1927+
ctx->progress = start_delayed_progress(ctx->r,
19281928
progress_title.buf, 0);
19291929
ctx->progress_done = 0;
19301930
}
@@ -1978,7 +1978,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
19781978
{
19791979
if (ctx->report_progress)
19801980
ctx->progress = start_delayed_progress(
1981-
the_repository,
1981+
ctx->r,
19821982
_("Finding commits for commit graph among packed objects"),
19831983
ctx->approx_nr_objects);
19841984
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)
19971997
ctx->num_extra_edges = 0;
19981998
if (ctx->report_progress)
19991999
ctx->progress = start_delayed_progress(
2000-
the_repository,
2000+
ctx->r,
20012001
_("Finding extra edges in commit graph"),
20022002
ctx->oids.nr);
20032003
oid_array_sort(&ctx->oids);
@@ -2076,7 +2076,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20762076
ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
20772077
}
20782078

2079-
if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
2079+
if (safe_create_leading_directories(ctx->r, ctx->graph_name)) {
20802080
error(_("unable to create leading directories of %s"),
20812081
ctx->graph_name);
20822082
return -1;
@@ -2095,18 +2095,18 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20952095
return -1;
20962096
}
20972097

2098-
if (adjust_shared_perm(the_repository, get_tempfile_path(graph_layer))) {
2098+
if (adjust_shared_perm(ctx->r, get_tempfile_path(graph_layer))) {
20992099
error(_("unable to adjust shared permissions for '%s'"),
21002100
get_tempfile_path(graph_layer));
21012101
return -1;
21022102
}
21032103

2104-
f = hashfd(the_repository->hash_algo,
2104+
f = hashfd(ctx->r->hash_algo,
21052105
get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
21062106
} else {
21072107
hold_lock_file_for_update_mode(&lk, ctx->graph_name,
21082108
LOCK_DIE_ON_ERROR, 0444);
2109-
f = hashfd(the_repository->hash_algo,
2109+
f = hashfd(ctx->r->hash_algo,
21102110
get_lock_file_fd(&lk), get_lock_file_path(&lk));
21112111
}
21122112

@@ -2159,7 +2159,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
21592159
get_num_chunks(cf)),
21602160
get_num_chunks(cf));
21612161
ctx->progress = start_delayed_progress(
2162-
the_repository,
2162+
ctx->r,
21632163
progress_title.buf,
21642164
st_mult(get_num_chunks(cf), ctx->commits.nr));
21652165
}
@@ -2217,7 +2217,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
22172217
}
22182218

22192219
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));
22212222
final_graph_name = get_split_graph_filename(ctx->odb_source,
22222223
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
22232224
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)
23712372

23722373
if (ctx->report_progress)
23732374
ctx->progress = start_delayed_progress(
2374-
the_repository,
2375+
ctx->r,
23752376
_("Scanning merged commits"),
23762377
ctx->commits.nr);
23772378

@@ -2416,7 +2417,7 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
24162417
current_graph_number--;
24172418

24182419
if (ctx->report_progress)
2419-
ctx->progress = start_delayed_progress(the_repository,
2420+
ctx->progress = start_delayed_progress(ctx->r,
24202421
_("Merging commit-graph"), 0);
24212422

24222423
merge_commit_graph(ctx, g);
@@ -2519,7 +2520,7 @@ int write_commit_graph(struct odb_source *source,
25192520
enum commit_graph_write_flags flags,
25202521
const struct commit_graph_opts *opts)
25212522
{
2522-
struct repository *r = the_repository;
2523+
struct repository *r = source->odb->repo;
25232524
struct write_commit_graph_context ctx = {
25242525
.r = r,
25252526
.odb_source = source,
@@ -2619,14 +2620,14 @@ int write_commit_graph(struct odb_source *source,
26192620
replace = ctx.opts->split_flags & COMMIT_GRAPH_SPLIT_REPLACE;
26202621
}
26212622

2622-
ctx.approx_nr_objects = repo_approximate_object_count(the_repository);
2623+
ctx.approx_nr_objects = repo_approximate_object_count(r);
26232624

26242625
if (ctx.append && ctx.r->objects->commit_graph) {
26252626
struct commit_graph *g = ctx.r->objects->commit_graph;
26262627
for (i = 0; i < g->num_commits; i++) {
26272628
struct object_id oid;
26282629
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2629-
the_repository->hash_algo);
2630+
r->hash_algo);
26302631
oid_array_append(&ctx.oids, &oid);
26312632
}
26322633
}
@@ -2734,7 +2735,7 @@ static void graph_report(const char *fmt, ...)
27342735

27352736
static int commit_graph_checksum_valid(struct commit_graph *g)
27362737
{
2737-
return hashfile_checksum_valid(the_repository->hash_algo,
2738+
return hashfile_checksum_valid(g->hash_algo,
27382739
g->data, g->data_len);
27392740
}
27402741

@@ -2757,7 +2758,7 @@ static int verify_one_commit_graph(struct repository *r,
27572758
struct commit *graph_commit;
27582759

27592760
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2760-
the_repository->hash_algo);
2761+
g->hash_algo);
27612762

27622763
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
27632764
graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2802,7 +2803,7 @@ static int verify_one_commit_graph(struct repository *r,
28022803

28032804
display_progress(progress, ++(*seen));
28042805
oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
2805-
the_repository->hash_algo);
2806+
g->hash_algo);
28062807

28072808
graph_commit = lookup_commit(r, &cur_oid);
28082809
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)
29062907
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
29072908
total += g->num_commits_in_base;
29082909

2909-
progress = start_progress(the_repository,
2910+
progress = start_progress(r,
29102911
_("Verifying commits in commit graph"),
29112912
total);
29122913
}

commit-graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* call this method oustide of a builtin, and only if you know what
2222
* you are doing!
2323
*/
24-
void git_test_write_commit_graph_or_die(void);
24+
void git_test_write_commit_graph_or_die(struct odb_source *source);
2525

2626
struct commit;
2727
struct bloom_filter_settings;

0 commit comments

Comments
 (0)