Skip to content

Commit 23a3f0c

Browse files
stefanbellergitster
authored andcommitted
refs: add repository argument to get_main_ref_store
Add a repository argument to allow the get_main_ref_store caller to be more specific about which repository to handle. This is a small mechanical change; it doesn't change the implementation to handle repositories other than the_repository yet. As with the previous commits, use a macro to catch callers passing a repository other than the_repository at compile time. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c3c36d7 commit 23a3f0c

File tree

5 files changed

+44
-38
lines changed

5 files changed

+44
-38
lines changed

builtin/pack-refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "builtin.h"
22
#include "parse-options.h"
33
#include "refs.h"
4+
#include "repository.h"
45

56
static char const * const pack_refs_usage[] = {
67
N_("git pack-refs [<options>]"),
@@ -17,5 +18,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
1718
};
1819
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
1920
usage_with_options(pack_refs_usage, opts);
20-
return refs_pack_refs(get_main_ref_store(), flags);
21+
return refs_pack_refs(get_main_ref_store(the_repository), flags);
2122
}

refs.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tag.h"
1414
#include "submodule.h"
1515
#include "worktree.h"
16+
#include "repository.h"
1617

1718
/*
1819
* List of all available backends
@@ -206,7 +207,7 @@ char *refs_resolve_refdup(struct ref_store *refs,
206207
char *resolve_refdup(const char *refname, int resolve_flags,
207208
struct object_id *oid, int *flags)
208209
{
209-
return refs_resolve_refdup(get_main_ref_store(),
210+
return refs_resolve_refdup(get_main_ref_store(the_repository),
210211
refname, resolve_flags,
211212
oid, flags);
212213
}
@@ -228,7 +229,7 @@ int refs_read_ref_full(struct ref_store *refs, const char *refname,
228229

229230
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
230231
{
231-
return refs_read_ref_full(get_main_ref_store(), refname,
232+
return refs_read_ref_full(get_main_ref_store(the_repository), refname,
232233
resolve_flags, oid, flags);
233234
}
234235

@@ -375,7 +376,7 @@ int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
375376

376377
int for_each_tag_ref(each_ref_fn fn, void *cb_data)
377378
{
378-
return refs_for_each_tag_ref(get_main_ref_store(), fn, cb_data);
379+
return refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, cb_data);
379380
}
380381

381382
int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
@@ -385,7 +386,7 @@ int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da
385386

386387
int for_each_branch_ref(each_ref_fn fn, void *cb_data)
387388
{
388-
return refs_for_each_branch_ref(get_main_ref_store(), fn, cb_data);
389+
return refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, cb_data);
389390
}
390391

391392
int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
@@ -395,7 +396,7 @@ int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_da
395396

396397
int for_each_remote_ref(each_ref_fn fn, void *cb_data)
397398
{
398-
return refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data);
399+
return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data);
399400
}
400401

401402
int head_ref_namespaced(each_ref_fn fn, void *cb_data)
@@ -730,7 +731,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
730731
struct strbuf err = STRBUF_INIT;
731732

732733
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
733-
assert(refs == get_main_ref_store());
734+
assert(refs == get_main_ref_store(the_repository));
734735
return delete_pseudoref(refname, old_oid);
735736
}
736737

@@ -752,7 +753,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
752753
int delete_ref(const char *msg, const char *refname,
753754
const struct object_id *old_oid, unsigned int flags)
754755
{
755-
return refs_delete_ref(get_main_ref_store(), msg, refname,
756+
return refs_delete_ref(get_main_ref_store(the_repository), msg, refname,
756757
old_oid, flags);
757758
}
758759

@@ -928,7 +929,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
928929

929930
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
930931
{
931-
return ref_store_transaction_begin(get_main_ref_store(), err);
932+
return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
932933
}
933934

934935
void ref_transaction_free(struct ref_transaction *transaction)
@@ -1060,7 +1061,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
10601061
int ret = 0;
10611062

10621063
if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
1063-
assert(refs == get_main_ref_store());
1064+
assert(refs == get_main_ref_store(the_repository));
10641065
ret = write_pseudoref(refname, new_oid, old_oid, &err);
10651066
} else {
10661067
t = ref_store_transaction_begin(refs, &err);
@@ -1099,7 +1100,7 @@ int update_ref(const char *msg, const char *refname,
10991100
const struct object_id *old_oid,
11001101
unsigned int flags, enum action_on_err onerr)
11011102
{
1102-
return refs_update_ref(get_main_ref_store(), msg, refname, new_oid,
1103+
return refs_update_ref(get_main_ref_store(the_repository), msg, refname, new_oid,
11031104
old_oid, flags, onerr);
11041105
}
11051106

@@ -1320,7 +1321,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
13201321

13211322
int head_ref(each_ref_fn fn, void *cb_data)
13221323
{
1323-
return refs_head_ref(get_main_ref_store(), fn, cb_data);
1324+
return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data);
13241325
}
13251326

13261327
struct ref_iterator *refs_ref_iterator_begin(
@@ -1379,7 +1380,7 @@ int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
13791380

13801381
int for_each_ref(each_ref_fn fn, void *cb_data)
13811382
{
1382-
return refs_for_each_ref(get_main_ref_store(), fn, cb_data);
1383+
return refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data);
13831384
}
13841385

13851386
int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
@@ -1390,7 +1391,7 @@ int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
13901391

13911392
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
13921393
{
1393-
return refs_for_each_ref_in(get_main_ref_store(), prefix, fn, cb_data);
1394+
return refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data);
13941395
}
13951396

13961397
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)
@@ -1399,7 +1400,7 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig
13991400

14001401
if (broken)
14011402
flag = DO_FOR_EACH_INCLUDE_BROKEN;
1402-
return do_for_each_ref(get_main_ref_store(),
1403+
return do_for_each_ref(get_main_ref_store(the_repository),
14031404
prefix, fn, 0, flag, cb_data);
14041405
}
14051406

@@ -1416,7 +1417,7 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
14161417

14171418
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
14181419
{
1419-
return do_for_each_ref(get_main_ref_store(),
1420+
return do_for_each_ref(get_main_ref_store(the_repository),
14201421
git_replace_ref_base, fn,
14211422
strlen(git_replace_ref_base),
14221423
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
@@ -1427,7 +1428,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
14271428
struct strbuf buf = STRBUF_INIT;
14281429
int ret;
14291430
strbuf_addf(&buf, "%srefs/", get_git_namespace());
1430-
ret = do_for_each_ref(get_main_ref_store(),
1431+
ret = do_for_each_ref(get_main_ref_store(the_repository),
14311432
buf.buf, fn, 0, 0, cb_data);
14321433
strbuf_release(&buf);
14331434
return ret;
@@ -1441,7 +1442,7 @@ int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
14411442

14421443
int for_each_rawref(each_ref_fn fn, void *cb_data)
14431444
{
1444-
return refs_for_each_rawref(get_main_ref_store(), fn, cb_data);
1445+
return refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data);
14451446
}
14461447

14471448
int refs_read_raw_ref(struct ref_store *ref_store,
@@ -1547,15 +1548,15 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
15471548
/* backend functions */
15481549
int refs_init_db(struct strbuf *err)
15491550
{
1550-
struct ref_store *refs = get_main_ref_store();
1551+
struct ref_store *refs = get_main_ref_store(the_repository);
15511552

15521553
return refs->be->init_db(refs, err);
15531554
}
15541555

