Skip to content

Commit 0586c0c

Browse files
avargitster
authored andcommitted
libs: use "struct repository *" argument, not "the_repository"
As can easily be seen from grepping in our sources, we had these uses of "the_repository" in various library code in cases where the function in question was already getting a "struct repository *" argument. Let's use that argument instead. Out of these changes only the changes to "cache-tree.c", "commit-reach.c", "shallow.c" and "upload-pack.c" would have cleanly applied before the migration away from the "repo_*()" wrapper macros in the preceding commits. The rest aren't new, as we'd previously implicitly refer to "the_repository", but it's now more obvious that we were doing the wrong thing all along, and should have used the parameter instead. The change to change "get_index_format_default(the_repository)" in "read-cache.c" to use the "r" variable instead should arguably have been part of [1], or in the subsequent cleanup in [2]. Let's do it here, as can be seen from the initial code in [3] it's not important that we use "the_repository" there, but would prefer to always use the current repository. This change excludes the "the_repository" use in "upload-pack.c"'s upload_pack_advertise(), as the in-flight [4] makes that change. 1. ee1f0c2 (read-cache: add index.skipHash config option, 2023-01-06) 2. 6269f8e (treewide: always have a valid "index_state.repo" member, 2023-01-17) 3. 7211b9e (repo-settings: consolidate some config settings, 2019-08-13) 4. <Y/[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8929455 commit 0586c0c

17 files changed

+76
-82
lines changed

