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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
May 7, 2024 at 09:11 UTC
2e5c4758b75f7cbae612c89b177aa045fa4f9c68
75 files changed
+711
-436
add-interactive.c
+11
-6
@@ -532,8 +532,9 @@ static int get_modified_files(struct repository *r,
532
size_t *binary_count)
533
{
534
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);
538
struct collection_status s = { 0 };
539
int i;
540
@@ -761,8 +762,10 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps,
762
size_t count, i, j;
763
764
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);
769
struct lock_file index_lock;
770
const char **paths;
771
struct tree *tree;
@@ -990,8 +993,10 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
993
ssize_t count, i;
994
995
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);
1000
if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)
1001
return -1;
1002
bisect.c
+17
-8
@@ -469,7 +469,8 @@ static int register_ref(const char *refname, const struct object_id *oid,
469
470
static int read_bisect_refs(void)
471
{
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);
474
}
475
476
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,
710
static int is_expected_rev(const struct object_id *oid)
711
{
712
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))
714
return 0;
715
return oideq(oid, &expected_oid);
716
}
@@ -721,11 +722,14 @@ enum bisect_error bisect_checkout(const struct object_id *bisect_rev,
722
struct pretty_print_context pp = {0};
723
struct strbuf commit_msg = STRBUF_INIT;
724
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);
728
729
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);
733
} else {
734
struct child_process cmd = CHILD_PROCESS_INIT;
735
@@ -1027,7 +1031,8 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1031
* If no_checkout is non-zero, the bisection process does not
1032
* checkout the trial commit but instead simply updates BISECT_HEAD.
1033
*/
1030
- int no_checkout = ref_exists("BISECT_HEAD");
1034
+ int no_checkout = refs_ref_exists(get_main_ref_store(the_repository),
1035
+ "BISECT_HEAD");
1036
unsigned bisect_flags = 0;
1037
1038
read_bisect_terms(&term_bad, &term_good);
@@ -1178,10 +1183,14 @@ int bisect_clean_state(void)
1183
1184
/* There may be some refs packed during bisection */
1185
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);
1189
string_list_append(&refs_for_removal, xstrdup("BISECT_HEAD"));
1190
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);
1194
refs_for_removal.strdup_strings = 1;
1195
string_list_clear(&refs_for_removal, 0);
1196
unlink_or_warn(git_path_bisect_ancestors_ok());
blame.c
+2
-2
@@ -2700,7 +2700,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
2700
return NULL;
2701
2702
/* 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))
2704
return NULL;
2705
head_commit = lookup_commit_reference_gently(revs->repo,
2706
&head_oid, 1);
@@ -2803,7 +2803,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
2803
if (sb->final) {
2804
parent_oid = &sb->final->object.oid;
2805
} 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))
2807
die("no such ref: HEAD");
2808
parent_oid = &head_oid;
2809
}
branch.c
+3
-2
@@ -377,7 +377,7 @@ int validate_branchname(const char *name, struct strbuf *ref)
377
exit(code);
378
}
379
380
- return ref_exists(ref->buf);
380
+ return refs_ref_exists(get_main_ref_store(the_repository), ref->buf);
381
}
382
383
static int initialized_checked_out_branches;
@@ -623,7 +623,8 @@ void create_branch(struct repository *r,
623
msg = xstrfmt("branch: Reset to %s", start_name);
624
else
625
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);
628
if (!transaction ||
629
ref_transaction_update(transaction, ref.buf,
630
&oid, forcing ? NULL : null_oid(),
builtin/am.c
+24
-14
@@ -1001,7 +1001,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
1001
1002
if (mkdir(state->dir, 0777) < 0 && errno != EEXIST)
1003
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);
1006
1007
if (split_mail(state, patch_format, paths, keep_cr) < 0) {
1008
am_destroy(state);
@@ -1081,12 +1082,15 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
1082
if (!repo_get_oid(the_repository, "HEAD", &curr_head)) {
1083
write_state_text(state, "abort-safety", oid_to_hex(&curr_head));
1084
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);
1089
} else {
1090
write_state_text(state, "abort-safety", "");
1091
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);
1094
}
1095
1096
/*
@@ -1119,7 +1123,8 @@ static void am_next(struct am_state *state)
1123
1124
oidclr(&state->orig_commit);
1125
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);
1128
1129
if (!repo_get_oid(the_repository, "HEAD", &head))
1130
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)
1471
1472
oidcpy(&state->orig_commit, &commit_oid);
1473
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);
1477
1478
return 0;
1479
}
@@ -1697,8 +1703,9 @@ static void do_commit(const struct am_state *state)
1703
strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
1704
state->msg);
1705
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);
1709
1710
if (state->rebasing) {
1711
FILE *fp = xfopen(am_path(state, "rewritten"), "a");
@@ -2175,7 +2182,8 @@ static void am_abort(struct am_state *state)
2182
2183
am_rerere_clear();
2184
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);
2187
has_curr_head = curr_branch && !is_null_oid(&curr_head);
2188
if (!has_curr_head)
2189
oidcpy(&curr_head, the_hash_algo->empty_tree);
@@ -2188,11 +2196,13 @@ static void am_abort(struct am_state *state)
2196
die(_("failed to clean index"));
2197
2198
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);
2203
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);
2206
2207
free(curr_branch);
2208
am_destroy(state);
builtin/bisect.c
+26
-18
@@ -243,7 +243,7 @@ static int bisect_reset(const char *commit)
243
strbuf_addstr(&branch, commit);
244
}
245
246
- if (branch.len && !ref_exists("BISECT_HEAD")) {
246
+ if (branch.len && !refs_ref_exists(get_main_ref_store(the_repository), "BISECT_HEAD")) {
247
struct child_process cmd = CHILD_PROCESS_INIT;
248
249
cmd.git_cmd = 1;
@@ -302,8 +302,8 @@ static int bisect_write(const char *state, const char *rev,
302
goto finish;
303
}
304
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)) {
307
res = -1;
308
goto finish;
309
}
@@ -416,11 +416,12 @@ static void bisect_status(struct bisect_state *state,
416
char *bad_ref = xstrfmt("refs/bisect/%s", terms->term_bad);
417
char *good_glob = xstrfmt("%s-*", terms->term_good);
418
419
- if (ref_exists(bad_ref))
419
+ if (refs_ref_exists(get_main_ref_store(the_repository), bad_ref))
420
state->nr_bad = 1;
421
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);
425
426
free(good_glob);
427
free(bad_ref);
@@ -574,9 +575,11 @@ static int prepare_revs(struct bisect_terms *terms, struct rev_info *revs)
575
reset_revision_walk();
576
repo_init_revisions(the_repository, revs, NULL);
577
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);
580
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);
583
if (prepare_revision_walk(revs))
584
res = error(_("revision walk setup failed\n"));
585
@@ -636,7 +639,7 @@ static int bisect_successful(struct bisect_terms *terms)
639
char *bad_ref = xstrfmt("refs/bisect/%s",terms->term_bad);
640
int res;
641
639
- read_ref(bad_ref, &oid);
642
+ refs_read_ref(get_main_ref_store(the_repository), bad_ref, &oid);
643
commit = lookup_commit_reference_by_name(bad_ref);
644
repo_format_commit_message(the_repository, commit, "%s", &commit_name,
645
&pp);
@@ -779,7 +782,8 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
782
/*
783
* Verify HEAD
784
*/
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);
787
if (!head)
788
if (repo_get_oid(the_repository, "HEAD", &head_oid))
789
return error(_("bad HEAD - I need a HEAD"));
@@ -838,8 +842,8 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
842
res = error(_("invalid ref: '%s'"), start_head.buf);
843
goto finish;
844
}
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)) {
847
res = BISECT_FAILED;
848
goto finish;
849
}
@@ -972,7 +976,7 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
976
oid_array_append(&revs, &commit->object.oid);
977
}
978
975
- if (read_ref("BISECT_EXPECTED_REV", &expected))
979
+ if (refs_read_ref(get_main_ref_store(the_repository), "BISECT_EXPECTED_REV", &expected))
980
verify_expected = 0; /* Ignore invalid file contents */
981
982
for (i = 0; i < revs.nr; i++) {
@@ -982,7 +986,9 @@ static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
986
}
987
if (verify_expected && !oideq(&revs.oid[i], &expected)) {
988
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);
992
verify_expected = 0;
993
}
994
}
@@ -1179,13 +1185,15 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
1185
struct object_id good_rev;
1186
struct object_id current_rev;
1187
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");
1190
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);
1194
free(good_glob);
1195
1188
- if (read_ref(no_checkout ? "BISECT_HEAD" : "HEAD", ¤t_rev))
1196
+ if (refs_read_ref(get_main_ref_store(the_repository), no_checkout ? "BISECT_HEAD" : "HEAD", ¤t_rev))
1197
return -1;
1198
1199
res = bisect_checkout(&good_rev, no_checkout);
builtin/blame.c
+2
-2
@@ -1093,8 +1093,8 @@ parse_done:
1093
struct commit *head_commit;
1094
struct object_id head_oid;
1095
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) ||
1098
!(head_commit = lookup_commit_reference_gently(revs.repo,
1099
&head_oid, 1)))
1100
die("no such ref: HEAD");
builtin/branch.c
+27
-22
@@ -148,8 +148,8 @@ static int branch_merged(int kind, const char *name,
148
149
if (upstream &&
150
(reference_name = reference_name_to_free =
151
- resolve_refdup(upstream, RESOLVE_REF_READING,
152
- &oid, NULL)) != NULL)
151
+ refs_resolve_refdup(get_main_ref_store(the_repository), upstream, RESOLVE_REF_READING,
152
+ &oid, NULL)) != NULL)
153
reference_rev = lookup_commit_reference(the_repository,
154
&oid);
155
}
@@ -272,21 +272,24 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
272
}
273
}
274
275
- target = resolve_refdup(name,
276
- RESOLVE_REF_READING
277
- | RESOLVE_REF_NO_RECURSE
278
- | RESOLVE_REF_ALLOW_BAD_NAME,
279
- &oid, &flags);
275
+ target = refs_resolve_refdup(get_main_ref_store(the_repository),
276
+ name,
277
+ RESOLVE_REF_READING
278
+ | RESOLVE_REF_NO_RECURSE
279
+ | RESOLVE_REF_ALLOW_BAD_NAME,
280
+ &oid, &flags);
281
if (!target) {
282
if (remote_branch) {
283
error(_("remote-tracking branch '%s' not found"), bname.buf);
284
} else {
285
char *virtual_name = mkpathdup(fmt_remotes, bname.buf);
285
- char *virtual_target = resolve_refdup(virtual_name,
286
- RESOLVE_REF_READING
287
- | RESOLVE_REF_NO_RECURSE
288
- | RESOLVE_REF_ALLOW_BAD_NAME,
289
- &oid, &flags);
286
+ char *virtual_target = refs_resolve_refdup(get_main_ref_store(the_repository),
287
+ virtual_name,
288
+ RESOLVE_REF_READING
289
+ | RESOLVE_REF_NO_RECURSE
290
+ | RESOLVE_REF_ALLOW_BAD_NAME,
291
+ &oid,
292
+ &flags);
293
FREE_AND_NULL(virtual_name);
294
295
if (virtual_target)
@@ -317,13 +320,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
320
free(target);
321
}
322
320
- if (delete_refs(NULL, &refs_to_delete, REF_NO_DEREF))
323
+ if (refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF))
324
ret = 1;
325
326
for_each_string_list_item(item, &refs_to_delete) {
327
char *describe_ref = item->util;
328
char *name = item->string;
326
- if (!ref_exists(name)) {
329
+ if (!refs_ref_exists(get_main_ref_store(the_repository), name)) {
330
char *refname = name + branch_name_pos;
331
if (!quiet)
332
printf(remote_branch
@@ -499,7 +502,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
502
static void print_current_branch_name(void)
503
{
504
int flags;
502
- const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
505
+ const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
506
+ "HEAD", 0, NULL, &flags);
507
const char *shortname;
508
if (!refname)
509
die(_("could not resolve HEAD"));
@@ -580,7 +584,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
584
* Bad name --- this could be an attempt to rename a
585
* ref that we used to allow to be created by accident.
586
*/
583
- if (ref_exists(oldref.buf))
587
+ if (refs_ref_exists(get_main_ref_store(the_repository), oldref.buf))
588
recovery = 1;
589
else {
590
int code = die_message(_("invalid branch name: '%s'"), oldname);
@@ -601,7 +605,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
605
}
606
}
607
604
- if ((copy || !(oldref_usage & IS_HEAD)) && !ref_exists(oldref.buf)) {
608
+ if ((copy || !(oldref_usage & IS_HEAD)) && !refs_ref_exists(get_main_ref_store(the_repository), oldref.buf)) {
609
if (oldref_usage & IS_HEAD)
610
die(_("no commit on branch '%s' yet"), oldname);
611
else
@@ -632,9 +636,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
636
oldref.buf, newref.buf);
637
638
if (!copy && !(oldref_usage & IS_ORPHAN) &&
635
- rename_ref(oldref.buf, newref.buf, logmsg.buf))
639
+ refs_rename_ref(get_main_ref_store(the_repository), oldref.buf, newref.buf, logmsg.buf))
640
die(_("branch rename failed"));
637
- if (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf))
641
+ if (copy && refs_copy_existing_ref(get_main_ref_store(the_repository), oldref.buf, newref.buf, logmsg.buf))
642
die(_("branch copy failed"));
643
644
if (recovery) {
@@ -786,7 +790,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
790
791
track = git_branch_track;
792
789
- head = resolve_refdup("HEAD", 0, &head_oid, NULL);
793
+ head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
794
+ 0, &head_oid, NULL);
795
if (!head)
796
die(_("failed to resolve HEAD as a valid ref"));
797
if (!strcmp(head, "HEAD"))
@@ -891,7 +896,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
896
}
897
898
strbuf_addf(&branch_ref, "refs/heads/%s", branch_name);
894
- if (!ref_exists(branch_ref.buf))
899
+ if (!refs_ref_exists(get_main_ref_store(the_repository), branch_ref.buf))
900
error((!argc || branch_checked_out(branch_ref.buf))
901
? _("no commit on branch '%s' yet")
902
: _("no branch named '%s'"),
@@ -936,7 +941,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
941
die(_("no such branch '%s'"), argv[0]);
942
}
943
939
- if (!ref_exists(branch->refname)) {
944
+ if (!refs_ref_exists(get_main_ref_store(the_repository), branch->refname)) {
945
if (!argc || branch_checked_out(branch->refname))
946
die(_("no commit on branch '%s' yet"), branch->name);
947
die(_("branch '%s' does not exist"), branch->name);
builtin/checkout.c
+22
-13
@@ -646,7 +646,8 @@ static int checkout_paths(const struct checkout_opts *opts,
646
rollback_lock_file(&lock_file);
647
}
648
649
- read_ref_full("HEAD", 0, &rev, NULL);
649
+ refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", 0,
650
+ &rev, NULL);
651
head = lookup_commit_reference_gently(the_repository, &rev, 1);
652
653
errs |= post_checkout_hook(head, head, 0);
@@ -958,7 +959,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
959
int ret;
960
struct strbuf err = STRBUF_INIT;
961
961
- ret = safe_create_reflog(refname, &err);
962
+ ret = refs_create_reflog(get_main_ref_store(the_repository),
963
+ refname, &err);
964
if (ret) {
965
fprintf(stderr, _("Can not do reflog for '%s': %s\n"),
966
opts->new_orphan_branch, err.buf);
@@ -999,8 +1001,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
1001
if (!strcmp(new_branch_info->name, "HEAD") && !new_branch_info->path && !opts->force_detach) {
1002
/* Nothing to do. */
1003
} else if (opts->force_detach || !new_branch_info->path) { /* No longer on any branch. */
1002
- update_ref(msg.buf, "HEAD", &new_branch_info->commit->object.oid, NULL,
1003
- REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
1004
+ refs_update_ref(get_main_ref_store(the_repository), msg.buf,
1005
+ "HEAD", &new_branch_info->commit->object.oid,
1006
+ NULL,
1007
+ REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR);
1008
if (!opts->quiet) {
1009
if (old_branch_info->path &&
1010
advice_enabled(ADVICE_DETACHED_HEAD) && !opts->force_detach)
@@ -1008,7 +1012,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
1012
describe_detached_head(_("HEAD is now at"), new_branch_info->commit);
1013
}
1014
} else if (new_branch_info->path) { /* Switch branches. */
1011
- if (create_symref("HEAD", new_branch_info->path, msg.buf) < 0)
1015
+ if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf) < 0)
1016
die(_("unable to update HEAD"));
1017
if (!opts->quiet) {
1018
if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) {
@@ -1029,8 +1033,9 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
1033
}
1034
}
1035
if (old_branch_info->path && old_branch_info->name) {
1032
- if (!ref_exists(old_branch_info->path) && reflog_exists(old_branch_info->path))
1033
- delete_reflog(old_branch_info->path);
1036
+ if (!refs_ref_exists(get_main_ref_store(the_repository), old_branch_info->path) && refs_reflog_exists(get_main_ref_store(the_repository), old_branch_info->path))
1037
+ refs_delete_reflog(get_main_ref_store(the_repository),
1038
+ old_branch_info->path);
1039
}
1040
}
1041
remove_branch_state(the_repository, !opts->quiet);
@@ -1129,7 +1134,8 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
1134
object->flags &= ~UNINTERESTING;
1135
add_pending_object(&revs, object, oid_to_hex(&object->oid));
1136
1132
- for_each_ref(add_pending_uninteresting_ref, &revs);
1137
+ refs_for_each_ref(get_main_ref_store(the_repository),
1138
+ add_pending_uninteresting_ref, &revs);
1139
if (new_commit)
1140
add_pending_oid(&revs, "HEAD",
1141
&new_commit->object.oid,
@@ -1159,7 +1165,8 @@ static int switch_branches(const struct checkout_opts *opts,
1165
trace2_cmd_mode("branch");
1166
1167
memset(&old_branch_info, 0, sizeof(old_branch_info));
1162
- old_branch_info.path = resolve_refdup("HEAD", 0, &rev, &flag);
1168
+ old_branch_info.path = refs_resolve_refdup(get_main_ref_store(the_repository),
1169
+ "HEAD", 0, &rev, &flag);
1170
if (old_branch_info.path)
1171
old_branch_info.commit = lookup_commit_reference_gently(the_repository, &rev, 1);
1172
if (!(flag & REF_ISSYMREF))
@@ -1247,7 +1254,7 @@ static void setup_new_branch_info_and_source_tree(
1254
setup_branch_path(new_branch_info);
1255
1256
if (!check_refname_format(new_branch_info->path, 0) &&
1250
- !read_ref(new_branch_info->path, &branch_rev))
1257
+ !refs_read_ref(get_main_ref_store(the_repository), new_branch_info->path, &branch_rev))
1258
oidcpy(rev, &branch_rev);
1259
else
1260
/* not an existing branch */
@@ -1466,7 +1473,8 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
1473
if (!opts->new_branch)
1474
die(_("You are on a branch yet to be born"));
1475
strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch);
1469
- status = create_symref("HEAD", branch_ref.buf, "checkout -b");
1476
+ status = refs_create_symref(get_main_ref_store(the_repository),
1477
+ "HEAD", branch_ref.buf, "checkout -b");
1478
strbuf_release(&branch_ref);
1479
if (!opts->quiet)
1480
fprintf(stderr, _("Switched to a new branch '%s'\n"),
@@ -1553,7 +1561,8 @@ static void die_if_switching_to_a_branch_in_use(struct checkout_opts *opts,
1561
1562
if (opts->ignore_other_worktrees)
1563
return;
1556
- head_ref = resolve_refdup("HEAD", 0, NULL, &flags);
1564
+ head_ref = refs_resolve_refdup(get_main_ref_store(the_repository),
1565
+ "HEAD", 0, NULL, &flags);
1566
if (head_ref && (!(flags & REF_ISSYMREF) || strcmp(head_ref, full_ref)))
1567
die_if_checked_out(full_ref, 1);
1568
free(head_ref);
@@ -1634,7 +1643,7 @@ static int checkout_branch(struct checkout_opts *opts,
1643
struct object_id rev;
1644
int flag;
1645
1637
- if (!read_ref_full("HEAD", 0, &rev, &flag) &&
1646
+ if (!refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", 0, &rev, &flag) &&
1647
(flag & REF_ISSYMREF) && is_null_oid(&rev))
1648
return switch_unborn_to_new_branch(opts);
1649
}
builtin/clone.c
+21
-15
@@ -539,7 +539,8 @@ static void write_remote_refs(const struct ref *local_refs)
539
struct ref_transaction *t;
540
struct strbuf err = STRBUF_INIT;
541
542
- t = ref_transaction_begin(&err);
542
+ t = ref_store_transaction_begin(get_main_ref_store(the_repository),
543
+ &err);
544
if (!t)
545
die("%s", err.buf);
546
@@ -570,8 +571,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
571
OBJECT_INFO_QUICK |
572
OBJECT_INFO_SKIP_FETCH_OBJECT))
573
continue;
573
- update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
574
- UPDATE_REFS_DIE_ON_ERR);
574
+ refs_update_ref(get_main_ref_store(the_repository), msg,
575
+ ref->name, &ref->old_oid, NULL, 0,
576
+ UPDATE_REFS_DIE_ON_ERR);
577
}
578
}
579
@@ -623,9 +625,9 @@ static void update_remote_refs(const struct ref *refs,
625
struct strbuf head_ref = STRBUF_INIT;
626
strbuf_addstr(&head_ref, branch_top);
627
strbuf_addstr(&head_ref, "HEAD");
626
- if (create_symref(head_ref.buf,
627
- remote_head_points_at->peer_ref->name,
628
- msg) < 0)
628
+ if (refs_create_symref(get_main_ref_store(the_repository), head_ref.buf,
629
+ remote_head_points_at->peer_ref->name,
630
+ msg) < 0)
631
die(_("unable to update %s"), head_ref.buf);
632
strbuf_release(&head_ref);
633
}
@@ -637,33 +639,36 @@ static void update_head(const struct ref *our, const struct ref *remote,
639
const char *head;
640
if (our && skip_prefix(our->name, "refs/heads/", &head)) {
641
/* Local default branch link */
640
- if (create_symref("HEAD", our->name, NULL) < 0)
642
+ if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL) < 0)
643
die(_("unable to update HEAD"));
644
if (!option_bare) {
643
- update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
644
- UPDATE_REFS_DIE_ON_ERR);
645
+ refs_update_ref(get_main_ref_store(the_repository),
646
+ msg, "HEAD", &our->old_oid, NULL, 0,
647
+ UPDATE_REFS_DIE_ON_ERR);
648
install_branch_config(0, head, remote_name, our->name);
649
}
650
} else if (our) {
651
struct commit *c = lookup_commit_reference(the_repository,
652
&our->old_oid);
653
/* --branch specifies a non-branch (i.e. tags), detach HEAD */
651
- update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
652
- UPDATE_REFS_DIE_ON_ERR);
654
+ refs_update_ref(get_main_ref_store(the_repository), msg,
655
+ "HEAD", &c->object.oid, NULL, REF_NO_DEREF,
656
+ UPDATE_REFS_DIE_ON_ERR);
657
} else if (remote) {
658
/*
659
* We know remote HEAD points to a non-branch, or
660
* HEAD points to a branch but we don't know which one.
661
* Detach HEAD in all these cases.
662
*/
659
- update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NO_DEREF,
660
- UPDATE_REFS_DIE_ON_ERR);
663
+ refs_update_ref(get_main_ref_store(the_repository), msg,
664
+ "HEAD", &remote->old_oid, NULL, REF_NO_DEREF,
665
+ UPDATE_REFS_DIE_ON_ERR);
666
} else if (unborn && skip_prefix(unborn, "refs/heads/", &head)) {
667
/*
668
* Unborn head from remote; same as "our" case above except
669
* that we have no ref to update.
670
*/
666
- if (create_symref("HEAD", unborn, NULL) < 0)
671
+ if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL) < 0)
672
die(_("unable to update HEAD"));
673
if (!option_bare)
674
install_branch_config(0, head, remote_name, unborn);
@@ -704,7 +709,8 @@ static int checkout(int submodule_progress, int filter_submodules)
709
if (option_no_checkout)
710
return 0;
711
707
- head = resolve_refdup("HEAD", RESOLVE_REF_READING, &oid, NULL);
712
+ head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
713
+ RESOLVE_REF_READING, &oid, NULL);
714
if (!head) {
715
warning(_("remote HEAD refers to nonexistent ref, "
716
"unable to checkout"));
builtin/describe.c
+2
-1
@@ -638,7 +638,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
638
}
639
640
hashmap_init(&names, commit_name_neq, NULL, 0);
641
- for_each_rawref(get_name, NULL);
641
+ refs_for_each_rawref(get_main_ref_store(the_repository), get_name,
642
+ NULL);
643
if (!hashmap_get_size(&names) && !always)
644
die(_("No names found, cannot describe anything."));
645
builtin/fast-import.c
+7
-4
@@ -1604,10 +1604,11 @@ static int update_branch(struct branch *b)
1604
1605
if (is_null_oid(&b->oid)) {
1606
if (b->delete)
1607
- delete_ref(NULL, b->name, NULL, 0);
1607
+ refs_delete_ref(get_main_ref_store(the_repository),
1608
+ NULL, b->name, NULL, 0);
1609
return 0;
1610
}
1610
- if (read_ref(b->name, &old_oid))
1611
+ if (refs_read_ref(get_main_ref_store(the_repository), b->name, &old_oid))
1612
oidclr(&old_oid);
1613
if (!force_update && !is_null_oid(&old_oid)) {
1614
struct commit *old_cmit, *new_cmit;
@@ -1631,7 +1632,8 @@ static int update_branch(struct branch *b)
1632
return -1;
1633
}
1634
}
1634
- transaction = ref_transaction_begin(&err);
1635
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1636
+ &err);
1637
if (!transaction ||
1638
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
1639
0, msg, &err) ||
@@ -1665,7 +1667,8 @@ static void dump_tags(void)
1667
struct strbuf err = STRBUF_INIT;
1668
struct ref_transaction *transaction;
1669
1668
- transaction = ref_transaction_begin(&err);
1670
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1671
+ &err);
1672
if (!transaction) {
1673
failure |= error("%s", err.buf);
1674
goto cleanup;
builtin/fetch.c
+14
-6
@@ -340,7 +340,8 @@ static void find_non_local_tags(const struct ref *refs,
340
refname_hash_init(&remote_refs);
341
create_fetch_oidset(head, &fetch_oids);
342
343
- for_each_ref(add_one_refname, &existing_refs);
343
+ refs_for_each_ref(get_main_ref_store(the_repository), add_one_refname,
344
+ &existing_refs);
345
346
/*
347
* If we already have a transaction, then we need to filter out all
@@ -614,7 +615,9 @@ static struct ref *get_ref_map(struct remote *remote,
615
616
if (!existing_refs_populated) {
617
refname_hash_init(&existing_refs);
617
- for_each_ref(add_one_refname, &existing_refs);
618
+ refs_for_each_ref(get_main_ref_store(the_repository),
619
+ add_one_refname,
620
+ &existing_refs);
621
existing_refs_populated = 1;
622
}
623
@@ -659,7 +662,8 @@ static int s_update_ref(const char *action,
662
* lifecycle.
663
*/
664
if (!transaction) {
662
- transaction = our_transaction = ref_transaction_begin(&err);
665
+ transaction = our_transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
666
+ &err);
667
if (!transaction) {
668
ret = STORE_REF_ERROR_OTHER;
669
goto out;
@@ -1393,7 +1397,9 @@ static int prune_refs(struct display_state *display_state,
1397
for (ref = stale_refs; ref; ref = ref->next)
1398
string_list_append(&refnames, ref->name);
1399
1396
- result = delete_refs("fetch: prune", &refnames, 0);
1400
+ result = refs_delete_refs(get_main_ref_store(the_repository),
1401
+ "fetch: prune", &refnames,
1402
+ 0);
1403
string_list_clear(&refnames, 0);
1404
}
1405
}
@@ -1479,7 +1485,8 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
1485
continue;
1486
}
1487
old_nr = oids->nr;
1482
- for_each_glob_ref(add_oid, s, oids);
1488
+ refs_for_each_glob_ref(get_main_ref_store(the_repository),
1489
+ add_oid, s, oids);
1490
if (old_nr == oids->nr)
1491
warning("ignoring --negotiation-tip=%s because it does not match any refs",
1492
s);
@@ -1655,7 +1662,8 @@ static int do_fetch(struct transport *transport,
1662
config->display_format);
1663
1664
if (atomic_fetch) {
1658
- transaction = ref_transaction_begin(&err);
1665
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1666
+ &err);
1667
if (!transaction) {
1668
retcode = -1;
1669
goto cleanup;
builtin/fsck.c
+8
-3
@@ -514,7 +514,9 @@ static int fsck_handle_reflog(const char *logname, void *cb_data)
514
struct strbuf refname = STRBUF_INIT;
515
516
strbuf_worktree_ref(cb_data, &refname, logname);
517
- for_each_reflog_ent(refname.buf, fsck_handle_reflog_ent, refname.buf);
517
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
518
+ refname.buf, fsck_handle_reflog_ent,
519
+ refname.buf);
520
strbuf_release(&refname);
521
return 0;
522
}
@@ -563,7 +565,8 @@ static void get_default_heads(void)
565
const char *head_points_at;
566
struct object_id head_oid;
567
566
- for_each_rawref(fsck_handle_ref, NULL);
568
+ refs_for_each_rawref(get_main_ref_store(the_repository),
569
+ fsck_handle_ref, NULL);
570
571
worktrees = get_worktrees();
572
for (p = worktrees; *p; p++) {
@@ -712,7 +715,9 @@ static int fsck_head_link(const char *head_ref_name,
715
if (verbose)
716
fprintf_ln(stderr, _("Checking %s link"), head_ref_name);
717
715
- *head_points_at = resolve_ref_unsafe(head_ref_name, 0, head_oid, NULL);
718
+ *head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
719
+ head_ref_name, 0, head_oid,
720
+ NULL);
721
if (!*head_points_at) {
722
errors_found |= ERROR_REFS;
723
return error(_("invalid %s"), head_ref_name);
builtin/gc.c
+2
-1
@@ -907,7 +907,8 @@ static int should_write_commit_graph(void)
907
if (data.limit < 0)
908
return 1;
909
910
- result = for_each_ref(dfs_on_ref, &data);
910
+ result = refs_for_each_ref(get_main_ref_store(the_repository),
911
+ dfs_on_ref, &data);
912
913
repo_clear_commit_marks(the_repository, SEEN);
914
builtin/log.c
+4
-2
@@ -2226,8 +2226,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2226
2227
if (check_head) {
2228
const char *ref, *v;
2229
- ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
2230
- NULL, NULL);
2229
+ ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
2230
+ "HEAD",
2231
+ RESOLVE_REF_READING,
2232
+ NULL, NULL);
2233
if (ref && skip_prefix(ref, "refs/heads/", &v))
2234
branch_name = xstrdup(v);
2235
else
builtin/merge.c
+22
-12
@@ -449,8 +449,10 @@ static void finish(struct commit *head_commit,
449
if (verbosity >= 0 && !merge_msg.len)
450
printf(_("No merge message -- not updating HEAD\n"));
451
else {
452
- update_ref(reflog_message.buf, "HEAD", new_head, head,
453
- 0, UPDATE_REFS_DIE_ON_ERR);
452
+ refs_update_ref(get_main_ref_store(the_repository),
453
+ reflog_message.buf, "HEAD", new_head,
454
+ head,
455
+ 0, UPDATE_REFS_DIE_ON_ERR);
456
/*
457
* We ignore errors in 'gc --auto', since the
458
* user should see them.
@@ -547,7 +549,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
549
struct strbuf truname = STRBUF_INIT;
550
strbuf_addf(&truname, "refs/heads/%s", remote);
551
strbuf_setlen(&truname, truname.len - len);
550
- if (ref_exists(truname.buf)) {
552
+ if (refs_ref_exists(get_main_ref_store(the_repository), truname.buf)) {
553
strbuf_addf(msg,
554
"%s\t\tbranch '%s'%s of .\n",
555
oid_to_hex(&remote_head->object.oid),
@@ -1252,7 +1254,7 @@ static int merging_a_throwaway_tag(struct commit *commit)
1254
*/
1255
tag_ref = xstrfmt("refs/tags/%s",
1256
((struct tag *)merge_remote_util(commit)->obj)->tag);
1255
- if (!read_ref(tag_ref, &oid) &&
1257
+ if (!refs_read_ref(get_main_ref_store(the_repository), tag_ref, &oid) &&
1258
oideq(&oid, &merge_remote_util(commit)->obj->oid))
1259
is_throwaway_tag = 0;
1260
else
@@ -1284,7 +1286,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1286
* Check if we are _not_ on a detached HEAD, i.e. if there is a
1287
* current branch.
1288
*/
1287
- branch = branch_to_free = resolve_refdup("HEAD", 0, &head_oid, NULL);
1289
+ branch = branch_to_free = refs_resolve_refdup(get_main_ref_store(the_repository),
1290
+ "HEAD", 0, &head_oid,
1291
+ NULL);
1292
if (branch)
1293
skip_prefix(branch, "refs/heads/", &branch);
1294
@@ -1325,8 +1329,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1329
if (!file_exists(git_path_merge_head(the_repository)))
1330
die(_("There is no merge to abort (MERGE_HEAD missing)."));
1331
1328
- if (!read_ref("MERGE_AUTOSTASH", &stash_oid))
1329
- delete_ref("", "MERGE_AUTOSTASH", &stash_oid, REF_NO_DEREF);
1332
+ if (!refs_read_ref(get_main_ref_store(the_repository), "MERGE_AUTOSTASH", &stash_oid))
1333
+ refs_delete_ref(get_main_ref_store(the_repository),
1334
+ "", "MERGE_AUTOSTASH", &stash_oid,
1335
+ REF_NO_DEREF);
1336
1337
/* Invoke 'git reset --merge' */
1338
ret = cmd_reset(nargc, nargv, prefix);
@@ -1379,7 +1385,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1385
else
1386
die(_("You have not concluded your merge (MERGE_HEAD exists)."));
1387
}
1382
- if (ref_exists("CHERRY_PICK_HEAD")) {
1388
+ if (refs_ref_exists(get_main_ref_store(the_repository), "CHERRY_PICK_HEAD")) {
1389
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
1390
die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
1391
"Please, commit your changes before you merge."));
@@ -1450,8 +1456,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1456
1457
remote_head_oid = &remoteheads->item->object.oid;
1458
read_empty(remote_head_oid);
1453
- update_ref("initial pull", "HEAD", remote_head_oid, NULL, 0,
1454
- UPDATE_REFS_DIE_ON_ERR);
1459
+ refs_update_ref(get_main_ref_store(the_repository),
1460
+ "initial pull", "HEAD", remote_head_oid, NULL,
1461
+ 0,
1462
+ UPDATE_REFS_DIE_ON_ERR);
1463
goto done;
1464
}
1465
@@ -1531,8 +1539,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1539
free(list);
1540
}
1541
1534
- update_ref("updating ORIG_HEAD", "ORIG_HEAD",
1535
- &head_commit->object.oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
1542
+ refs_update_ref(get_main_ref_store(the_repository),
1543
+ "updating ORIG_HEAD", "ORIG_HEAD",
1544
+ &head_commit->object.oid, NULL, 0,
1545
+ UPDATE_REFS_DIE_ON_ERR);
1546
1547
if (remoteheads && !common) {
1548
/* No common ancestors found. */
builtin/name-rev.c
+3
-2
@@ -296,7 +296,8 @@ static void add_to_tip_table(const struct object_id *oid, const char *refname,
296
char *short_refname = NULL;
297
298
if (shorten_unambiguous)
299
- short_refname = shorten_unambiguous_ref(refname, 0);
299
+ short_refname = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
300
+ refname, 0);
301
else if (skip_prefix(refname, "refs/heads/", &refname))
302
; /* refname already advanced */
303
else
@@ -647,7 +648,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
648
649
adjust_cutoff_timestamp_for_slop();
650
650
- for_each_ref(name_ref, &data);
651
+ refs_for_each_ref(get_main_ref_store(the_repository), name_ref, &data);
652
name_tips(&string_pool);
653
654
if (annotate_stdin) {
builtin/notes.c
+15
-11
@@ -794,9 +794,9 @@ static int merge_abort(struct notes_merge_options *o)
794
* notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
795
*/
796
797
- if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
797
+ if (refs_delete_ref(get_main_ref_store(the_repository), NULL, "NOTES_MERGE_PARTIAL", NULL, 0))
798
ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"));
799
- if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NO_DEREF))
799
+ if (refs_delete_ref(get_main_ref_store(the_repository), NULL, "NOTES_MERGE_REF", NULL, REF_NO_DEREF))
800
ret += error(_("failed to delete ref NOTES_MERGE_REF"));
801
if (notes_merge_abort(o))
802
ret += error(_("failed to remove 'git notes merge' worktree"));
@@ -834,7 +834,8 @@ static int merge_commit(struct notes_merge_options *o)
834
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
835
836
o->local_ref = local_ref_to_free =
837
- resolve_refdup("NOTES_MERGE_REF", 0, &oid, NULL);
837
+ refs_resolve_refdup(get_main_ref_store(the_repository),
838
+ "NOTES_MERGE_REF", 0, &oid, NULL);
839
if (!o->local_ref)
840
die(_("failed to resolve NOTES_MERGE_REF"));
841
@@ -847,9 +848,10 @@ static int merge_commit(struct notes_merge_options *o)
848
&pretty_ctx);
849
strbuf_trim(&msg);
850
strbuf_insertstr(&msg, 0, "notes: ");
850
- update_ref(msg.buf, o->local_ref, &oid,
851
- is_null_oid(&parent_oid) ? NULL : &parent_oid,
852
- 0, UPDATE_REFS_DIE_ON_ERR);
851
+ refs_update_ref(get_main_ref_store(the_repository), msg.buf,
852
+ o->local_ref, &oid,
853
+ is_null_oid(&parent_oid) ? NULL : &parent_oid,
854
+ 0, UPDATE_REFS_DIE_ON_ERR);
855
856
free_notes(t);
857
strbuf_release(&msg);
@@ -961,14 +963,16 @@ static int merge(int argc, const char **argv, const char *prefix)
963
964
if (result >= 0) /* Merge resulted (trivially) in result_oid */
965
/* Update default notes ref with new commit */
964
- update_ref(msg.buf, default_notes_ref(), &result_oid, NULL, 0,
965
- UPDATE_REFS_DIE_ON_ERR);
966
+ refs_update_ref(get_main_ref_store(the_repository), msg.buf,
967
+ default_notes_ref(), &result_oid, NULL, 0,
968
+ UPDATE_REFS_DIE_ON_ERR);
969
else { /* Merge has unresolved conflicts */
970
struct worktree **worktrees;
971
const struct worktree *wt;
972
/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
970
- update_ref(msg.buf, "NOTES_MERGE_PARTIAL", &result_oid, NULL,
971
- 0, UPDATE_REFS_DIE_ON_ERR);
973
+ refs_update_ref(get_main_ref_store(the_repository), msg.buf,
974
+ "NOTES_MERGE_PARTIAL", &result_oid, NULL,
975
+ 0, UPDATE_REFS_DIE_ON_ERR);
976
/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
977
worktrees = get_worktrees();
978
wt = find_shared_symref(worktrees, "NOTES_MERGE_REF",
@@ -977,7 +981,7 @@ static int merge(int argc, const char **argv, const char *prefix)
981
die(_("a notes merge into %s is already in-progress at %s"),
982
default_notes_ref(), wt->path);
983
free_worktrees(worktrees);
980
- if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL))
984
+ if (refs_create_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL))
985
die(_("failed to store link to current notes ref (%s)"),
986
default_notes_ref());
987
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "
builtin/pack-objects.c
+7
-3
@@ -939,7 +939,8 @@ static struct object_entry **compute_write_order(void)
939
/*
940
* Mark objects that are at the tip of tags.
941
*/
942
- for_each_tag_ref(mark_tagged, NULL);
942
+ refs_for_each_tag_ref(get_main_ref_store(the_repository), mark_tagged,
943
+ NULL);
944
945
if (use_delta_islands) {
946
max_layers = compute_pack_layers(&to_pack);
@@ -4093,7 +4094,9 @@ static void mark_bitmap_preferred_tips(void)
4094
return;
4095
4096
for_each_string_list_item(item, preferred_tips) {
4096
- for_each_ref_in(item->string, mark_bitmap_preferred_tip, NULL);
4097
+ refs_for_each_ref_in(get_main_ref_store(the_repository),
4098
+ item->string, mark_bitmap_preferred_tip,
4099
+ NULL);
4100
}
4101
}
4102
@@ -4588,7 +4591,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
4591
}
4592
cleanup_preferred_base();
4593
if (include_tag && nr_result)
4591
- for_each_tag_ref(add_ref_tag, NULL);
4594
+ refs_for_each_tag_ref(get_main_ref_store(the_repository),
4595
+ add_ref_tag, NULL);
4596
stop_progress(&progress_state);
4597
trace2_region_leave("pack-objects", "enumerate-objects",
4598
the_repository);
builtin/pull.c
+1
-1
@@ -611,7 +611,7 @@ static int pull_into_void(const struct object_id *merge_head,
611
merge_head, 0))
612
return 1;
613
614
- if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
614
+ if (refs_update_ref(get_main_ref_store(the_repository), "initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
615
return 1;
616
617
return 0;
builtin/rebase.c
+10
-8
@@ -252,7 +252,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
252
if (!is_directory(merge_dir()) && mkdir_in_gitdir(merge_dir()))
253
return error_errno(_("could not create temporary %s"), merge_dir());
254
255
- delete_reflog("REBASE_HEAD");
255
+ refs_delete_reflog(get_main_ref_store(the_repository), "REBASE_HEAD");
256
257
interactive = fopen(path_interactive(), "w");
258
if (!interactive)
@@ -514,8 +514,10 @@ static int finish_rebase(struct rebase_options *opts)
514
struct strbuf dir = STRBUF_INIT;
515
int ret = 0;
516
517
- delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
518
- delete_ref(NULL, "AUTO_MERGE", NULL, REF_NO_DEREF);
517
+ refs_delete_ref(get_main_ref_store(the_repository), NULL,
518
+ "REBASE_HEAD", NULL, REF_NO_DEREF);
519
+ refs_delete_ref(get_main_ref_store(the_repository), NULL,
520
+ "AUTO_MERGE", NULL, REF_NO_DEREF);
521
apply_autostash(state_dir_path("autostash", opts));
522
/*
523
* We ignore errors in 'git maintenance run --auto', since the
@@ -1623,7 +1625,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1625
/* Is it a local branch? */
1626
strbuf_reset(&buf);
1627
strbuf_addf(&buf, "refs/heads/%s", branch_name);
1626
- if (!read_ref(buf.buf, &branch_oid)) {
1628
+ if (!refs_read_ref(get_main_ref_store(the_repository), buf.buf, &branch_oid)) {
1629
die_if_checked_out(buf.buf, 1);
1630
options.head_name = xstrdup(buf.buf);
1631
options.orig_head =
@@ -1640,8 +1642,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1642
} else if (argc == 0) {
1643
/* Do not need to switch branches, we are already on it. */
1644
options.head_name =
1643
- xstrdup_or_null(resolve_ref_unsafe("HEAD", 0, NULL,
1644
- &flags));
1645
+ xstrdup_or_null(refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL,
1646
+ &flags));
1647
if (!options.head_name)
1648
die(_("No such ref: %s"), "HEAD");
1649
if (flags & REF_ISSYMREF) {
@@ -1735,7 +1737,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1737
if (!(options.flags & REBASE_NO_QUIET))
1738
; /* be quiet */
1739
else if (!strcmp(branch_name, "HEAD") &&
1738
- resolve_ref_unsafe("HEAD", 0, NULL, &flag))
1740
+ refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL, &flag))
1741
puts(_("HEAD is up to date."));
1742
else
1743
printf(_("Current branch %s is up to date.\n"),
@@ -1745,7 +1747,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1747
} else if (!(options.flags & REBASE_NO_QUIET))
1748
; /* be quiet */
1749
else if (!strcmp(branch_name, "HEAD") &&
1748
- resolve_ref_unsafe("HEAD", 0, NULL, &flag))
1750
+ refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL, &flag))
1751
puts(_("HEAD is up to date, rebase forced."));
1752
else
1753
printf(_("Current branch %s is up to date, rebase "
builtin/receive-pack.c
+10
-5
@@ -1566,7 +1566,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
1566
struct strbuf err = STRBUF_INIT;
1567
if (!parse_object(the_repository, old_oid)) {
1568
old_oid = NULL;
1569
- if (ref_exists(name)) {
1569
+ if (refs_ref_exists(get_main_ref_store(the_repository), name)) {
1570
rp_warning("allowing deletion of corrupt ref");
1571
} else {
1572
rp_warning("deleting a non-existent ref");
@@ -1693,7 +1693,8 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
1693
int flag;
1694
1695
strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
1696
- dst_name = resolve_ref_unsafe(buf.buf, 0, NULL, &flag);
1696
+ dst_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1697
+ buf.buf, 0, NULL, &flag);
1698
check_aliased_update_internal(cmd, list, dst_name, flag);
1699
strbuf_release(&buf);
1700
}
@@ -1829,7 +1830,8 @@ static void execute_commands_non_atomic(struct command *commands,
1830
if (!should_process_cmd(cmd) || cmd->run_proc_receive)
1831
continue;
1832
1832
- transaction = ref_transaction_begin(&err);
1833
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1834
+ &err);
1835
if (!transaction) {
1836
rp_error("%s", err.buf);
1837
strbuf_reset(&err);
@@ -1857,7 +1859,8 @@ static void execute_commands_atomic(struct command *commands,
1859
struct strbuf err = STRBUF_INIT;
1860
const char *reported_error = "atomic push failure";
1861
1860
- transaction = ref_transaction_begin(&err);
1862
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1863
+ &err);
1864
if (!transaction) {
1865
rp_error("%s", err.buf);
1866
strbuf_reset(&err);
@@ -1983,7 +1986,9 @@ static void execute_commands(struct command *commands,
1986
check_aliased_updates(commands);
1987
1988
free(head_name_to_free);
1986
- head_name = head_name_to_free = resolve_refdup("HEAD", 0, NULL, NULL);
1989
+ head_name = head_name_to_free = refs_resolve_refdup(get_main_ref_store(the_repository),
1990
+ "HEAD", 0, NULL,
1991
+ NULL);
1992
1993
if (run_proc_receive &&
1994
run_proc_receive_hook(commands, push_options))
builtin/reflog.c
+14
-11
@@ -364,11 +364,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
364
};
365
366
set_reflog_expiry_param(&cb.cmd, item->string);
367
- status |= reflog_expire(item->string, flags,
368
- reflog_expiry_prepare,
369
- should_prune_fn,
370
- reflog_expiry_cleanup,
371
- &cb);
367
+ status |= refs_reflog_expire(get_main_ref_store(the_repository),
368
+ item->string, flags,
369
+ reflog_expiry_prepare,
370
+ should_prune_fn,
371
+ reflog_expiry_cleanup,
372
+ &cb);
373
}
374
string_list_clear(&collected.reflogs, 0);
375
}
@@ -382,11 +383,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
383
continue;
384
}
385
set_reflog_expiry_param(&cb.cmd, ref);
385
- status |= reflog_expire(ref, flags,
386
- reflog_expiry_prepare,
387
- should_prune_fn,
388
- reflog_expiry_cleanup,
389
- &cb);
386
+ status |= refs_reflog_expire(get_main_ref_store(the_repository),
387
+ ref, flags,
388
+ reflog_expiry_prepare,
389
+ should_prune_fn,
390
+ reflog_expiry_cleanup,
391
+ &cb);
392
free(ref);
393
}
394
return status;
@@ -437,7 +439,8 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix)
439
refname = argv[0];
440
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
441
die(_("invalid ref format: %s"), refname);
440
- return !reflog_exists(refname);
442
+ return !refs_reflog_exists(get_main_ref_store(the_repository),
443
+ refname);
444
}
445
446
/*
builtin/remote.c
+22
-15
@@ -240,7 +240,7 @@ static int add(int argc, const char **argv, const char *prefix)
240
strbuf_reset(&buf2);
241
strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
242
243
- if (create_symref(buf.buf, buf2.buf, "remote add"))
243
+ if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add"))
244
return error(_("Could not setup master '%s'"), master);
245
}
246
@@ -376,7 +376,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
376
for (ref = fetch_map; ref; ref = ref->next) {
377
if (omit_name_by_refspec(ref->name, &states->remote->fetch))
378
string_list_append(&states->skipped, abbrev_branch(ref->name));
379
- else if (!ref->peer_ref || !ref_exists(ref->peer_ref->name))
379
+ else if (!ref->peer_ref || !refs_ref_exists(get_main_ref_store(the_repository), ref->peer_ref->name))
380
string_list_append(&states->new_refs, abbrev_branch(ref->name));
381
else
382
string_list_append(&states->tracked, abbrev_branch(ref->name));
@@ -598,8 +598,9 @@ static int read_remote_branches(const char *refname,
598
strbuf_addf(&buf, "refs/remotes/%s/", rename->old_name);
599
if (starts_with(refname, buf.buf)) {
600
item = string_list_append(rename->remote_branches, refname);
601
- symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,
602
- NULL, &flag);
601
+ symref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
602
+ refname, RESOLVE_REF_READING,
603
+ NULL, &flag);
604
if (symref && (flag & REF_ISSYMREF)) {
605
item->util = xstrdup(symref);
606
rename->symrefs_nr++;
@@ -789,7 +790,8 @@ static int mv(int argc, const char **argv, const char *prefix)
790
* First remove symrefs, then rename the rest, finally create
791
* the new symrefs.
792
*/
792
- for_each_ref(read_remote_branches, &rename);
793
+ refs_for_each_ref(get_main_ref_store(the_repository),
794
+ read_remote_branches, &rename);
795
if (show_progress) {
796
/*
797
* Count symrefs twice, since "renaming" them is done by
@@ -805,7 +807,7 @@ static int mv(int argc, const char **argv, const char *prefix)
807
if (refs_read_symbolic_ref(get_main_ref_store(the_repository), item->string,
808
&referent))
809
continue;
808
- if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
810
+ if (refs_delete_ref(get_main_ref_store(the_repository), NULL, item->string, NULL, REF_NO_DEREF))
811
die(_("deleting '%s' failed"), item->string);
812
813
strbuf_release(&referent);
@@ -823,7 +825,7 @@ static int mv(int argc, const char **argv, const char *prefix)
825
strbuf_reset(&buf2);
826
strbuf_addf(&buf2, "remote: renamed %s to %s",
827
item->string, buf.buf);
826
- if (rename_ref(item->string, buf.buf, buf2.buf))
828
+ if (refs_rename_ref(get_main_ref_store(the_repository), item->string, buf.buf, buf2.buf))
829
die(_("renaming '%s' failed"), item->string);
830
display_progress(progress, ++refs_renamed_nr);
831
}
@@ -843,7 +845,7 @@ static int mv(int argc, const char **argv, const char *prefix)
845
strbuf_reset(&buf3);
846
strbuf_addf(&buf3, "remote: renamed %s to %s",
847
item->string, buf.buf);
846
- if (create_symref(buf.buf, buf2.buf, buf3.buf))
848
+ if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf))
849
die(_("creating '%s' failed"), buf.buf);
850
display_progress(progress, ++refs_renamed_nr);
851
}
@@ -917,11 +919,14 @@ static int rm(int argc, const char **argv, const char *prefix)
919
* refs, which are invalidated when deleting a branch.
920
*/
921
cb_data.remote = remote;
920
- result = for_each_ref(add_branch_for_removal, &cb_data);
922
+ result = refs_for_each_ref(get_main_ref_store(the_repository),
923
+ add_branch_for_removal, &cb_data);
924
strbuf_release(&buf);
925
926
if (!result)
924
- result = delete_refs("remote: remove", &branches, REF_NO_DEREF);
927
+ result = refs_delete_refs(get_main_ref_store(the_repository),
928
+ "remote: remove", &branches,
929
+ REF_NO_DEREF);
930
string_list_clear(&branches, 0);
931
932
if (skipped.nr) {
@@ -1010,7 +1015,8 @@ static int get_remote_ref_states(const char *name,
1015
get_push_ref_states(remote_refs, states);
1016
transport_disconnect(transport);
1017
} else {
1013
- for_each_ref(append_ref_to_tracked_list, states);
1018
+ refs_for_each_ref(get_main_ref_store(the_repository),
1019
+ append_ref_to_tracked_list, states);
1020
string_list_sort(&states->tracked);
1021
get_push_ref_states_noquery(states);
1022
}
@@ -1407,7 +1413,7 @@ static int set_head(int argc, const char **argv, const char *prefix)
1413
head_name = xstrdup(states.heads.items[0].string);
1414
free_remote_ref_states(&states);
1415
} else if (opt_d && !opt_a && argc == 1) {
1410
- if (delete_ref(NULL, buf.buf, NULL, REF_NO_DEREF))
1416
+ if (refs_delete_ref(get_main_ref_store(the_repository), NULL, buf.buf, NULL, REF_NO_DEREF))
1417
result |= error(_("Could not delete %s"), buf.buf);
1418
} else
1419
usage_with_options(builtin_remote_sethead_usage, options);
@@ -1415,9 +1421,9 @@ static int set_head(int argc, const char **argv, const char *prefix)
1421
if (head_name) {
1422
strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
1423
/* make sure it's valid */
1418
- if (!ref_exists(buf2.buf))
1424
+ if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf))
1425
result |= error(_("Not a valid ref: %s"), buf2.buf);
1420
- else if (create_symref(buf.buf, buf2.buf, "remote set-head"))
1426
+ else if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head"))
1427
result |= error(_("Could not setup %s"), buf.buf);
1428
else if (opt_a)
1429
printf("%s/HEAD set to %s\n", argv[0], head_name);
@@ -1457,7 +1463,8 @@ static int prune_remote(const char *remote, int dry_run)
1463
string_list_sort(&refs_to_prune);
1464
1465
if (!dry_run)
1460
- result |= delete_refs("remote: prune", &refs_to_prune, 0);
1466
+ result |= refs_delete_refs(get_main_ref_store(the_repository),
1467
+ "remote: prune", &refs_to_prune, 0);
1468
1469
for_each_string_list_item(item, &states.stale) {
1470
const char *refname = item->util;
builtin/repack.c
+5
-2
@@ -706,11 +706,14 @@ static void midx_snapshot_refs(struct tempfile *f)
706
707
data.preferred = 1;
708
for_each_string_list_item(item, preferred)
709
- for_each_ref_in(item->string, midx_snapshot_ref_one, &data);
709
+ refs_for_each_ref_in(get_main_ref_store(the_repository),
710
+ item->string,
711
+ midx_snapshot_ref_one, &data);
712
data.preferred = 0;
713
}
714
713
- for_each_ref(midx_snapshot_ref_one, &data);
715
+ refs_for_each_ref(get_main_ref_store(the_repository),
716
+ midx_snapshot_ref_one, &data);
717
718
if (close_tempfile_gently(f)) {
719
int save_errno = errno;
builtin/replace.c
+5
-4
@@ -130,7 +130,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
130
strbuf_addstr(&ref, oid_to_hex(&oid));
131
full_hex = ref.buf + base_len;
132
133
- if (read_ref(ref.buf, &oid)) {
133
+ if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &oid)) {
134
error(_("replace ref '%s' not found"), full_hex);
135
had_error = 1;
136
continue;
@@ -145,7 +145,7 @@ static int for_each_replace_name(const char **argv, each_replace_name_fn fn)
145
static int delete_replace_ref(const char *name, const char *ref,
146
const struct object_id *oid)
147
{
148
- if (delete_ref(NULL, ref, oid, 0))
148
+ if (refs_delete_ref(get_main_ref_store(the_repository), NULL, ref, oid, 0))
149
return 1;
150
printf_ln(_("Deleted replace ref '%s'"), name);
151
return 0;
@@ -163,7 +163,7 @@ static int check_ref_valid(struct object_id *object,
163
if (check_refname_format(ref->buf, 0))
164
return error(_("'%s' is not a valid ref name"), ref->buf);
165
166
- if (read_ref(ref->buf, prev))
166
+ if (refs_read_ref(get_main_ref_store(the_repository), ref->buf, prev))
167
oidclr(prev);
168
else if (!force)
169
return error(_("replace ref '%s' already exists"), ref->buf);
@@ -198,7 +198,8 @@ static int replace_object_oid(const char *object_ref,
198
return -1;
199
}
200
201
- transaction = ref_transaction_begin(&err);
201
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
202
+ &err);
203
if (!transaction ||
204
ref_transaction_update(transaction, ref.buf, repl, &prev,
205
0, NULL, &err) ||
builtin/reset.c
+8
-5
@@ -307,13 +307,16 @@ static int reset_refs(const char *rev, const struct object_id *oid)
307
if (!repo_get_oid(the_repository, "HEAD", &oid_orig)) {
308
orig = &oid_orig;
309
set_reflog_message(&msg, "updating ORIG_HEAD", NULL);
310
- update_ref(msg.buf, "ORIG_HEAD", orig, old_orig, 0,
311
- UPDATE_REFS_MSG_ON_ERR);
310
+ refs_update_ref(get_main_ref_store(the_repository), msg.buf,
311
+ "ORIG_HEAD", orig, old_orig, 0,
312
+ UPDATE_REFS_MSG_ON_ERR);
313
} else if (old_orig)
313
- delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
314
+ refs_delete_ref(get_main_ref_store(the_repository), NULL,
315
+ "ORIG_HEAD", old_orig, 0);
316
set_reflog_message(&msg, "updating HEAD", rev);
315
- update_ref_status = update_ref(msg.buf, "HEAD", oid, orig, 0,
316
- UPDATE_REFS_MSG_ON_ERR);
317
+ update_ref_status = refs_update_ref(get_main_ref_store(the_repository),
318
+ msg.buf, "HEAD", oid, orig, 0,
319
+ UPDATE_REFS_MSG_ON_ERR);
320
strbuf_release(&msg);
321
return update_ref_status;
322
}
builtin/rev-parse.c
+18
-7
@@ -160,8 +160,9 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
160
case 1: /* happy */
161
if (abbrev_ref) {
162
char *old = full;
163
- full = shorten_unambiguous_ref(full,
164
- abbrev_ref_strict);
163
+ full = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
164
+ full,
165
+ abbrev_ref_strict);
166
free(old);
167
}
168
show_with_type(type, full);
@@ -599,9 +600,12 @@ static int opt_with_value(const char *arg, const char *opt, const char **value)
600
static void handle_ref_opt(const char *pattern, const char *prefix)
601
{
602
if (pattern)
602
- for_each_glob_ref_in(show_reference, pattern, prefix, NULL);
603
+ refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
604
+ show_reference, pattern, prefix,
605
+ NULL);
606
else
604
- for_each_ref_in(prefix, show_reference, NULL);
607
+ refs_for_each_ref_in(get_main_ref_store(the_repository),
608
+ prefix, show_reference, NULL);
609
clear_ref_exclusions(&ref_excludes);
610
}
611
@@ -898,7 +902,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
902
continue;
903
}
904
if (!strcmp(arg, "--all")) {
901
- for_each_ref(show_reference, NULL);
905
+ refs_for_each_ref(get_main_ref_store(the_repository),
906
+ show_reference, NULL);
907
clear_ref_exclusions(&ref_excludes);
908
continue;
909
}
@@ -908,8 +913,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
913
continue;
914
}
915
if (!strcmp(arg, "--bisect")) {
911
- for_each_fullref_in("refs/bisect/bad", NULL, show_reference, NULL);
912
- for_each_fullref_in("refs/bisect/good", NULL, anti_reference, NULL);
916
+ refs_for_each_fullref_in(get_main_ref_store(the_repository),
917
+ "refs/bisect/bad",
918
+ NULL, show_reference,
919
+ NULL);
920
+ refs_for_each_fullref_in(get_main_ref_store(the_repository),
921
+ "refs/bisect/good",
922
+ NULL, anti_reference,
923
+ NULL);
924
continue;
925
}
926
if (opt_with_value(arg, "--branches", &arg)) {
builtin/show-branch.c
+14
-8
@@ -479,13 +479,15 @@ static void snarf_refs(int head, int remotes)
479
if (head) {
480
int orig_cnt = ref_name_cnt;
481
482
- for_each_ref(append_head_ref, NULL);
482
+ refs_for_each_ref(get_main_ref_store(the_repository),
483
+ append_head_ref, NULL);
484
sort_ref_range(orig_cnt, ref_name_cnt);
485
}
486
if (remotes) {
487
int orig_cnt = ref_name_cnt;
488
488
- for_each_ref(append_remote_ref, NULL);
489
+ refs_for_each_ref(get_main_ref_store(the_repository),
490
+ append_remote_ref, NULL);
491
sort_ref_range(orig_cnt, ref_name_cnt);
492
}
493
}
@@ -549,7 +551,8 @@ static void append_one_rev(const char *av)
551
552
match_ref_pattern = av;
553
match_ref_slash = count_slashes(av);
552
- for_each_ref(append_matching_ref, NULL);
554
+ refs_for_each_ref(get_main_ref_store(the_repository),
555
+ append_matching_ref, NULL);
556
if (saved_matches == ref_name_cnt &&
557
ref_name_cnt < MAX_REVS)
558
error(_("no matching refs with %s"), av);
@@ -740,9 +743,11 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
743
if (ac == 0) {
744
static const char *fake_av[2];
745
743
- fake_av[0] = resolve_refdup("HEAD",
744
- RESOLVE_REF_READING, &oid,
745
- NULL);
746
+ fake_av[0] = refs_resolve_refdup(get_main_ref_store(the_repository),
747
+ "HEAD",
748
+ RESOLVE_REF_READING,
749
+ &oid,
750
+ NULL);
751
fake_av[1] = NULL;
752
av = fake_av;
753
ac = 1;
@@ -815,8 +820,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
820
snarf_refs(all_heads, all_remotes);
821
}
822
818
- head = resolve_refdup("HEAD", RESOLVE_REF_READING,
819
- &head_oid, NULL);
823
+ head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
824
+ RESOLVE_REF_READING,
825
+ &head_oid, NULL);
826
827
if (with_current_branch && head) {
828
int has_head = 0;
builtin/show-ref.c
+13
-6
@@ -129,7 +129,8 @@ static int cmd_show_ref__exclude_existing(const struct exclude_existing_options
129
char buf[1024];
130
int patternlen = opts->pattern ? strlen(opts->pattern) : 0;
131
132
- for_each_ref(add_existing, &existing_refs);
132
+ refs_for_each_ref(get_main_ref_store(the_repository), add_existing,
133
+ &existing_refs);
134
while (fgets(buf, sizeof(buf), stdin)) {
135
char *ref;
136
int len = strlen(buf);
@@ -173,7 +174,7 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
174
struct object_id oid;
175
176
if ((starts_with(*refs, "refs/") || refname_is_safe(*refs)) &&
176
- !read_ref(*refs, &oid)) {
177
+ !refs_read_ref(get_main_ref_store(the_repository), *refs, &oid)) {
178
show_one(show_one_opts, *refs, &oid);
179
}
180
else if (!show_one_opts->quiet)
@@ -205,14 +206,20 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
206
show_ref_data.patterns = patterns;
207
208
if (opts->show_head)
208
- head_ref(show_ref, &show_ref_data);
209
+ refs_head_ref(get_main_ref_store(the_repository), show_ref,
210
+ &show_ref_data);
211
if (opts->heads_only || opts->tags_only) {
212
if (opts->heads_only)
211
- for_each_fullref_in("refs/heads/", NULL, show_ref, &show_ref_data);
213
+ refs_for_each_fullref_in(get_main_ref_store(the_repository),
214
+ "refs/heads/", NULL,
215
+ show_ref, &show_ref_data);
216
if (opts->tags_only)
213
- for_each_fullref_in("refs/tags/", NULL, show_ref, &show_ref_data);
217
+ refs_for_each_fullref_in(get_main_ref_store(the_repository),
218
+ "refs/tags/", NULL, show_ref,
219
+ &show_ref_data);
220
} else {
215
- for_each_ref(show_ref, &show_ref_data);
221
+ refs_for_each_ref(get_main_ref_store(the_repository),
222
+ show_ref, &show_ref_data);
223
}
224
if (!show_ref_data.found_match)
225
return 1;
builtin/stash.c
+13
-10
@@ -196,7 +196,7 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv)
196
commit = argv[0];
197
198
if (!commit) {
199
- if (!ref_exists(ref_stash)) {
199
+ if (!refs_ref_exists(get_main_ref_store(the_repository), ref_stash)) {
200
fprintf_ln(stderr, _("No stash entries found."));
201
return -1;
202
}
@@ -244,7 +244,8 @@ static int do_clear_stash(void)
244
if (repo_get_oid(the_repository, ref_stash, &obj))
245
return 0;
246
247
- return delete_ref(NULL, ref_stash, &obj, 0);
247
+ return refs_delete_ref(get_main_ref_store(the_repository), NULL,
248
+ ref_stash, &obj, 0);
249
}
250
251
static int clear_stash(int argc, const char **argv, const char *prefix)
@@ -687,7 +688,8 @@ static int reject_reflog_ent(struct object_id *ooid UNUSED,
688
689
static int reflog_is_empty(const char *refname)
690
{
690
- return !for_each_reflog_ent(refname, reject_reflog_ent, NULL);
691
+ return !refs_for_each_reflog_ent(get_main_ref_store(the_repository),
692
+ refname, reject_reflog_ent, NULL);
693
}
694
695
static int do_drop_stash(struct stash_info *info, int quiet)
@@ -824,7 +826,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
826
git_stash_list_usage,
827
PARSE_OPT_KEEP_UNKNOWN_OPT);
828
827
- if (!ref_exists(ref_stash))
829
+ if (!refs_ref_exists(get_main_ref_store(the_repository), ref_stash))
830
return 0;
831
832
cp.git_cmd = 1;
@@ -998,10 +1000,10 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms
1000
if (!stash_msg)
1001
stash_msg = "Created via \"git stash store\".";
1002
1001
- if (update_ref(stash_msg, ref_stash, w_commit, NULL,
1002
- REF_FORCE_CREATE_REFLOG,
1003
- quiet ? UPDATE_REFS_QUIET_ON_ERR :
1004
- UPDATE_REFS_MSG_ON_ERR)) {
1003
+ if (refs_update_ref(get_main_ref_store(the_repository), stash_msg, ref_stash, w_commit, NULL,
1004
+ REF_FORCE_CREATE_REFLOG,
1005
+ quiet ? UPDATE_REFS_QUIET_ON_ERR :
1006
+ UPDATE_REFS_MSG_ON_ERR)) {
1007
if (!quiet) {
1008
fprintf_ln(stderr, _("Cannot update %s with %s"),
1009
ref_stash, oid_to_hex(w_commit));
@@ -1384,7 +1386,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
1386
goto done;
1387
}
1388
1387
- branch_ref = resolve_ref_unsafe("HEAD", 0, NULL, &flags);
1389
+ branch_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1390
+ "HEAD", 0, NULL, &flags);
1391
if (flags & REF_ISSYMREF)
1392
skip_prefix(branch_ref, "refs/heads/", &branch_name);
1393
head_short_sha1 = repo_find_unique_abbrev(the_repository,
@@ -1566,7 +1569,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
1569
goto done;
1570
}
1571
1569
- if (!reflog_exists(ref_stash) && do_clear_stash()) {
1572
+ if (!refs_reflog_exists(get_main_ref_store(the_repository), ref_stash) && do_clear_stash()) {
1573
ret = -1;
1574
if (!quiet)
1575
fprintf_ln(stderr, _("Cannot initialize stash"));
builtin/submodule--helper.c
+5
-2
@@ -2390,7 +2390,9 @@ static int remote_submodule_branch(const char *path, const char **branch)
2390
}
2391
2392
if (!strcmp(*branch, ".")) {
2393
- const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL);
2393
+ const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
2394
+ "HEAD", 0, NULL,
2395
+ NULL);
2396
2397
if (!refname)
2398
return die_message(_("No such ref: %s"), "HEAD");
@@ -2796,7 +2798,8 @@ static int push_check(int argc, const char **argv, const char *prefix UNUSED)
2798
argv++;
2799
argc--;
2800
/* Get the submodule's head ref and determine if it is detached */
2799
- head = resolve_refdup("HEAD", 0, &head_oid, NULL);
2801
+ head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
2802
+ 0, &head_oid, NULL);
2803
if (!head)
2804
die(_("Failed to resolve HEAD as a valid ref."));
2805
if (!strcmp(head, "HEAD"))
builtin/symbolic-ref.c
+9
-4
@@ -18,7 +18,8 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int recurse, i
18
const char *refname;
19
20
resolve_flags = (recurse ? 0 : RESOLVE_REF_NO_RECURSE);
21
- refname = resolve_ref_unsafe(HEAD, resolve_flags, NULL, &flag);
21
+ refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
22
+ HEAD, resolve_flags, NULL, &flag);
23
24
if (!refname)
25
die("No such ref: %s", HEAD);
@@ -31,7 +32,9 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int recurse, i
32
if (print) {
33
char *to_free = NULL;
34
if (shorten)
34
- refname = to_free = shorten_unambiguous_ref(refname, 0);
35
+ refname = to_free = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
36
+ refname,
37
+ 0);
38
puts(refname);
39
free(to_free);
40
}
@@ -66,7 +69,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
69
die("Cannot delete %s, not a symbolic ref", argv[0]);
70
if (!strcmp(argv[0], "HEAD"))
71
die("deleting '%s' is not allowed", argv[0]);
69
- return delete_ref(NULL, argv[0], NULL, REF_NO_DEREF);
72
+ return refs_delete_ref(get_main_ref_store(the_repository),
73
+ NULL, argv[0], NULL, REF_NO_DEREF);
74
}
75
76
switch (argc) {
@@ -79,7 +83,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
83
die("Refusing to point HEAD outside of refs/");
84
if (check_refname_format(argv[1], REFNAME_ALLOW_ONELEVEL) < 0)
85
die("Refusing to set '%s' to invalid ref '%s'", argv[0], argv[1]);
82
- ret = !!create_symref(argv[0], argv[1], msg);
86
+ ret = !!refs_create_symref(get_main_ref_store(the_repository),
87
+ argv[0], argv[1], msg);
88
break;
89
default:
90
usage_with_options(git_symbolic_ref_usage, options);
builtin/tag.c
+6
-5
@@ -87,7 +87,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
87
for (p = argv; *p; p++) {
88
strbuf_reset(&ref);
89
strbuf_addf(&ref, "refs/tags/%s", *p);
90
- if (read_ref(ref.buf, &oid)) {
90
+ if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &oid)) {
91
error(_("tag '%s' not found."), *p);
92
had_error = 1;
93
continue;
@@ -116,13 +116,13 @@ static int delete_tags(const char **argv)
116
struct string_list_item *item;
117
118
result = for_each_tag_name(argv, collect_tags, (void *)&refs_to_delete);
119
- if (delete_refs(NULL, &refs_to_delete, REF_NO_DEREF))
119
+ if (refs_delete_refs(get_main_ref_store(the_repository), NULL, &refs_to_delete, REF_NO_DEREF))
120
result = 1;
121
122
for_each_string_list_item(item, &refs_to_delete) {
123
const char *name = item->string;
124
struct object_id *oid = item->util;
125
- if (!ref_exists(name))
125
+ if (!refs_ref_exists(get_main_ref_store(the_repository), name))
126
printf(_("Deleted tag '%s' (was %s)\n"),
127
item->string + 10,
128
repo_find_unique_abbrev(the_repository, oid, DEFAULT_ABBREV));
@@ -630,7 +630,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
630
if (strbuf_check_tag_ref(&ref, tag))
631
die(_("'%s' is not a valid tag name."), tag);
632
633
- if (read_ref(ref.buf, &prev))
633
+ if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
634
oidclr(&prev);
635
else if (!force)
636
die(_("tag '%s' already exists"), tag);
@@ -657,7 +657,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
657
path);
658
}
659
660
- transaction = ref_transaction_begin(&err);
660
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
661
+ &err);
662
if (!transaction ||
663
ref_transaction_update(transaction, ref.buf, &object, &prev,
664
create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
builtin/update-index.c
+1
-1
@@ -682,7 +682,7 @@ static int do_reupdate(const char **paths,
682
PATHSPEC_PREFER_CWD,
683
prefix, paths);
684
685
- if (read_ref("HEAD", &head_oid))
685
+ if (refs_read_ref(get_main_ref_store(the_repository), "HEAD", &head_oid))
686
/* If there is no HEAD, that means it is an initial
687
* commit. Update everything in the index.
688
*/
builtin/update-ref.c
+13
-8
@@ -397,7 +397,8 @@ static void update_refs_stdin(void)
397
struct ref_transaction *transaction;
398
int i, j;
399
400
- transaction = ref_transaction_begin(&err);
400
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
401
+ &err);
402
if (!transaction)
403
die("%s", err.buf);
404
@@ -464,7 +465,8 @@ static void update_refs_stdin(void)
465
* get a "start".
466
*/
467
state = cmd->state;
467
- transaction = ref_transaction_begin(&err);
468
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
469
+ &err);
470
if (!transaction)
471
die("%s", err.buf);
472
@@ -571,11 +573,14 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
573
* For purposes of backwards compatibility, we treat
574
* NULL_SHA1 as "don't care" here:
575
*/
574
- return delete_ref(msg, refname,
575
- (oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
576
- default_flags);
576
+ return refs_delete_ref(get_main_ref_store(the_repository),
577
+ msg, refname,
578
+ (oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
579
+ default_flags);
580
else
578
- return update_ref(msg, refname, &oid, oldval ? &oldoid : NULL,
579
- default_flags | create_reflog_flag,
580
- UPDATE_REFS_DIE_ON_ERR);
581
+ return refs_update_ref(get_main_ref_store(the_repository),
582
+ msg, refname, &oid,
583
+ oldval ? &oldoid : NULL,
584
+ default_flags | create_reflog_flag,
585
+ UPDATE_REFS_DIE_ON_ERR);
586
}
builtin/worktree.c
+11
-8
@@ -433,7 +433,7 @@ static int add_worktree(const char *path, const char *refname,
433
434
/* is 'refname' a branch or commit? */
435
if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
436
- ref_exists(symref.buf)) {
436
+ refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
437
is_branch = 1;
438
if (!opts->force)
439
die_if_checked_out(symref.buf, 0);
@@ -605,7 +605,7 @@ static void print_preparing_worktree_line(int detach,
605
} else {
606
struct strbuf s = STRBUF_INIT;
607
if (!detach && !strbuf_check_branch_ref(&s, branch) &&
608
- ref_exists(s.buf))
608
+ refs_ref_exists(get_main_ref_store(the_repository), s.buf))
609
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
610
branch);
611
else {
@@ -647,9 +647,9 @@ static int first_valid_ref(const char *refname UNUSED,
647
*/
648
static int can_use_local_refs(const struct add_opts *opts)
649
{
650
- if (head_ref(first_valid_ref, NULL)) {
650
+ if (refs_head_ref(get_main_ref_store(the_repository), first_valid_ref, NULL)) {
651
return 1;
652
- } else if (for_each_branch_ref(first_valid_ref, NULL)) {
652
+ } else if (refs_for_each_branch_ref(get_main_ref_store(the_repository), first_valid_ref, NULL)) {
653
if (!opts->quiet) {
654
struct strbuf path = STRBUF_INIT;
655
struct strbuf contents = STRBUF_INIT;
@@ -689,7 +689,7 @@ static int can_use_remote_refs(const struct add_opts *opts)
689
{
690
if (!guess_remote) {
691
return 0;
692
- } else if (for_each_remote_ref(first_valid_ref, NULL)) {
692
+ } else if (refs_for_each_remote_ref(get_main_ref_store(the_repository), first_valid_ref, NULL)) {
693
return 1;
694
} else if (!opts->force && remote_get(NULL)) {
695
die(_("No local or remote refs exist despite at least one remote\n"
@@ -747,7 +747,8 @@ static const char *dwim_branch(const char *path, const char **new_branch)
747
UNLEAK(branchname);
748
749
branch_exists = !strbuf_check_branch_ref(&ref, branchname) &&
750
- ref_exists(ref.buf);
750
+ refs_ref_exists(get_main_ref_store(the_repository),
751
+ ref.buf);
752
strbuf_release(&ref);
753
if (branch_exists)
754
return branchname;
@@ -838,7 +839,7 @@ static int add(int ac, const char **av, const char *prefix)
839
840
if (!opts.force &&
841
!strbuf_check_branch_ref(&symref, new_branch) &&
841
- ref_exists(symref.buf))
842
+ refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
843
die_if_checked_out(symref.buf, 0);
844
strbuf_release(&symref);
845
}
@@ -974,7 +975,9 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
975
if (wt->is_detached)
976
strbuf_addstr(&sb, "(detached HEAD)");
977
else if (wt->head_ref) {
977
- char *ref = shorten_unambiguous_ref(wt->head_ref, 0);
978
+ char *ref = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
979
+ wt->head_ref,
980
+ 0);
981
strbuf_addf(&sb, "[%s]", ref);
982
free(ref);
983
} else
bundle-uri.c
+7
-5
@@ -395,11 +395,13 @@ static int unbundle_from_file(struct repository *r, const char *file)
395
strbuf_setlen(&bundle_ref, bundle_prefix_len);
396
strbuf_addstr(&bundle_ref, branch_name);
397
398
- has_old = !read_ref(bundle_ref.buf, &old_oid);
399
- update_ref("fetched bundle", bundle_ref.buf, oid,
400
- has_old ? &old_oid : NULL,
401
- REF_SKIP_OID_VERIFICATION,
402
- UPDATE_REFS_MSG_ON_ERR);
398
+ has_old = !refs_read_ref(get_main_ref_store(the_repository),
399
+ bundle_ref.buf, &old_oid);
400
+ refs_update_ref(get_main_ref_store(the_repository),
401
+ "fetched bundle", bundle_ref.buf, oid,
402
+ has_old ? &old_oid : NULL,
403
+ REF_SKIP_OID_VERIFICATION,
404
+ UPDATE_REFS_MSG_ON_ERR);
405
}
406
407
bundle_header_release(&header);
bundle.c
+1
-1
@@ -389,7 +389,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
389
if (repo_dwim_ref(the_repository, e->name, strlen(e->name),
390
&oid, &ref, 0) != 1)
391
goto skip_write_ref;
392
- if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
392
+ if (refs_read_ref_full(get_main_ref_store(the_repository), e->name, RESOLVE_REF_READING, &oid, &flag))
393
flag = 0;
394
display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
395
commit-graph.c
+2
-1
@@ -1845,7 +1845,8 @@ int write_commit_graph_reachable(struct object_directory *odb,
1845
data.progress = start_delayed_progress(
1846
_("Collecting referenced commits"), 0);
1847
1848
- for_each_ref(add_ref_to_set, &data);
1848
+ refs_for_each_ref(get_main_ref_store(the_repository), add_ref_to_set,
1849
+ &data);
1850
1851
stop_progress(&data.progress);
1852
commit.c
+2
-1
@@ -1070,7 +1070,8 @@ struct commit *get_fork_point(const char *refname, struct commit *commit)
1070
1071
memset(&revs, 0, sizeof(revs));
1072
revs.initial = 1;
1073
- for_each_reflog_ent(full_refname, collect_one_reflog_ent, &revs);
1073
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
1074
+ full_refname, collect_one_reflog_ent, &revs);
1075
1076
if (!revs.nr)
1077
add_one_commit(&oid, &revs);
config.c
+2
-1
@@ -303,7 +303,8 @@ static int include_by_branch(const char *cond, size_t cond_len)
303
int ret;
304
struct strbuf pattern = STRBUF_INIT;
305
const char *refname = !the_repository->gitdir ?
306
- NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags);
306
+ NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
307
+ "HEAD", 0, NULL, &flags);
308
const char *shortname;
309
310
if (!refname || !(flags & REF_ISSYMREF) ||
delta-islands.c
+2
-1
@@ -488,7 +488,8 @@ void load_delta_islands(struct repository *r, int progress)
488
489
git_config(island_config_callback, &ild);
490
ild.remote_islands = kh_init_str();
491
- for_each_ref(find_island_for_ref, &ild);
491
+ refs_for_each_ref(get_main_ref_store(the_repository),
492
+ find_island_for_ref, &ild);
493
free_config_regexes(&ild);
494
deduplicate_islands(ild.remote_islands, r);
495
free_remote_islands(ild.remote_islands);
fetch-pack.c
+4
-2
@@ -290,7 +290,8 @@ static void mark_tips(struct fetch_negotiator *negotiator,
290
int i;
291
292
if (!negotiation_tips) {
293
- for_each_rawref(rev_list_insert_ref_oid, negotiator);
293
+ refs_for_each_rawref(get_main_ref_store(the_repository),
294
+ rev_list_insert_ref_oid, negotiator);
295
return;
296
}
297
@@ -793,7 +794,8 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
794
*/
795
trace2_region_enter("fetch-pack", "mark_complete_local_refs", NULL);
796
if (!args->deepen) {
796
- for_each_rawref(mark_complete_oid, NULL);
797
+ refs_for_each_rawref(get_main_ref_store(the_repository),
798
+ mark_complete_oid, NULL);
799
for_each_cached_alternate(NULL, mark_alternate_complete);
800
commit_list_sort_by_date(&complete);
801
if (cutoff)
fmt-merge-msg.c
+3
-1
@@ -661,7 +661,9 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
661
662
/* learn the commit that we merge into and the current branch name */
663
current_branch = current_branch_to_free =
664
- resolve_refdup("HEAD", RESOLVE_REF_READING, &head_oid, NULL);
664
+ refs_resolve_refdup(get_main_ref_store(the_repository),
665
+ "HEAD", RESOLVE_REF_READING, &head_oid,
666
+ NULL);
667
if (!current_branch)
668
die("No current branch");
669
help.c
+3
-2
@@ -800,7 +800,7 @@ static int append_similar_ref(const char *refname,
800
if (starts_with(refname, "refs/remotes/") &&
801
!strcmp(branch, cb->base_ref))
802
string_list_append_nodup(cb->similar_refs,
803
- shorten_unambiguous_ref(refname, 1));
803
+ refs_shorten_unambiguous_ref(get_main_ref_store(the_repository), refname, 1));
804
return 0;
805
}
806
@@ -811,7 +811,8 @@ static struct string_list guess_refs(const char *ref)
811
812
ref_cb.base_ref = ref;
813
ref_cb.similar_refs = &similar_refs;
814
- for_each_ref(append_similar_ref, &ref_cb);
814
+ refs_for_each_ref(get_main_ref_store(the_repository),
815
+ append_similar_ref, &ref_cb);
816
return similar_refs;
817
}
818
http-backend.c
+8
-5
@@ -559,7 +559,8 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED)
559
560
} else {
561
select_getanyfile(hdr);
562
- for_each_namespaced_ref(NULL, show_text_ref, &buf);
562
+ refs_for_each_namespaced_ref(get_main_ref_store(the_repository),
563
+ NULL, show_text_ref, &buf);
564
send_strbuf(hdr, "text/plain", &buf);
565
}
566
strbuf_release(&buf);
@@ -571,9 +572,10 @@ static int show_head_ref(const char *refname, const struct object_id *oid,
572
struct strbuf *buf = cb_data;
573
574
if (flag & REF_ISSYMREF) {
574
- const char *target = resolve_ref_unsafe(refname,
575
- RESOLVE_REF_READING,
576
- NULL, NULL);
575
+ const char *target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
576
+ refname,
577
+ RESOLVE_REF_READING,
578
+ NULL, NULL);
579
580
if (target)
581
strbuf_addf(buf, "ref: %s\n", strip_namespace(target));
@@ -589,7 +591,8 @@ static void get_head(struct strbuf *hdr, char *arg UNUSED)
591
struct strbuf buf = STRBUF_INIT;
592
593
select_getanyfile(hdr);
592
- head_ref_namespaced(show_head_ref, &buf);
594
+ refs_head_ref_namespaced(get_main_ref_store(the_repository),
595
+ show_head_ref, &buf);
596
send_strbuf(hdr, "text/plain", &buf);
597
strbuf_release(&buf);
598
}
log-tree.c
+6
-3
@@ -232,8 +232,10 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
232
}
233
decoration_loaded = 1;
234
decoration_flags = flags;
235
- for_each_ref(add_ref_decoration, filter);
236
- head_ref(add_ref_decoration, filter);
235
+ refs_for_each_ref(get_main_ref_store(the_repository),
236
+ add_ref_decoration, filter);
237
+ refs_head_ref(get_main_ref_store(the_repository),
238
+ add_ref_decoration, filter);
239
for_each_commit_graft(add_graft_decoration, filter);
240
}
241
}
@@ -277,7 +279,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
279
return NULL;
280
281
/* Now resolve and find the matching current branch */
280
- branch_name = resolve_ref_unsafe("HEAD", 0, NULL, &rru_flags);
282
+ branch_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
283
+ "HEAD", 0, NULL, &rru_flags);
284
if (!branch_name || !(rru_flags & REF_ISSYMREF))
285
return NULL;
286
ls-refs.c
+6
-4
@@ -95,9 +95,11 @@ static int send_ref(const char *refname, const struct object_id *oid,
95
strbuf_addf(&data->buf, "unborn %s", refname_nons);
96
if (data->symrefs && flag & REF_ISSYMREF) {
97
struct object_id unused;
98
- const char *symref_target = resolve_ref_unsafe(refname, 0,
99
- &unused,
100
- &flag);
98
+ const char *symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
99
+ refname,
100
+ 0,
101
+ &unused,
102
+ &flag);
103
104
if (!symref_target)
105
die("'%s' is a symref but it is not?", refname);
@@ -126,7 +128,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data)
128
int oid_is_null;
129
130
strbuf_addf(&namespaced, "%sHEAD", get_git_namespace());
129
- if (!resolve_ref_unsafe(namespaced.buf, 0, &oid, &flag))
131
+ if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), namespaced.buf, 0, &oid, &flag))
132
return; /* bad ref */
133
oid_is_null = is_null_oid(&oid);
134
if (!oid_is_null ||
midx-write.c
+2
-1
@@ -755,7 +755,8 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
755
read_refs_snapshot(refs_snapshot, &revs);
756
} else {
757
setup_revisions(0, NULL, &revs, NULL);
758
- for_each_ref(add_ref_to_pending, &revs);
758
+ refs_for_each_ref(get_main_ref_store(the_repository),
759
+ add_ref_to_pending, &revs);
760
}
761
762
/*
negotiator/default.c
+2
-1
@@ -192,6 +192,7 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)
192
ns->rev_list.compare = compare_commits_by_commit_date;
193
194
if (marked)
195
- for_each_ref(clear_marks, NULL);
195
+ refs_for_each_ref(get_main_ref_store(the_repository),
196
+ clear_marks, NULL);
197
marked = 1;
198
}
negotiator/skipping.c
+2
-1
@@ -261,6 +261,7 @@ void skipping_negotiator_init(struct fetch_negotiator *negotiator)
261
data->rev_list.compare = compare;
262
263
if (marked)
264
- for_each_ref(clear_marks, NULL);
264
+ refs_for_each_ref(get_main_ref_store(the_repository),
265
+ clear_marks, NULL);
266
marked = 1;
267
}
notes-cache.c
+3
-3
@@ -17,7 +17,7 @@ static int notes_cache_match_validity(struct repository *r,
17
struct strbuf msg = STRBUF_INIT;
18
int ret;
19
20
- if (read_ref(ref, &oid) < 0)
20
+ if (refs_read_ref(get_main_ref_store(the_repository), ref, &oid) < 0)
21
return 0;
22
23
commit = lookup_commit_reference_gently(r, &oid, 1);
@@ -66,8 +66,8 @@ int notes_cache_write(struct notes_cache *c)
66
if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
67
&commit_oid, NULL, NULL) < 0)
68
return -1;
69
- if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
70
- NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
69
+ if (refs_update_ref(get_main_ref_store(the_repository), "update notes cache", c->tree.update_ref, &commit_oid,
70
+ NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
71
return -1;
72
73
return 0;
notes-merge.c
+1
-1
@@ -562,7 +562,7 @@ int notes_merge(struct notes_merge_options *o,
562
o->local_ref, o->remote_ref);
563
564
/* Dereference o->local_ref into local_sha1 */
565
- if (read_ref_full(o->local_ref, 0, &local_oid, NULL))
565
+ if (refs_read_ref_full(get_main_ref_store(the_repository), o->local_ref, 0, &local_oid, NULL))
566
die("Failed to resolve local notes ref '%s'", o->local_ref);
567
else if (!check_refname_format(o->local_ref, 0) &&
568
is_null_oid(&local_oid))
notes-utils.c
+4
-3
@@ -23,7 +23,7 @@ void create_notes_commit(struct repository *r,
23
if (!parents) {
24
/* Deduce parent commit from t->ref */
25
struct object_id parent_oid;
26
- if (!read_ref(t->ref, &parent_oid)) {
26
+ if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
27
struct commit *parent = lookup_commit(r, &parent_oid);
28
if (repo_parse_commit(r, parent))
29
die("Failed to find/parse commit %s", t->ref);
@@ -55,8 +55,9 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
55
56
create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
57
strbuf_insertstr(&buf, 0, "notes: ");
58
- update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
59
- UPDATE_REFS_DIE_ON_ERR);
58
+ refs_update_ref(get_main_ref_store(the_repository), buf.buf,
59
+ t->update_ref, &commit_oid, NULL, 0,
60
+ UPDATE_REFS_DIE_ON_ERR);
61
62
strbuf_release(&buf);
63
}
notes.c
+3
-2
@@ -945,7 +945,8 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
945
{
946
assert(list->strdup_strings);
947
if (has_glob_specials(glob)) {
948
- for_each_glob_ref(string_list_add_one_ref, glob, list);
948
+ refs_for_each_glob_ref(get_main_ref_store(the_repository),
949
+ string_list_add_one_ref, glob, list);
950
} else {
951
struct object_id oid;
952
if (repo_get_oid(the_repository, glob, &oid))
@@ -1029,7 +1030,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
1030
if (flags & NOTES_INIT_EMPTY ||
1031
repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
1032
return;
1032
- if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
1033
+ if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
1034
die("Cannot use notes ref %s", notes_ref);
1035
if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
1036
die("Failed to read notes tree referenced by %s (%s)",
reachable.c
+3
-2
@@ -363,10 +363,11 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
363
add_index_objects_to_pending(revs, 0);
364
365
/* Add all external refs */
366
- for_each_ref(add_one_ref, revs);
366
+ refs_for_each_ref(get_main_ref_store(the_repository), add_one_ref,
367
+ revs);
368
369
/* detached HEAD is not included in the list above */
369
- head_ref(add_one_ref, revs);
370
+ refs_head_ref(get_main_ref_store(the_repository), add_one_ref, revs);
371
other_head_refs(add_one_ref, revs);
372
373
/* rebase autostash and orig-head */
ref-filter.c
+25
-10
@@ -895,7 +895,9 @@ static int head_atom_parser(struct ref_format *format UNUSED,
895
{
896
if (arg)
897
return err_no_arg(err, "HEAD");
898
- atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL);
898
+ atom->u.head = refs_resolve_refdup(get_main_ref_store(the_repository),
899
+ "HEAD", RESOLVE_REF_READING, NULL,
900
+ NULL);
901
return 0;
902
}
903
@@ -2135,7 +2137,9 @@ static const char *rstrip_ref_components(const char *refname, int len)
2137
static const char *show_ref(struct refname_atom *atom, const char *refname)
2138
{
2139
if (atom->option == R_SHORT)
2138
- return shorten_unambiguous_ref(refname, warn_ambiguous_refs);
2140
+ return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2141
+ refname,
2142
+ warn_ambiguous_refs);
2143
else if (atom->option == R_LSTRIP)
2144
return lstrip_ref_components(refname, atom->lstrip);
2145
else if (atom->option == R_RSTRIP)
@@ -2338,8 +2342,10 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
2342
CALLOC_ARRAY(ref->value, used_atom_cnt);
2343
2344
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
2341
- ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
2342
- NULL, NULL);
2345
+ ref->symref = refs_resolve_refdup(get_main_ref_store(the_repository),
2346
+ ref->refname,
2347
+ RESOLVE_REF_READING,
2348
+ NULL, NULL);
2349
if (!ref->symref)
2350
ref->symref = xstrdup("");
2351
}
@@ -2640,7 +2646,8 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
2646
* prefixes like "refs/heads/" etc. are stripped off,
2647
* so we have to look at everything:
2648
*/
2643
- return for_each_fullref_in("", NULL, cb, cb_data);
2649
+ return refs_for_each_fullref_in(get_main_ref_store(the_repository),
2650
+ "", NULL, cb, cb_data);
2651
}
2652
2653
if (filter->ignore_case) {
@@ -2649,7 +2656,8 @@ static int for_each_fullref_in_pattern(struct ref_filter *filter,
2656
* so just return everything and let the caller
2657
* sort it out.
2658
*/
2652
- return for_each_fullref_in("", NULL, cb, cb_data);
2659
+ return refs_for_each_fullref_in(get_main_ref_store(the_repository),
2660
+ "", NULL, cb, cb_data);
2661
}
2662
2663
if (!filter->name_patterns[0]) {
@@ -3060,11 +3068,17 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref
3068
* of filter_ref_kind().
3069
*/
3070
if (filter->kind == FILTER_REFS_BRANCHES)
3063
- ret = for_each_fullref_in("refs/heads/", NULL, fn, cb_data);
3071
+ ret = refs_for_each_fullref_in(get_main_ref_store(the_repository),
3072
+ "refs/heads/", NULL,
3073
+ fn, cb_data);
3074
else if (filter->kind == FILTER_REFS_REMOTES)
3065
- ret = for_each_fullref_in("refs/remotes/", NULL, fn, cb_data);
3075
+ ret = refs_for_each_fullref_in(get_main_ref_store(the_repository),
3076
+ "refs/remotes/", NULL,
3077
+ fn, cb_data);
3078
else if (filter->kind == FILTER_REFS_TAGS)
3067
- ret = for_each_fullref_in("refs/tags/", NULL, fn, cb_data);
3079
+ ret = refs_for_each_fullref_in(get_main_ref_store(the_repository),
3080
+ "refs/tags/", NULL, fn,
3081
+ cb_data);
3082
else if (filter->kind & FILTER_REFS_REGULAR)
3083
ret = for_each_fullref_in_pattern(filter, fn, cb_data);
3084
@@ -3074,7 +3088,8 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref
3088
*/
3089
if (!ret && (filter->kind != FILTER_REFS_KIND_MASK) &&
3090
(filter->kind & FILTER_REFS_DETACHED_HEAD))
3077
- head_ref(fn, cb_data);
3091
+ refs_head_ref(get_main_ref_store(the_repository), fn,
3092
+ cb_data);
3093
}
3094
3095
clear_contains_cache(&filter->internal.contains_cache);
reflog-walk.c
+19
-8
@@ -67,24 +67,32 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)
67
struct complete_reflogs *reflogs =
68
xcalloc(1, sizeof(struct complete_reflogs));
69
reflogs->ref = xstrdup(ref);
70
- for_each_reflog_ent(ref, read_one_reflog, reflogs);
70
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository), ref,
71
+ read_one_reflog, reflogs);
72
if (reflogs->nr == 0) {
73
const char *name;
74
void *name_to_free;
74
- name = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,
75
- NULL, NULL);
75
+ name = name_to_free = refs_resolve_refdup(get_main_ref_store(the_repository),
76
+ ref,
77
+ RESOLVE_REF_READING,
78
+ NULL, NULL);
79
if (name) {
77
- for_each_reflog_ent(name, read_one_reflog, reflogs);
80
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
81
+ name, read_one_reflog,
82
+ reflogs);
83
free(name_to_free);
84
}
85
}
86
if (reflogs->nr == 0) {
87
char *refname = xstrfmt("refs/%s", ref);
83
- for_each_reflog_ent(refname, read_one_reflog, reflogs);
88
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
89
+ refname, read_one_reflog, reflogs);
90
if (reflogs->nr == 0) {
91
free(refname);
92
refname = xstrfmt("refs/heads/%s", ref);
87
- for_each_reflog_ent(refname, read_one_reflog, reflogs);
93
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
94
+ refname, read_one_reflog,
95
+ reflogs);
96
}
97
free(refname);
98
}
@@ -174,7 +182,8 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
182
else {
183
if (*branch == '\0') {
184
free(branch);
177
- branch = resolve_refdup("HEAD", 0, NULL, NULL);
185
+ branch = refs_resolve_refdup(get_main_ref_store(the_repository),
186
+ "HEAD", 0, NULL, NULL);
187
if (!branch)
188
die("no current branch");
189
@@ -236,7 +245,9 @@ void get_reflog_selector(struct strbuf *sb,
245
if (shorten) {
246
if (!commit_reflog->reflogs->short_ref)
247
commit_reflog->reflogs->short_ref
239
- = shorten_unambiguous_ref(commit_reflog->reflogs->ref, 0);
248
+ = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
249
+ commit_reflog->reflogs->ref,
250
+ 0);
251
printed_ref = commit_reflog->reflogs->short_ref;
252
} else {
253
printed_ref = commit_reflog->reflogs->ref;
reflog.c
+12
-8
@@ -343,7 +343,8 @@ void reflog_expiry_prepare(const char *refname,
343
case UE_ALWAYS:
344
return;
345
case UE_HEAD:
346
- for_each_ref(push_tip_to_list, &cb->tips);
346
+ refs_for_each_ref(get_main_ref_store(the_repository),
347
+ push_tip_to_list, &cb->tips);
348
for (elem = cb->tips; elem; elem = elem->next)
349
commit_list_insert(elem->item, &cb->mark_list);
350
break;
@@ -416,19 +417,22 @@ int reflog_delete(const char *rev, enum expire_reflog_flags flags, int verbose)
417
recno = strtoul(spec + 2, &ep, 10);
418
if (*ep == '}') {
419
cmd.recno = -recno;
419
- for_each_reflog_ent(ref, count_reflog_ent, &cmd);
420
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
421
+ ref, count_reflog_ent, &cmd);
422
} else {
423
cmd.expire_total = approxidate(spec + 2);
422
- for_each_reflog_ent(ref, count_reflog_ent, &cmd);
424
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
425
+ ref, count_reflog_ent, &cmd);
426
cmd.expire_total = 0;
427
}
428
429
cb.cmd = cmd;
427
- status |= reflog_expire(ref, flags,
428
- reflog_expiry_prepare,
429
- should_prune_fn,
430
- reflog_expiry_cleanup,
431
- &cb);
430
+ status |= refs_reflog_expire(get_main_ref_store(the_repository), ref,
431
+ flags,
432
+ reflog_expiry_prepare,
433
+ should_prune_fn,
434
+ reflog_expiry_cleanup,
435
+ &cb);
436
437
cleanup:
438
free(ref);
refs.c
+6
-3
@@ -487,7 +487,8 @@ static int warn_if_dangling_symref(const char *refname,
487
if (!(flags & REF_ISSYMREF))
488
return 0;
489
490
- resolves_to = resolve_ref_unsafe(refname, 0, NULL, NULL);
490
+ resolves_to = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
491
+ refname, 0, NULL, NULL);
492
if (!resolves_to
493
|| (d->refname
494
? strcmp(resolves_to, d->refname)
@@ -508,7 +509,8 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
509
data.refname = refname;
510
data.refnames = NULL;
511
data.msg_fmt = msg_fmt;
511
- for_each_rawref(warn_if_dangling_symref, &data);
512
+ refs_for_each_rawref(get_main_ref_store(the_repository),
513
+ warn_if_dangling_symref, &data);
514
}
515
516
void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames)
@@ -519,7 +521,8 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_li
521
data.refname = NULL;
522
data.refnames = refnames;
523
data.msg_fmt = msg_fmt;
522
- for_each_rawref(warn_if_dangling_symref, &data);
524
+ refs_for_each_rawref(get_main_ref_store(the_repository),
525
+ warn_if_dangling_symref, &data);
526
}
527
528
int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
remote.c
+24
-14
@@ -1198,8 +1198,10 @@ static char *guess_ref(const char *name, struct ref *peer)
1198
{
1199
struct strbuf buf = STRBUF_INIT;
1200
1201
- const char *r = resolve_ref_unsafe(peer->name, RESOLVE_REF_READING,
1202
- NULL, NULL);
1201
+ const char *r = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1202
+ peer->name,
1203
+ RESOLVE_REF_READING,
1204
+ NULL, NULL);
1205
if (!r)
1206
return NULL;
1207
@@ -1316,9 +1318,10 @@ static int match_explicit(struct ref *src, struct ref *dst,
1318
if (!dst_value) {
1319
int flag;
1320
1319
- dst_value = resolve_ref_unsafe(matched_src->name,
1320
- RESOLVE_REF_READING,
1321
- NULL, &flag);
1321
+ dst_value = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1322
+ matched_src->name,
1323
+ RESOLVE_REF_READING,
1324
+ NULL, &flag);
1325
if (!dst_value ||
1326
((flag & REF_ISSYMREF) &&
1327
!starts_with(dst_value, "refs/heads/")))
@@ -1882,7 +1885,7 @@ const char *branch_get_upstream(struct branch *branch, struct strbuf *err)
1885
* or because it is not a real branch, and get_branch
1886
* auto-vivified it?
1887
*/
1885
- if (!ref_exists(branch->refname))
1888
+ if (!refs_ref_exists(get_main_ref_store(the_repository), branch->refname))
1889
return error_buf(err, _("no such branch: '%s'"),
1890
branch->name);
1891
return error_buf(err,
@@ -2168,13 +2171,13 @@ static int stat_branch_pair(const char *branch_name, const char *base,
2171
struct strvec argv = STRVEC_INIT;
2172
2173
/* Cannot stat if what we used to build on no longer exists */
2171
- if (read_ref(base, &oid))
2174
+ if (refs_read_ref(get_main_ref_store(the_repository), base, &oid))
2175
return -1;
2176
theirs = lookup_commit_reference(the_repository, &oid);
2177
if (!theirs)
2178
return -1;
2179
2177
- if (read_ref(branch_name, &oid))
2180
+ if (refs_read_ref(get_main_ref_store(the_repository), branch_name, &oid))
2181
return -1;
2182
ours = lookup_commit_reference(the_repository, &oid);
2183
if (!ours)
@@ -2278,7 +2281,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb,
2281
upstream_is_gone = 1;
2282
}
2283
2281
- base = shorten_unambiguous_ref(full_base, 0);
2284
+ base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2285
+ full_base, 0);
2286
if (upstream_is_gone) {
2287
strbuf_addf(sb,
2288
_("Your branch is based on '%s', but the upstream is gone.\n"),
@@ -2358,7 +2362,8 @@ struct ref *get_local_heads(void)
2362
{
2363
struct ref *local_refs = NULL, **local_tail = &local_refs;
2364
2361
- for_each_ref(one_local_ref, &local_tail);
2365
+ refs_for_each_ref(get_main_ref_store(the_repository), one_local_ref,
2366
+ &local_tail);
2367
return local_refs;
2368
}
2369
@@ -2468,7 +2473,8 @@ struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map)
2473
for (ref = fetch_map; ref; ref = ref->next)
2474
string_list_append(&ref_names, ref->name);
2475
string_list_sort(&ref_names);
2471
- for_each_ref(get_stale_heads_cb, &info);
2476
+ refs_for_each_ref(get_main_ref_store(the_repository),
2477
+ get_stale_heads_cb, &info);
2478
string_list_clear(&ref_names, 0);
2479
return stale_refs;
2480
}
@@ -2553,7 +2559,7 @@ static int remote_tracking(struct remote *remote, const char *refname,
2559
dst = apply_refspecs(&remote->fetch, refname);
2560
if (!dst)
2561
return -1; /* no tracking ref for refname at remote */
2556
- if (read_ref(dst, oid))
2562
+ if (refs_read_ref(get_main_ref_store(the_repository), dst, oid))
2563
return -1; /* we know what the tracking ref is but we cannot read it */
2564
2565
*dst_refname = dst;
@@ -2659,12 +2665,16 @@ static int is_reachable_in_reflog(const char *local, const struct ref *remote)
2665
* Get the timestamp from the latest entry
2666
* of the remote-tracking ref's reflog.
2667
*/
2662
- for_each_reflog_ent_reverse(remote->tracking_ref, peek_reflog, &date);
2668
+ refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),
2669
+ remote->tracking_ref, peek_reflog,
2670
+ &date);
2671
2672
cb.remote_commit = commit;
2673
cb.local_commits = &arr;
2674
cb.remote_reflog_timestamp = date;
2667
- ret = for_each_reflog_ent_reverse(local, check_and_collect_until, &cb);
2675
+ ret = refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),
2676
+ local, check_and_collect_until,
2677
+ &cb);
2678
2679
/* We found an entry in the reflog. */
2680
if (ret > 0)
reset.c
+17
-12
@@ -47,11 +47,13 @@ static int update_refs(const struct reset_head_opts *opts,
47
strbuf_addstr(&msg, "updating ORIG_HEAD");
48
reflog_orig_head = msg.buf;
49
}
50
- update_ref(reflog_orig_head, "ORIG_HEAD",
51
- orig_head ? orig_head : head,
52
- old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
50
+ refs_update_ref(get_main_ref_store(the_repository),
51
+ reflog_orig_head, "ORIG_HEAD",
52
+ orig_head ? orig_head : head,
53
+ old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
54
} else if (old_orig)
54
- delete_ref(NULL, "ORIG_HEAD", old_orig, 0);
55
+ refs_delete_ref(get_main_ref_store(the_repository),
56
+ NULL, "ORIG_HEAD", old_orig, 0);
57
}
58
59
if (!reflog_head) {
@@ -60,16 +62,19 @@ static int update_refs(const struct reset_head_opts *opts,
62
reflog_head = msg.buf;
63
}
64
if (!switch_to_branch)
63
- ret = update_ref(reflog_head, "HEAD", oid, head,
64
- detach_head ? REF_NO_DEREF : 0,
65
- UPDATE_REFS_MSG_ON_ERR);
65
+ ret = refs_update_ref(get_main_ref_store(the_repository),
66
+ reflog_head, "HEAD", oid, head,
67
+ detach_head ? REF_NO_DEREF : 0,
68
+ UPDATE_REFS_MSG_ON_ERR);
69
else {
67
- ret = update_ref(reflog_branch ? reflog_branch : reflog_head,
68
- switch_to_branch, oid, NULL, 0,
69
- UPDATE_REFS_MSG_ON_ERR);
70
+ ret = refs_update_ref(get_main_ref_store(the_repository),
71
+ reflog_branch ? reflog_branch : reflog_head,
72
+ switch_to_branch, oid, NULL, 0,
73
+ UPDATE_REFS_MSG_ON_ERR);
74
if (!ret)
71
- ret = create_symref("HEAD", switch_to_branch,
72
- reflog_head);
75
+ ret = refs_create_symref(get_main_ref_store(the_repository),
76
+ "HEAD", switch_to_branch,
77
+ reflog_head);
78
}
79
if (!ret && run_hook)
80
run_hooks_l("post-checkout",
revision.c
+18
-9
@@ -1738,7 +1738,8 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
1738
cb.all_revs = revs;
1739
cb.all_flags = flags;
1740
cb.wt = NULL;
1741
- for_each_reflog(handle_one_reflog, &cb);
1741
+ refs_for_each_reflog(get_main_ref_store(the_repository),
1742
+ handle_one_reflog, &cb);
1743
1744
if (!revs->single_worktree)
1745
add_other_reflogs_to_pending(&cb);
@@ -1979,9 +1980,9 @@ static const char *lookup_other_head(struct object_id *oid)
1980
};
1981
1982
for (i = 0; i < ARRAY_SIZE(other_head); i++)
1982
- if (!read_ref_full(other_head[i],
1983
- RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1984
- oid, NULL)) {
1983
+ if (!refs_read_ref_full(get_main_ref_store(the_repository), other_head[i],
1984
+ RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1985
+ oid, NULL)) {
1986
if (is_null_oid(oid))
1987
die(_("%s exists but is a symbolic ref"), other_head[i]);
1988
return other_head[i];
@@ -2789,7 +2790,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2790
} else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
2791
struct all_refs_cb cb;
2792
init_all_refs_cb(&cb, revs, *flags);
2792
- for_each_glob_ref(handle_one_ref, optarg, &cb);
2793
+ refs_for_each_glob_ref(get_main_ref_store(the_repository),
2794
+ handle_one_ref, optarg, &cb);
2795
clear_ref_exclusions(&revs->ref_excludes);
2796
return argcount;
2797
} else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
@@ -2804,7 +2806,9 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2806
return error(_("options '%s' and '%s' cannot be used together"),
2807
"--exclude-hidden", "--branches");
2808
init_all_refs_cb(&cb, revs, *flags);
2807
- for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
2809
+ refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2810
+ handle_one_ref, optarg,
2811
+ "refs/heads/", &cb);
2812
clear_ref_exclusions(&revs->ref_excludes);
2813
} else if (skip_prefix(arg, "--tags=", &optarg)) {
2814
struct all_refs_cb cb;
@@ -2812,7 +2816,9 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2816
return error(_("options '%s' and '%s' cannot be used together"),
2817
"--exclude-hidden", "--tags");
2818
init_all_refs_cb(&cb, revs, *flags);
2815
- for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
2819
+ refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2820
+ handle_one_ref, optarg,
2821
+ "refs/tags/", &cb);
2822
clear_ref_exclusions(&revs->ref_excludes);
2823
} else if (skip_prefix(arg, "--remotes=", &optarg)) {
2824
struct all_refs_cb cb;
@@ -2820,7 +2826,9 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
2826
return error(_("options '%s' and '%s' cannot be used together"),
2827
"--exclude-hidden", "--remotes");
2828
init_all_refs_cb(&cb, revs, *flags);
2823
- for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
2829
+ refs_for_each_glob_ref_in(get_main_ref_store(the_repository),
2830
+ handle_one_ref, optarg,
2831
+ "refs/remotes/", &cb);
2832
clear_ref_exclusions(&revs->ref_excludes);
2833
} else if (!strcmp(arg, "--reflog")) {
2834
add_reflogs_to_pending(revs, *flags);
@@ -2911,7 +2919,8 @@ static void NORETURN diagnose_missing_default(const char *def)
2919
int flags;
2920
const char *refname;
2921
2914
- refname = resolve_ref_unsafe(def, 0, NULL, &flags);
2922
+ refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
2923
+ def, 0, NULL, &flags);
2924
if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN))
2925
die(_("your current branch appears to be broken"));
2926
sequencer.c
+33
-28
@@ -266,7 +266,7 @@ static struct update_ref_record *init_update_ref_record(const char *ref)
266
oidcpy(&rec->after, null_oid());
267
268
/* This may fail, but that's fine, we will keep the null OID. */
269
- read_ref(ref, &rec->before);
269
+ refs_read_ref(get_main_ref_store(the_repository), ref, &rec->before);
270
271
return rec;
272
}
@@ -440,7 +440,7 @@ int sequencer_remove_state(struct replay_opts *opts)
440
char *eol = strchr(p, '\n');
441
if (eol)
442
*eol = '\0';
443
- if (delete_ref("(rebase) cleanup", p, NULL, 0) < 0) {
443
+ if (refs_delete_ref(get_main_ref_store(the_repository), "(rebase) cleanup", p, NULL, 0) < 0) {
444
warning(_("could not delete '%s'"), p);
445
ret = -1;
446
}
@@ -661,7 +661,8 @@ static int fast_forward_to(struct repository *r,
661
662
strbuf_addf(&sb, "%s: fast-forward", action_name(opts));
663
664
- transaction = ref_transaction_begin(&err);
664
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
665
+ &err);
666
if (!transaction ||
667
ref_transaction_update(transaction, "HEAD",
668
to, unborn && !is_rebase_i(opts) ?
@@ -841,11 +842,12 @@ static int is_index_unchanged(struct repository *r)
842
struct index_state *istate = r->index;
843
const char *head_name;
844
844
- if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) {
845
+ if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL)) {
846
/* Check to see if this is an unborn branch */
846
- head_name = resolve_ref_unsafe("HEAD",
847
- RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
848
- &head_oid, NULL);
847
+ head_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
848
+ "HEAD",
849
+ RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
850
+ &head_oid, NULL);
851
if (!head_name ||
852
!starts_with(head_name, "refs/heads/") ||
853
!is_null_oid(&head_oid))
@@ -1294,7 +1296,8 @@ int update_head_with_reflog(const struct commit *old_head,
1296
strbuf_addch(&sb, '\n');
1297
}
1298
1297
- transaction = ref_transaction_begin(err);
1299
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1300
+ err);
1301
if (!transaction ||
1302
ref_transaction_update(transaction, "HEAD", new_head,
1303
old_head ? &old_head->object.oid : null_oid(),
@@ -1720,8 +1723,8 @@ out:
1723
1724
static int write_rebase_head(struct object_id *oid)
1725
{
1723
- if (update_ref("rebase", "REBASE_HEAD", oid,
1724
- NULL, REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
1726
+ if (refs_update_ref(get_main_ref_store(the_repository), "rebase", "REBASE_HEAD", oid,
1727
+ NULL, REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
1728
return error(_("could not update %s"), "REBASE_HEAD");
1729
1730
return 0;
@@ -2455,12 +2458,12 @@ static int do_pick_commit(struct repository *r,
2458
if ((command == TODO_PICK || command == TODO_REWORD ||
2459
command == TODO_EDIT) && !opts->no_commit &&
2460
(res == 0 || res == 1) &&
2458
- update_ref(NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL,
2459
- REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
2461
+ refs_update_ref(get_main_ref_store(the_repository), NULL, "CHERRY_PICK_HEAD", &commit->object.oid, NULL,
2462
+ REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
2463
res = -1;
2464
if (command == TODO_REVERT && ((opts->no_commit && res == 0) || res == 1) &&
2462
- update_ref(NULL, "REVERT_HEAD", &commit->object.oid, NULL,
2463
- REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
2465
+ refs_update_ref(get_main_ref_store(the_repository), NULL, "REVERT_HEAD", &commit->object.oid, NULL,
2466
+ REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR))
2467
res = -1;
2468
2469
if (res) {
@@ -3364,7 +3367,7 @@ static int rollback_single_pick(struct repository *r)
3367
if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
3368
!refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
3369
return error(_("no cherry-pick or revert in progress"));
3367
- if (read_ref_full("HEAD", 0, &head_oid, NULL))
3370
+ if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", 0, &head_oid, NULL))
3371
return error(_("cannot resolve HEAD"));
3372
if (is_null_oid(&head_oid))
3373
return error(_("cannot abort from a branch yet to be born"));
@@ -3375,7 +3378,7 @@ static int skip_single_pick(void)
3378
{
3379
struct object_id head;
3380
3378
- if (read_ref_full("HEAD", 0, &head, NULL))
3381
+ if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", 0, &head, NULL))
3382
return error(_("cannot resolve HEAD"));
3383
return reset_merge(&head);
3384
}
@@ -3891,7 +3894,7 @@ static struct commit *lookup_label(struct repository *r, const char *label,
3894
3895
strbuf_reset(buf);
3896
strbuf_addf(buf, "refs/rewritten/%.*s", len, label);
3894
- if (!read_ref(buf->buf, &oid)) {
3897
+ if (!refs_read_ref(get_main_ref_store(the_repository), buf->buf, &oid)) {
3898
commit = lookup_commit_object(r, &oid);
3899
} else {
3900
/* fall back to non-rewritten ref or commit */
@@ -3987,9 +3990,10 @@ static int do_reset(struct repository *r,
3990
ret = error(_("could not write index"));
3991
3992
if (!ret)
3990
- ret = update_ref(reflog_message(opts, "reset", "'%.*s'",
3991
- len, name), "HEAD", &oid,
3992
- NULL, 0, UPDATE_REFS_MSG_ON_ERR);
3993
+ ret = refs_update_ref(get_main_ref_store(the_repository), reflog_message(opts, "reset", "'%.*s'",
3994
+ len, name),
3995
+ "HEAD", &oid,
3996
+ NULL, 0, UPDATE_REFS_MSG_ON_ERR);
3997
cleanup:
3998
free((void *)desc.buffer);
3999
if (ret < 0)
@@ -4471,7 +4475,7 @@ static int do_update_ref(struct repository *r, const char *refname)
4475
for_each_string_list_item(item, &list) {
4476
if (!strcmp(item->string, refname)) {
4477
struct update_ref_record *rec = item->util;
4474
- if (read_ref("HEAD", &rec->after))
4478
+ if (refs_read_ref(get_main_ref_store(the_repository), "HEAD", &rec->after))
4479
return -1;
4480
break;
4481
}
@@ -5031,15 +5035,15 @@ cleanup_head_ref:
5035
}
5036
msg = reflog_message(opts, "finish", "%s onto %s",
5037
head_ref.buf, buf.buf);
5034
- if (update_ref(msg, head_ref.buf, &head, &orig,
5035
- REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
5038
+ if (refs_update_ref(get_main_ref_store(the_repository), msg, head_ref.buf, &head, &orig,
5039
+ REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR)) {
5040
res = error(_("could not update %s"),
5041
head_ref.buf);
5042
goto cleanup_head_ref;
5043
}
5044
msg = reflog_message(opts, "finish", "returning to %s",
5045
head_ref.buf);
5042
- if (create_symref("HEAD", head_ref.buf, msg)) {
5046
+ if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", head_ref.buf, msg)) {
5047
res = error(_("could not update HEAD to %s"),
5048
head_ref.buf);
5049
goto cleanup_head_ref;
@@ -6209,10 +6213,11 @@ static int add_decorations_to_list(const struct commit *commit,
6213
struct todo_add_branch_context *ctx)
6214
{
6215
const struct name_decoration *decoration = get_name_decoration(&commit->object);
6212
- const char *head_ref = resolve_ref_unsafe("HEAD",
6213
- RESOLVE_REF_READING,
6214
- NULL,
6215
- NULL);
6216
+ const char *head_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
6217
+ "HEAD",
6218
+ RESOLVE_REF_READING,
6219
+ NULL,
6220
+ NULL);
6221
6222
while (decoration) {
6223
struct todo_item *item;
server-info.c
+2
-1
@@ -175,7 +175,8 @@ static int add_info_ref(const char *path, const struct object_id *oid,
175
176
static int generate_info_refs(struct update_info_ctx *uic)
177
{
178
- return for_each_ref(add_info_ref, uic);
178
+ return refs_for_each_ref(get_main_ref_store(the_repository),
179
+ add_info_ref, uic);
180
}
181
182
static int update_info_refs(int force)
setup.c
+1
-1
@@ -2001,7 +2001,7 @@ void create_reference_database(unsigned int ref_storage_format,
2001
die(_("invalid initial branch name: '%s'"),
2002
initial_branch);
2003
2004
- if (create_symref("HEAD", ref, NULL) < 0)
2004
+ if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", ref, NULL) < 0)
2005
exit(1);
2006
free(ref);
2007
}
shallow.c
+10
-6
@@ -678,8 +678,10 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
678
* connect to old refs. If not (e.g. force ref updates) it'll
679
* have to go down to the current shallow commits.
680
*/
681
- head_ref(mark_uninteresting, NULL);
682
- for_each_ref(mark_uninteresting, NULL);
681
+ refs_head_ref(get_main_ref_store(the_repository), mark_uninteresting,
682
+ NULL);
683
+ refs_for_each_ref(get_main_ref_store(the_repository),
684
+ mark_uninteresting, NULL);
685
686
/* Mark potential bottoms so we won't go out of bound */
687
for (i = 0; i < nr_shallow; i++) {
@@ -782,8 +784,8 @@ static void post_assign_shallow(struct shallow_info *info,
784
info->nr_theirs = dst;
785
786
memset(&ca, 0, sizeof(ca));
785
- head_ref(add_ref, &ca);
786
- for_each_ref(add_ref, &ca);
787
+ refs_head_ref(get_main_ref_store(the_repository), add_ref, &ca);
788
+ refs_for_each_ref(get_main_ref_store(the_repository), add_ref, &ca);
789
790
/* Remove unreachable shallow commits from "ours" */
791
for (i = dst = 0; i < info->nr_ours; i++) {
@@ -822,8 +824,10 @@ int delayed_reachability_test(struct shallow_info *si, int c)
824
struct commit_array ca;
825
826
memset(&ca, 0, sizeof(ca));
825
- head_ref(add_ref, &ca);
826
- for_each_ref(add_ref, &ca);
827
+ refs_head_ref(get_main_ref_store(the_repository),
828
+ add_ref, &ca);
829
+ refs_for_each_ref(get_main_ref_store(the_repository),
830
+ add_ref, &ca);
831
si->commits = ca.commits;
832
si->nr_commits = ca.nr;
833
}
submodule.c
+4
-2
@@ -1233,7 +1233,8 @@ int push_unpushed_submodules(struct repository *r,
1233
char *head;
1234
struct object_id head_oid;
1235
1236
- head = resolve_refdup("HEAD", 0, &head_oid, NULL);
1236
+ head = refs_resolve_refdup(get_main_ref_store(the_repository),
1237
+ "HEAD", 0, &head_oid, NULL);
1238
if (!head)
1239
die(_("Failed to resolve HEAD as a valid ref."));
1240
@@ -1271,7 +1272,8 @@ static int append_oid_to_array(const char *ref UNUSED,
1272
void check_for_new_submodule_commits(struct object_id *oid)
1273
{
1274
if (!initialized_fetch_ref_tips) {
1274
- for_each_ref(append_oid_to_array, &ref_tips_before_fetch);
1275
+ refs_for_each_ref(get_main_ref_store(the_repository),
1276
+ append_oid_to_array, &ref_tips_before_fetch);
1277
initialized_fetch_ref_tips = 1;
1278
}
1279
transport-helper.c
+17
-12
@@ -551,7 +551,7 @@ static int fetch_with_import(struct transport *transport,
551
else
552
private = xstrdup(name);
553
if (private) {
554
- if (read_ref(private, &posn->old_oid) < 0)
554
+ if (refs_read_ref(get_main_ref_store(the_repository), private, &posn->old_oid) < 0)
555
die(_("could not read ref %s"), private);
556
free(private);
557
}
@@ -923,8 +923,10 @@ static int push_update_refs_status(struct helper_data *data,
923
private = apply_refspecs(&data->rs, ref->name);
924
if (!private)
925
continue;
926
- update_ref("update by helper", private, &(ref->new_oid),
927
- NULL, 0, 0);
926
+ refs_update_ref(get_main_ref_store(the_repository),
927
+ "update by helper", private,
928
+ &(ref->new_oid),
929
+ NULL, 0, 0);
930
free(private);
931
} else {
932
for (report = ref->report; report; report = report->next) {
@@ -934,11 +936,12 @@ static int push_update_refs_status(struct helper_data *data,
936
: ref->name);
937
if (!private)
938
continue;
937
- update_ref("update by helper", private,
938
- report->new_oid
939
- ? report->new_oid
940
- : &(ref->new_oid),
941
- NULL, 0, 0);
939
+ refs_update_ref(get_main_ref_store(the_repository),
940
+ "update by helper", private,
941
+ report->new_oid
942
+ ? report->new_oid
943
+ : &(ref->new_oid),
944
+ NULL, 0, 0);
945
free(private);
946
}
947
}
@@ -1105,9 +1108,11 @@ static int push_refs_with_export(struct transport *transport,
1108
int flag;
1109
1110
/* Follow symbolic refs (mainly for HEAD). */
1108
- name = resolve_ref_unsafe(ref->peer_ref->name,
1109
- RESOLVE_REF_READING,
1110
- &oid, &flag);
1111
+ name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1112
+ ref->peer_ref->name,
1113
+ RESOLVE_REF_READING,
1114
+ &oid,
1115
+ &flag);
1116
if (!name || !(flag & REF_ISSYMREF))
1117
name = ref->peer_ref->name;
1118
@@ -1252,7 +1257,7 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
1257
if (eon) {
1258
if (has_attribute(eon + 1, "unchanged")) {
1259
(*tail)->status |= REF_STATUS_UPTODATE;
1255
- if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
1260
+ if (refs_read_ref(get_main_ref_store(the_repository), (*tail)->name, &(*tail)->old_oid) < 0)
1261
die(_("could not read ref %s"),
1262
(*tail)->name);
1263
}
transport.c
+10
-6
@@ -100,8 +100,9 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
100
/* Follow symbolic refs (mainly for HEAD). */
101
localname = ref->peer_ref->name;
102
remotename = ref->name;
103
- tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
104
- NULL, &flag);
103
+ tmp = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
104
+ localname, RESOLVE_REF_READING,
105
+ NULL, &flag);
106
if (tmp && flag & REF_ISSYMREF &&
107
starts_with(tmp, "refs/heads/"))
108
localname = tmp;
@@ -543,10 +544,12 @@ static void update_one_tracking_ref(struct remote *remote, char *refname,
544
if (verbose)
545
fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
546
if (deletion)
546
- delete_ref(NULL, rs.dst, NULL, 0);
547
+ refs_delete_ref(get_main_ref_store(the_repository),
548
+ NULL, rs.dst, NULL, 0);
549
else
548
- update_ref("update by push", rs.dst, new_oid,
549
- NULL, 0, 0);
550
+ refs_update_ref(get_main_ref_store(the_repository),
551
+ "update by push", rs.dst, new_oid,
552
+ NULL, 0, 0);
553
free(rs.dst);
554
}
555
}
@@ -814,7 +817,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
817
if (transport_color_config() < 0)
818
warning(_("could not parse transport.color.* config"));
819
817
- head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL);
820
+ head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD",
821
+ RESOLVE_REF_READING, NULL, NULL);
822
823
if (verbose) {
824
for (ref = refs; ref; ref = ref->next)
upload-pack.c
+13
-7
@@ -618,7 +618,8 @@ static void for_each_namespaced_ref_1(each_ref_fn fn,
618
if (allow_hidden_refs(data->allow_uor))
619
excludes = hidden_refs_to_excludes(&data->hidden_refs);
620
621
- for_each_namespaced_ref(excludes, fn, data);
621
+ refs_for_each_namespaced_ref(get_main_ref_store(the_repository),
622
+ excludes, fn, data);
623
}
624
625
@@ -873,7 +874,8 @@ static void deepen(struct upload_pack_data *data, int depth)
874
* Checking for reachable shallows requires that our refs be
875
* marked with OUR_REF.
876
*/
876
- head_ref_namespaced(check_ref, data);
877
+ refs_head_ref_namespaced(get_main_ref_store(the_repository),
878
+ check_ref, data);
879
for_each_namespaced_ref_1(check_ref, data);
880
881
get_reachable_list(data, &reachable_shallows);
@@ -1288,7 +1290,8 @@ static int find_symref(const char *refname,
1290
1291
if ((flag & REF_ISSYMREF) == 0)
1292
return 0;
1291
- symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
1293
+ symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
1294
+ refname, 0, NULL, &flag);
1295
if (!symref_target || (flag & REF_ISSYMREF) == 0)
1296
die("'%s' is a symref but it is not?", refname);
1297
item = string_list_append(cb_data, strip_namespace(refname));
@@ -1413,13 +1416,15 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
1416
if (data.timeout)
1417
data.daemon_mode = 1;
1418
1416
- head_ref_namespaced(find_symref, &data.symref);
1419
+ refs_head_ref_namespaced(get_main_ref_store(the_repository),
1420
+ find_symref, &data.symref);
1421
1422
if (advertise_refs || !data.stateless_rpc) {
1423
reset_timeout(data.timeout);
1424
if (advertise_refs)
1425
data.no_done = 1;
1422
- head_ref_namespaced(send_ref, &data);
1426
+ refs_head_ref_namespaced(get_main_ref_store(the_repository),
1427
+ send_ref, &data);
1428
for_each_namespaced_ref_1(send_ref, &data);
1429
if (!data.sent_capabilities) {
1430
const char *refname = "capabilities^{}";
@@ -1433,7 +1438,8 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
1438
advertise_shallow_grafts(1);
1439
packet_flush(1);
1440
} else {
1436
- head_ref_namespaced(check_ref, &data);
1441
+ refs_head_ref_namespaced(get_main_ref_store(the_repository),
1442
+ check_ref, &data);
1443
for_each_namespaced_ref_1(check_ref, &data);
1444
}
1445
@@ -1511,7 +1517,7 @@ static int parse_want_ref(struct packet_writer *writer, const char *line,
1517
1518
strbuf_addf(&refname, "%s%s", get_git_namespace(), refname_nons);
1519
if (ref_is_hidden(refname_nons, refname.buf, hidden_refs) ||
1514
- read_ref(refname.buf, &oid)) {
1520
+ refs_read_ref(get_main_ref_store(the_repository), refname.buf, &oid)) {
1521
packet_writer_error(writer, "unknown ref %s", refname_nons);
1522
die("unknown ref %s", refname_nons);
1523
}
walker.c
+4
-2
@@ -286,7 +286,8 @@ int walker_fetch(struct walker *walker, int targets, char **target,
286
ALLOC_ARRAY(oids, targets);
287
288
if (write_ref) {
289
- transaction = ref_transaction_begin(&err);
289
+ transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
290
+ &err);
291
if (!transaction) {
292
error("%s", err.buf);
293
goto done;
@@ -294,7 +295,8 @@ int walker_fetch(struct walker *walker, int targets, char **target,
295
}
296
297
if (!walker->get_recover) {
297
- for_each_ref(mark_complete, NULL);
298
+ refs_for_each_ref(get_main_ref_store(the_repository),
299
+ mark_complete, NULL);
300
commit_list_sort_by_date(&complete);
301
}
302
wt-status.c
+13
-9
@@ -145,7 +145,8 @@ void wt_status_prepare(struct repository *r, struct wt_status *s)
145
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
146
s->use_color = -1;
147
s->relative_paths = 1;
148
- s->branch = resolve_refdup("HEAD", 0, NULL, NULL);
148
+ s->branch = refs_resolve_refdup(get_main_ref_store(the_repository),
149
+ "HEAD", 0, NULL, NULL);
150
s->reference = "HEAD";
151
s->fp = stdout;
152
s->index_file = get_index_file();
@@ -976,7 +977,8 @@ static int stash_count_refs(struct object_id *ooid UNUSED,
977
static int count_stash_entries(void)
978
{
979
int n = 0;
979
- for_each_reflog_ent("refs/stash", stash_count_refs, &n);
980
+ refs_for_each_reflog_ent(get_main_ref_store(the_repository),
981
+ "refs/stash", stash_count_refs, &n);
982
return n;
983
}
984
@@ -1304,10 +1306,10 @@ static int split_commit_in_progress(struct wt_status *s)
1306
!s->branch || strcmp(s->branch, "HEAD"))
1307
return 0;
1308
1307
- if (read_ref_full("HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1308
- &head_oid, &head_flags) ||
1309
- read_ref_full("ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1310
- &orig_head_oid, &orig_head_flags))
1309
+ if (refs_read_ref_full(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1310
+ &head_oid, &head_flags) ||
1311
+ refs_read_ref_full(get_main_ref_store(the_repository), "ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1312
+ &orig_head_oid, &orig_head_flags))
1313
return 0;
1314
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
1315
return 0;
@@ -1679,7 +1681,7 @@ static void wt_status_get_detached_from(struct repository *r,
1681
char *ref = NULL;
1682
1683
strbuf_init(&cb.buf, 0);
1682
- if (for_each_reflog_ent_reverse("HEAD", grab_1st_switch, &cb) <= 0) {
1684
+ if (refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository), "HEAD", grab_1st_switch, &cb) <= 0) {
1685
strbuf_release(&cb.buf);
1686
return;
1687
}
@@ -2087,7 +2089,8 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
2089
upstream_is_gone = 1;
2090
}
2091
2090
- short_base = shorten_unambiguous_ref(base, 0);
2092
+ short_base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2093
+ base, 0);
2094
color_fprintf(s->fp, header_color, "...");
2095
color_fprintf(s->fp, branch_color_remote, "%s", short_base);
2096
free(short_base);
@@ -2220,7 +2223,8 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
2223
ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
2224
&base, 0, s->ahead_behind_flags);
2225
if (base) {
2223
- base = shorten_unambiguous_ref(base, 0);
2226
+ base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
2227
+ base, 0);
2228
fprintf(s->fp, "# branch.upstream %s%c", base, eol);
2229
free((char *)base);
2230