Skip to content

Commit 2e5c475

Browse files
pks-tgitster
authored andcommitted
cocci: apply rules to rewrite callers of "refs" interfaces
Apply the rules that rewrite callers of "refs" interfaces to explicitly pass `struct ref_store`. The resulting patch has been applied with the `--whitespace=fix` option. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b198ee0 commit 2e5c475

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+711
-436
lines changed

add-interactive.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,9 @@ static int get_modified_files(struct repository *r,
532532
size_t *binary_count)
533533
{
534534
struct object_id head_oid;
535-
int is_initial = !resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
536-
&head_oid, NULL);
535+
int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
536+
"HEAD", RESOLVE_REF_READING,
537+
&head_oid, NULL);
537538
struct collection_status s = { 0 };
538539
int i;
539540

@@ -761,8 +762,10 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps,
761762
size_t count, i, j;
762763

763764
struct object_id oid;
764-
int is_initial = !resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &oid,
765-
NULL);
765+
int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
766+
"HEAD", RESOLVE_REF_READING,
767+
&oid,
768+
NULL);
766769
struct lock_file index_lock;
767770
const char **paths;
768771
struct tree *tree;
@@ -990,8 +993,10 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
990993
ssize_t count, i;
991994

992995
struct object_id oid;
993-
int is_initial = !resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &oid,
994-
NULL);
996+
int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
997+
"HEAD", RESOLVE_REF_READING,
998+
&oid,
999+
NULL);
9951000
if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)
9961001
return -1;
9971002

bisect.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ static int register_ref(const char *refname, const struct object_id *oid,
469469

470470
static int read_bisect_refs(void)
471471
{
472-
return for_each_ref_in("refs/bisect/", register_ref, NULL);
472+
return refs_for_each_ref_in(get_main_ref_store(the_repository),
473+
"refs/bisect/", register_ref, NULL);
473474
}
474475

475476
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
@@ -709,7 +710,7 @@ static enum bisect_error error_if_skipped_commits(struct commit_list *tried,
709710
static int is_expected_rev(const struct object_id *oid)
710711
{
711712
struct object_id expected_oid;
712-
if (read_ref("BISECT_EXPECTED_REV", &expected_oid))
713+
if (refs_read_ref(get_main_ref_store(the_repository), "BISECT_EXPECTED_REV", &expected_oid))
713714
return 0;
714715
return oideq(oid, &expected_oid);
715716
}
@@ -721,11 +722,14 @@ enum bisect_error bisect_checkout(const struct object_id *bisect_rev,
721722
struct pretty_print_context pp = {0};
722723
struct strbuf commit_msg = STRBUF_INIT;
723724

724-
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
725+
refs_update_ref(get_main_ref_store(the_repository), NULL,
726+
"BISECT_EXPECTED_REV", bisect_rev, NULL, 0,
727+
UPDATE_REFS_DIE_ON_ERR);
725728

726729
if (no_checkout) {
727-
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0,
728-
UPDATE_REFS_DIE_ON_ERR);
730+
refs_update_ref(get_main_ref_store(the_repository), NULL,
731+
"BISECT_HEAD", bisect_rev, NULL, 0,
732+
UPDATE_REFS_DIE_ON_ERR);
729733
} else {
730734
struct child_process cmd = CHILD_PROCESS_INIT;
731735

@@ -1027,7 +1031,8 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10271031
* If no_checkout is non-zero, the bisection process does not
10281032
* checkout the trial commit but instead simply updates BISECT_HEAD.
10291033
*/
1030-
int no_checkout = ref_exists("BISECT_HEAD");
1034+
int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
1035+
"BISECT_HEAD");
10311036
unsigned bisect_flags = 0;
10321037

10331038
read_bisect_terms(&term_bad, &term_good);
@@ -1178,10 +1183,14 @@ int bisect_clean_state(void)
11781183

11791184
/* There may be some refs packed during bisection */
11801185
struct string_list refs_for_removal = STRING_LIST_INIT_NODUP;
1181-
for_each_ref_in("refs/bisect", mark_for_removal, (void *) &refs_for_removal);
1186+
refs_for_each_ref_in(get_main_ref_store(the_repository),
1187+
"refs/bisect", mark_for_removal,
1188+
(void *) &refs_for_removal);
11821189
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
11831190
string_list_append(&refs_for_removal, xstrdup("BISECT_EXPECTED_REV"));
1184-
result = delete_refs("bisect: remove", &refs_for_removal, REF_NO_DEREF);
1191+
result = refs_delete_refs(get_main_ref_store(the_repository),
1192+
"bisect: remove", &refs_for_removal,
1193+
REF_NO_DEREF);
11851194
refs_for_removal.strdup_strings = 1;
11861195
string_list_clear(&refs_for_removal, 0);
11871196
unlink_or_warn(git_path_bisect_ancestors_ok());

blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
27002700
return NULL;
27012701

27022702
/* Do we have HEAD? */
2703-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
2703+
if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL))
27042704
return NULL;
27052705
head_commit = lookup_commit_reference_gently(revs->repo,
27062706
&head_oid, 1);
@@ -2803,7 +2803,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28032803
if (sb->final) {
28042804
parent_oid = &sb->final->object.oid;
28052805
} else {
2806-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
2806+
if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL))
28072807
die("no such ref: HEAD");
28082808
parent_oid = &head_oid;
28092809
}