add-interactive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ static int get_modified_files(struct repository *r,
551551
opt.def = is_initial ?
552552
empty_tree_oid_hex() : oid_to_hex(&head_oid);
553553

554-
repo_init_revisions(the_repository, &rev, NULL);
554+
repo_init_revisions(r, &rev, NULL);
555555
setup_revisions(0, NULL, &rev, &opt);
556556

557557
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;

branch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
531531
explicit_tracking = 1;
532532

533533
real_ref = NULL;
534-
if (repo_get_oid_mb(the_repository, start_name, &oid)) {
534+
if (repo_get_oid_mb(r, start_name, &oid)) {
535535
if (explicit_tracking) {
536536
int code = die_message(_(upstream_missing), start_name);
537537
advise_if_enabled(ADVICE_SET_UPSTREAM_FAILURE,
@@ -541,8 +541,8 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
541541
die(_("not a valid object name: '%s'"), start_name);
542542
}
543543

544-
switch (repo_dwim_ref(the_repository, start_name, strlen(start_name),
545-
&oid, &real_ref, 0)) {
544+
switch (repo_dwim_ref(r, start_name, strlen(start_name), &oid,
545+
&real_ref, 0)) {
546546
case 0:
547547
/* Not branching from any existing branch */
548548
if (explicit_tracking)
@@ -773,7 +773,7 @@ void create_branches_recursively(struct repository *r, const char *name,
773773
name);
774774
}
775775

776-
create_branch(the_repository, name, start_commitish, force, 0, reflog, quiet,
776+
create_branch(r, name, start_commitish, force, 0, reflog, quiet,
777777
BRANCH_TRACK_NEVER, dry_run);
778778
if (dry_run)
779779
return;

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int show_reference(struct repository *r, const char *refname,
5454
struct object_id object;
5555
enum object_type obj_type, repl_type;
5656

57-
if (repo_get_oid(the_repository, refname, &object))
57+
if (repo_get_oid(r, refname, &object))
5858
return error(_("failed to resolve '%s' as a valid ref"), refname);
5959

6060
obj_type = oid_object_info(r, &object, NULL);

cache-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,14 @@ void prime_cache_tree(struct repository *r,
814814
{
815815
struct strbuf tree_path = STRBUF_INIT;
816816

817-
trace2_region_enter("cache-tree", "prime_cache_tree", the_repository);
817+
trace2_region_enter("cache-tree", "prime_cache_tree", r);
818818
cache_tree_free(&istate->cache_tree);
819819
istate->cache_tree = cache_tree();
820820

821821
prime_cache_tree_rec(r, istate->cache_tree, tree, &tree_path);
822822
strbuf_release(&tree_path);
823823
istate->cache_changed |= CACHE_TREE_CHANGED;
824-
trace2_region_leave("cache-tree", "prime_cache_tree", the_repository);
824+
trace2_region_leave("cache-tree", "prime_cache_tree", r);
825825
}
826826

827827
/*

combine-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static char *grab_blob(struct repository *r,
332332
*size = fill_textconv(r, textconv, df, &blob);
333333
free_filespec(df);
334334
} else {
335-
blob = repo_read_object_file(the_repository, oid, &type, size);
335+
blob = repo_read_object_file(r, oid, &type, size);
336336
if (type != OBJ_BLOB)
337337
die("object '%s' is not a blob!", oid_to_hex(oid));
338338
}

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
25492549

25502550
graph_commit = lookup_commit(r, &cur_oid);
25512551
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
2552-
if (repo_parse_commit_internal(the_repository, odb_commit, 0, 0)) {
2552+
if (repo_parse_commit_internal(r, odb_commit, 0, 0)) {
25532553
graph_report(_("failed to parse commit %s from object database for commit-graph"),
25542554
oid_to_hex(&cur_oid));
25552555
continue;

commit-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ int repo_is_descendant_of(struct repository *r,
448448
if (!with_commit)
449449
return 1;
450450

451-
if (generation_numbers_enabled(the_repository)) {
451+
if (generation_numbers_enabled(r)) {
452452
struct commit_list *from_list = NULL;
453453
int result;
454454
commit_list_insert(commit, &from_list);

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@ static struct commit *get_ref(struct repository *repo,
37983798
return make_virtual_commit(repo, (struct tree*)object, name);
37993799
if (object->type != OBJ_COMMIT)
38003800
return NULL;
3801-
if (repo_parse_commit(the_repository, (struct commit *)object))
3801+
if (repo_parse_commit(repo, (struct commit *)object))
38023802
return NULL;
38033803
return (struct commit *)object;
38043804
}

notes-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int notes_cache_match_validity(struct repository *r,
2323
return 0;
2424

2525
memset(&pretty_ctx, 0, sizeof(pretty_ctx));
26-
repo_format_commit_message(the_repository, commit, "%s", &msg,
26+
repo_format_commit_message(r, commit, "%s", &msg,
2727
&pretty_ctx);
2828
strbuf_trim(&msg);
2929

notes-utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void create_notes_commit(struct repository *r,
2323
struct object_id parent_oid;
2424
if (!read_ref(t->ref, &parent_oid)) {
2525
struct commit *parent = lookup_commit(r, &parent_oid);
26-
if (repo_parse_commit(the_repository, parent))
26+
if (repo_parse_commit(r, parent))
2727
die("Failed to find/parse commit %s", t->ref);
2828
commit_list_insert(parent, &parents);
2929
}

object-name.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ static enum get_oid_result get_parent(struct repository *r,
10381038
if (ret)
10391039
return ret;
10401040
commit = lookup_commit_reference(r, &oid);
1041-
if (repo_parse_commit(the_repository, commit))
1041+
if (repo_parse_commit(r, commit))
10421042
return MISSING_OBJECT;
10431043
if (!idx) {
10441044
oidcpy(result, &commit->object.oid);
@@ -1072,7 +1072,7 @@ static enum get_oid_result get_nth_ancestor(struct repository *r,
10721072
return MISSING_OBJECT;
10731073

10741074
while (generation--) {
1075-
if (repo_parse_commit(the_repository, commit) || !commit->parents)
1075+
if (repo_parse_commit(r, commit) || !commit->parents)
10761076
return MISSING_OBJECT;
10771077
commit = commit->parents->item;
10781078
}
@@ -1363,10 +1363,10 @@ static int get_oid_oneline(struct repository *r,
13631363
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
13641364
if (!parse_object(r, &commit->object.oid))
13651365
continue;
1366-
buf = repo_get_commit_buffer(the_repository, commit, NULL);
1366+
buf = repo_get_commit_buffer(r, commit, NULL);
13671367
p = strstr(buf, "\n\n");
13681368
matches = negative ^ (p && !regexec(&regex, p + 2, 0, NULL, 0));
1369-
repo_unuse_commit_buffer(the_repository, commit, buf);
1369+
repo_unuse_commit_buffer(r, commit, buf);
13701370

13711371
if (matches) {
13721372
oidcpy(oid, &commit->object.oid);

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ int repo_index_has_changes(struct repository *repo,
26282628

26292629
if (tree)
26302630
cmp = tree->object.oid;
2631-
if (tree || !repo_get_oid_tree(the_repository, "HEAD", &cmp)) {
2631+
if (tree || !repo_get_oid_tree(repo, "HEAD", &cmp)) {
26322632
struct diff_options opt;
26332633

26342634
repo_diff_setup(repo, &opt);
@@ -2947,7 +2947,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
29472947
}
29482948

29492949
if (!istate->version)
2950-
istate->version = get_index_format_default(the_repository);
2950+
istate->version = get_index_format_default(r);
29512951

29522952
/* demote version 3 to version 2 when the latter suffices */
29532953
if (istate->version == 3 || istate->version == 2)

reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
106106
goto leave_reset_head;
107107
}
108108

109-
if (!repo_get_oid(the_repository, "HEAD", &head_oid)) {
109+
if (!repo_get_oid(r, "HEAD", &head_oid)) {
110110
head = &head_oid;
111111
} else if (!oid || !reset_hard) {
112112
ret = error(_("could not determine HEAD revision"));

0 commit comments

Comments
 (0)