15551556
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
15561557
struct object_id *oid, int *flags)
15571558
{
1558-
return refs_resolve_ref_unsafe(get_main_ref_store(), refname,
1559+
return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
15591560
resolve_flags, oid, flags);
15601561
}
15611562

@@ -1651,7 +1652,7 @@ static struct ref_store *ref_store_init(const char *gitdir,
16511652
return refs;
16521653
}
16531654

1654-
struct ref_store *get_main_ref_store(void)
1655+
struct ref_store *get_main_ref_store_the_repository(void)
16551656
{
16561657
if (main_ref_store)
16571658
return main_ref_store;
@@ -1726,7 +1727,7 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
17261727
const char *id;
17271728

17281729
if (wt->is_current)
1729-
return get_main_ref_store();
1730+
return get_main_ref_store(the_repository);
17301731

17311732
id = wt->id ? wt->id : "/";
17321733
refs = lookup_ref_store_map(&worktree_ref_stores, id);
@@ -1782,7 +1783,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
17821783

17831784
int peel_ref(const char *refname, struct object_id *oid)
17841785
{
1785-
return refs_peel_ref(get_main_ref_store(), refname, oid);
1786+
return refs_peel_ref(get_main_ref_store(the_repository), refname, oid);
17861787
}
17871788

17881789
int refs_create_symref(struct ref_store *refs,
@@ -1798,7 +1799,7 @@ int refs_create_symref(struct ref_store *refs,
17981799
int create_symref(const char *ref_target, const char *refs_heads_master,
17991800
const char *logmsg)
18001801
{
1801-
return refs_create_symref(get_main_ref_store(), ref_target,
1802+
return refs_create_symref(get_main_ref_store(the_repository), ref_target,
18021803
refs_heads_master, logmsg);
18031804
}
18041805

@@ -2006,7 +2007,7 @@ int refs_for_each_reflog(struct ref_store *refs, each_ref_fn fn, void *cb_data)
20062007

20072008
int for_each_reflog(each_ref_fn fn, void *cb_data)
20082009
{
2009-
return refs_for_each_reflog(get_main_ref_store(), fn, cb_data);
2010+
return refs_for_each_reflog(get_main_ref_store(the_repository), fn, cb_data);
20102011
}
20112012

20122013
int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
@@ -2021,7 +2022,7 @@ int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
20212022
int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,
20222023
void *cb_data)
20232024
{
2024-
return refs_for_each_reflog_ent_reverse(get_main_ref_store(),
2025+
return refs_for_each_reflog_ent_reverse(get_main_ref_store(the_repository),
20252026
refname, fn, cb_data);
20262027
}
20272028

@@ -2034,7 +2035,7 @@ int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,
20342035
int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
20352036
void *cb_data)
20362037
{
2037-
return refs_for_each_reflog_ent(get_main_ref_store(), refname,
2038+
return refs_for_each_reflog_ent(get_main_ref_store(the_repository), refname,
20382039
fn, cb_data);
20392040
}
20402041

@@ -2045,7 +2046,7 @@ int refs_reflog_exists(struct ref_store *refs, const char *refname)
20452046

20462047
int reflog_exists(const char *refname)
20472048
{
2048-
return refs_reflog_exists(get_main_ref_store(), refname);
2049+
return refs_reflog_exists(get_main_ref_store(the_repository), refname);
20492050
}
20502051

20512052
int refs_create_reflog(struct ref_store *refs, const char *refname,
@@ -2057,7 +2058,7 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
20572058
int safe_create_reflog(const char *refname, int force_create,
20582059
struct strbuf *err)
20592060
{
2060-
return refs_create_reflog(get_main_ref_store(), refname,
2061+
return refs_create_reflog(get_main_ref_store(the_repository), refname,
20612062
force_create, err);
20622063
}
20632064

@@ -2068,7 +2069,7 @@ int refs_delete_reflog(struct ref_store *refs, const char *refname)
20682069

20692070
int delete_reflog(const char *refname)
20702071
{
2071-
return refs_delete_reflog(get_main_ref_store(), refname);
2072+
return refs_delete_reflog(get_main_ref_store(the_repository), refname);
20722073
}
20732074

20742075
int refs_reflog_expire(struct ref_store *refs,
@@ -2091,7 +2092,7 @@ int reflog_expire(const char *refname, const struct object_id *oid,
20912092
reflog_expiry_cleanup_fn cleanup_fn,
20922093
void *policy_cb_data)
20932094
{
2094-
return refs_reflog_expire(get_main_ref_store(),
2095+
return refs_reflog_expire(get_main_ref_store(the_repository),
20952096
refname, oid, flags,
20962097
prepare_fn, should_prune_fn,
20972098
cleanup_fn, policy_cb_data);
@@ -2114,7 +2115,7 @@ int refs_delete_refs(struct ref_store *refs, const char *msg,
21142115
int delete_refs(const char *msg, struct string_list *refnames,
21152116
unsigned int flags)
21162117
{
2117-
return refs_delete_refs(get_main_ref_store(), msg, refnames, flags);
2118+
return refs_delete_refs(get_main_ref_store(the_repository), msg, refnames, flags);
21182119
}
21192120

21202121
int refs_rename_ref(struct ref_store *refs, const char *oldref,
@@ -2125,7 +2126,7 @@ int refs_rename_ref(struct ref_store *refs, const char *oldref,
21252126

21262127
int rename_ref(const char *oldref, const char *newref, const char *logmsg)
21272128
{
2128-
return refs_rename_ref(get_main_ref_store(), oldref, newref, logmsg);
2129+
return refs_rename_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
21292130
}
21302131

21312132
int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
@@ -2136,5 +2137,5 @@ int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
21362137

21372138
int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)
21382139
{
2139-
return refs_copy_existing_ref(get_main_ref_store(), oldref, newref, logmsg);
2140+
return refs_copy_existing_ref(get_main_ref_store(the_repository), oldref, newref, logmsg);
21402141
}

refs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ int reflog_expire(const char *refname, const struct object_id *oid,
758758

759759
int ref_storage_backend_exists(const char *name);
760760

761-
struct ref_store *get_main_ref_store(void);
761+
#define get_main_ref_store(r) \
762+
get_main_ref_store_##r()
763+
struct ref_store *get_main_ref_store_the_repository(void);
762764
/*
763765
* Return the ref_store instance for the specified submodule. For the
764766
* main repository, use submodule==NULL; such a call cannot fail. For

revision.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "diff.h"
77
#include "refs.h"
88
#include "revision.h"
9+
#include "repository.h"
910
#include "graph.h"
1011
#include "grep.h"
1112
#include "reflog-walk.h"
@@ -1285,7 +1286,7 @@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags)
12851286

12861287
cb.all_revs = revs;
12871288
cb.all_flags = flags;
1288-
cb.refs = get_main_ref_store();
1289+
cb.refs = get_main_ref_store(the_repository);
12891290
for_each_reflog(handle_one_reflog, &cb);
12901291

12911292
if (!revs->single_worktree)
@@ -2176,7 +2177,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
21762177
die("BUG: --single-worktree cannot be used together with submodule");
21772178
refs = get_submodule_ref_store(submodule);
21782179
} else
2179-
refs = get_main_ref_store();
2180+
refs = get_main_ref_store(the_repository);
21802181

21812182
/*
21822183
* NOTE!

t/helper/test-ref-store.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "refs.h"
44
#include "worktree.h"
55
#include "object-store.h"
6+
#include "repository.h"
67

78
static const char *notnull(const char *arg, const char *name)
89
{
@@ -23,7 +24,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
2324
if (!argv[0]) {
2425
die("ref store required");
2526
} else if (!strcmp(argv[0], "main")) {
26-
*refs = get_main_ref_store();
27+
*refs = get_main_ref_store(the_repository);
2728
} else if (skip_prefix(argv[0], "submodule:", &gitdir)) {
2829
struct strbuf sb = STRBUF_INIT;
2930
int ret;

0 commit comments

Comments
 (0)