branch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ int validate_branchname(const char *name, struct strbuf *ref)
377377
exit(code);
378378
}
379379

380-
return ref_exists(ref->buf);
380+
return refs_ref_exists(get_main_ref_store(the_repository), ref->buf);
381381
}
382382

383383
static int initialized_checked_out_branches;
@@ -623,7 +623,8 @@ void create_branch(struct repository *r,
623623
msg = xstrfmt("branch: Reset to %s", start_name);
624624
else
625625
msg = xstrfmt("branch: Created from %s", start_name);
626-
transaction = ref_transaction_begin(&err);
626+
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
627+
&err);
627628
if (!transaction ||
628629
ref_transaction_update(transaction, ref.buf,
629630
&oid, forcing ? NULL : null_oid(),

builtin/am.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10011001

10021002
if (mkdir(state->dir, 0777) < 0 && errno != EEXIST)
10031003
die_errno(_("failed to create directory '%s'"), state->dir);
1004-
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
1004+
refs_delete_ref(get_main_ref_store(the_repository), NULL,
1005+
"REBASE_HEAD", NULL, REF_NO_DEREF);
10051006

10061007
if (split_mail(state, patch_format, paths, keep_cr) < 0) {
10071008
am_destroy(state);
@@ -1081,12 +1082,15 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
10811082
if (!repo_get_oid(the_repository, "HEAD", &curr_head)) {
10821083
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
10831084
if (!state->rebasing)
1084-
update_ref("am", "ORIG_HEAD", &curr_head, NULL, 0,
1085-
UPDATE_REFS_DIE_ON_ERR);
1085+
refs_update_ref(get_main_ref_store(the_repository),
1086+
"am", "ORIG_HEAD", &curr_head, NULL,
1087+
0,
1088+
UPDATE_REFS_DIE_ON_ERR);
10861089
} else {
10871090
write_state_text(state, "abort-safety", "");
10881091
if (!state->rebasing)
1089-
delete_ref(NULL, "ORIG_HEAD", NULL, 0);
1092+
refs_delete_ref(get_main_ref_store(the_repository),
1093+
NULL, "ORIG_HEAD", NULL, 0);
10901094
}
10911095

10921096
/*
@@ -1119,7 +1123,8 @@ static void am_next(struct am_state *state)
11191123

11201124
oidclr(&state->orig_commit);
11211125
unlink(am_path(state, "original-commit"));
1122-
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
1126+
refs_delete_ref(get_main_ref_store(the_repository), NULL,
1127+
"REBASE_HEAD", NULL, REF_NO_DEREF);
11231128

11241129
if (!repo_get_oid(the_repository, "HEAD", &head))
11251130
write_state_text(state, "abort-safety", oid_to_hex(&head));
@@ -1466,8 +1471,9 @@ static int parse_mail_rebase(struct am_state *state, const char *mail)
14661471

14671472
oidcpy(&state->orig_commit, &commit_oid);
14681473
write_state_text(state, "original-commit", oid_to_hex(&commit_oid));
1469-
update_ref("am", "REBASE_HEAD", &commit_oid,
1470-
NULL, REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
1474+
refs_update_ref(get_main_ref_store(the_repository), "am",
1475+
"REBASE_HEAD", &commit_oid,
1476+
NULL, REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
14711477

14721478
return 0;
14731479
}
@@ -1697,8 +1703,9 @@ static void do_commit(const struct am_state *state)
16971703
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
16981704
state->msg);
16991705

1700-
update_ref(sb.buf, "HEAD", &commit, old_oid, 0,
1701-
UPDATE_REFS_DIE_ON_ERR);
1706+
refs_update_ref(get_main_ref_store(the_repository), sb.buf, "HEAD",
1707+
&commit, old_oid, 0,
1708+
UPDATE_REFS_DIE_ON_ERR);
17021709

17031710
if (state->rebasing) {
17041711
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
@@ -2175,7 +2182,8 @@ static void am_abort(struct am_state *state)
21752182

21762183
am_rerere_clear();
21772184

2178-
curr_branch = resolve_refdup("HEAD", 0, &curr_head, NULL);
2185+
curr_branch = refs_resolve_refdup(get_main_ref_store(the_repository),
2186+
"HEAD", 0, &curr_head, NULL);
21792187
has_curr_head = curr_branch && !is_null_oid(&curr_head);
21802188
if (!has_curr_head)
21812189
oidcpy(&curr_head, the_hash_algo->empty_tree);
@@ -2188,11 +2196,13 @@ static void am_abort(struct am_state *state)
21882196
die(_("failed to clean index"));
21892197

21902198
if (has_orig_head)
2191-
update_ref("am --abort", "HEAD", &orig_head,
2192-
has_curr_head ? &curr_head : NULL, 0,
2193-
UPDATE_REFS_DIE_ON_ERR);
2199+
refs_update_ref(get_main_ref_store(the_repository),
2200+
"am --abort", "HEAD", &orig_head,
2201+
has_curr_head ? &curr_head : NULL, 0,
2202+
UPDATE_REFS_DIE_ON_ERR);
21942203
else if (curr_branch)
2195-
delete_ref(NULL, curr_branch, NULL, REF_NO_DEREF);
2204+
refs_delete_ref(get_main_ref_store(the_repository), NULL,
2205+
curr_branch, NULL, REF_NO_DEREF);
21962206

21972207
free(curr_branch);
21982208
am_destroy(state);

builtin/bisect.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int bisect_reset(const char *commit)
243243
strbuf_addstr(&branch, commit);
244244
}
245245

246-
if (branch.len && !ref_exists("BISECT_HEAD")) {
246+
if (branch.len && !refs_ref_exists(get_main_ref_store(the_repository), "BISECT_HEAD")) {
247247
struct child_process cmd = CHILD_PROCESS_INIT;
248248

249249
cmd.git_cmd = 1;
@@ -302,8 +302,8 @@ static int bisect_write(const char *state, const char *rev,
302302
goto finish;
303303
}
304304

305-
if (update_ref(NULL, tag.buf, &oid, NULL, 0,
306-
UPDATE_REFS_MSG_ON_ERR)) {
305+
if (refs_update_ref(get_main_ref_store(the_repository), NULL, tag.buf, &oid, NULL, 0,
306+
UPDATE_REFS_MSG_ON_ERR)) {
307307
res = -1;
308308
goto finish;
309309
}
@@ -416,11 +416,12 @@ static void bisect_status(struct bisect_state *state,
416416
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
417417
char *good_glob = xstrfmt("%s-*", terms->term_good);
418418

419-
if (ref_exists(bad_ref))
419+
if (refs_ref_exists(get_main_ref_store(the_repository), bad_ref))
420420
state->nr_bad = 1;
421421

422-
for_each_glob_ref_in(inc_nr, good_glob, "refs/bisect/",
423-
(void *) &state->nr_good);
422+
refs_for_each_glob_ref_in(get_main_ref_store(the_repository), inc_nr,
423+
good_glob, "refs/bisect/",
424+
(void *) &state->nr_good);
424425

425426
free(good_glob);
426427
free(bad_ref);
@@ -574,9 +575,11 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
574575
reset_revision_walk();
575576
repo_init_revisions(the_repository, revs, NULL);
576577
setup_revisions(0, NULL, revs, NULL);
577-
for_each_glob_ref_in(add_bisect_ref, bad, "refs/bisect/", &cb);
578+
refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
579+
add_bisect_ref, bad, "refs/bisect/", &cb);
578580
cb.object_flags = UNINTERESTING;
579-
for_each_glob_ref_in(add_bisect_ref, good, "refs/bisect/", &cb);
581+
refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
582+
add_bisect_ref, good, "refs/bisect/", &cb);
580583
if (prepare_revision_walk(revs))
581584
res = error(_("revision walk setup failed\n"));
582585

@@ -636,7 +639,7 @@ static int bisect_successful(struct bisect_terms *terms)
636639
char *bad_ref = xstrfmt("refs/bisect/%s",terms->term_bad);
637640
int res;
638641

639-
read_ref(bad_ref, &oid);
642+
refs_read_ref(get_main_ref_store(the_repository), bad_ref, &oid);
640643
commit = lookup_commit_reference_by_name(bad_ref);
641644
repo_format_commit_message(the_repository, commit, "%s", &commit_name,
642645
&pp);
@@ -779,7 +782,8 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
779782
/*
780783
* Verify HEAD
781784
*/
782-
head = resolve_ref_unsafe("HEAD", 0, &head_oid, &flags);
785+
head = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
786+
"HEAD", 0, &head_oid, &flags);
783787
if (!head)
784788
if (repo_get_oid(the_repository, "HEAD", &head_oid))
785789
return error(_("bad HEAD - I need a HEAD"));
@@ -838,8 +842,8 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
838842
res = error(_("invalid ref: '%s'"), start_head.buf);
839843
goto finish;
840844
}
841-
if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
842-
UPDATE_REFS_MSG_ON_ERR)) {
845+
if (refs_update_ref(get_main_ref_store(the_repository), NULL, "BISECT_HEAD", &oid, NULL, 0,
846+
UPDATE_REFS_MSG_ON_ERR)) {
843847
res = BISECT_FAILED;
844848
goto finish;
845849
}
@@ -972,7 +976,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
972976
oid_array_append(&revs, &commit->object.oid);
973977
}
974978

975-
if (read_ref("BISECT_EXPECTED_REV", &expected))
979+
if (refs_read_ref(get_main_ref_store(the_repository), "BISECT_EXPECTED_REV", &expected))
976980
verify_expected = 0; /* Ignore invalid file contents */
977981

978982
for (i = 0; i < revs.nr; i++) {
@@ -982,7 +986,9 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
982986
}
983987
if (verify_expected && !oideq(&revs.oid[i], &expected)) {
984988
unlink_or_warn(git_path_bisect_ancestors_ok());
985-
delete_ref(NULL, "BISECT_EXPECTED_REV", NULL, REF_NO_DEREF);
989+
refs_delete_ref(get_main_ref_store(the_repository),
990+
NULL, "BISECT_EXPECTED_REV", NULL,
991+
REF_NO_DEREF);
986992
verify_expected = 0;
987993
}
988994
}
@@ -1179,13 +1185,15 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
11791185
struct object_id good_rev;
11801186
struct object_id current_rev;
11811187
char *good_glob = xstrfmt("%s-*", terms->term_good);
1182-
int no_checkout = ref_exists("BISECT_HEAD");
1188+
int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
1189+
"BISECT_HEAD");
11831190

1184-
for_each_glob_ref_in(get_first_good, good_glob, "refs/bisect/",
1185-
&good_rev);
1191+
refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
1192+
get_first_good, good_glob, "refs/bisect/",
1193+
&good_rev);
11861194
free(good_glob);
11871195

1188-
if (read_ref(no_checkout ? "BISECT_HEAD" : "HEAD", &current_rev))
1196+
if (refs_read_ref(get_main_ref_store(the_repository), no_checkout ? "BISECT_HEAD" : "HEAD", &current_rev))
11891197
return -1;
11901198

11911199
res = bisect_checkout(&good_rev, no_checkout);

builtin/blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10931093
struct commit *head_commit;
10941094
struct object_id head_oid;
10951095

1096-
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
1097-
&head_oid, NULL) ||
1096+
if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING,
1097+
&head_oid, NULL) ||
10981098
!(head_commit = lookup_commit_reference_gently(revs.repo,
10991099
&head_oid, 1)))
11001100
die("no such ref: HEAD");

0 commit comments

Comments
 (0)