Skip to content

Commit 65cf102

Browse files
mhaggergitster
authored andcommitted
refs: change do_for_each_*() functions to take ref_cache arguments
Change the callers convert submodule names into ref_cache pointers. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b2a8226 commit 65cf102

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

refs.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,16 +1504,15 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
15041504
}
15051505

15061506
/*
1507-
* Call fn for each reference in the specified submodule, omitting
1507+
* Call fn for each reference in the specified ref_cache, omitting
15081508
* references not in the containing_dir of base. fn is called for all
15091509
* references, including broken ones. If fn ever returns a non-zero
15101510
* value, stop the iteration and return that value; otherwise, return
15111511
* 0.
15121512
*/
1513-
static int do_for_each_entry(const char *submodule, const char *base,
1513+
static int do_for_each_entry(struct ref_cache *refs, const char *base,
15141514
each_ref_entry_fn fn, void *cb_data)
15151515
{
1516-
struct ref_cache *refs = get_ref_cache(submodule);
15171516
struct ref_dir *packed_dir = get_packed_refs(refs);
15181517
struct ref_dir *loose_dir = get_loose_refs(refs);
15191518
int retval = 0;
@@ -1542,16 +1541,16 @@ static int do_for_each_entry(const char *submodule, const char *base,
15421541
}
15431542

15441543
/*
1545-
* Call fn for each reference in the specified submodule for which the
1544+
* Call fn for each reference in the specified ref_cache for which the
15461545
* refname begins with base. If trim is non-zero, then trim that many
15471546
* characters off the beginning of each refname before passing the
15481547
* refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to include
15491548
* broken references in the iteration. If fn ever returns a non-zero
15501549
* value, stop the iteration and return that value; otherwise, return
15511550
* 0.
15521551
*/
1553-
static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn fn,
1554-
int trim, int flags, void *cb_data)
1552+
static int do_for_each_ref(struct ref_cache *refs, const char *base,
1553+
each_ref_fn fn, int trim, int flags, void *cb_data)
15551554
{
15561555
struct ref_entry_cb data;
15571556
data.base = base;
@@ -1560,7 +1559,7 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
15601559
data.fn = fn;
15611560
data.cb_data = cb_data;
15621561

1563-
return do_for_each_entry(submodule, base, do_one_ref, &data);
1562+
return do_for_each_entry(refs, base, do_one_ref, &data);
15641563
}
15651564

15661565
static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
@@ -1593,23 +1592,23 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
15931592

15941593
int for_each_ref(each_ref_fn fn, void *cb_data)
15951594
{
1596-
return do_for_each_ref(NULL, "", fn, 0, 0, cb_data);
1595+
return do_for_each_ref(get_ref_cache(NULL), "", fn, 0, 0, cb_data);
15971596
}
15981597

15991598
int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
16001599
{
1601-
return do_for_each_ref(submodule, "", fn, 0, 0, cb_data);
1600+
return do_for_each_ref(get_ref_cache(submodule), "", fn, 0, 0, cb_data);
16021601
}
16031602

16041603
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
16051604
{
1606-
return do_for_each_ref(NULL, prefix, fn, strlen(prefix), 0, cb_data);
1605+
return do_for_each_ref(get_ref_cache(NULL), prefix, fn, strlen(prefix), 0, cb_data);
16071606
}
16081607

16091608
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
16101609
each_ref_fn fn, void *cb_data)
16111610
{
1612-
return do_for_each_ref(submodule, prefix, fn, strlen(prefix), 0, cb_data);
1611+
return do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);
16131612
}
16141613

16151614
int for_each_tag_ref(each_ref_fn fn, void *cb_data)
@@ -1644,7 +1643,7 @@ int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *c
16441643

16451644
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
16461645
{
1647-
return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);
1646+
return do_for_each_ref(get_ref_cache(NULL), "refs/replace/", fn, 13, 0, cb_data);
16481647
}
16491648

16501649
int head_ref_namespaced(each_ref_fn fn, void *cb_data)
@@ -1667,7 +1666,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
16671666
struct strbuf buf = STRBUF_INIT;
16681667
int ret;
16691668
strbuf_addf(&buf, "%srefs/", get_git_namespace());
1670-
ret = do_for_each_ref(NULL, buf.buf, fn, 0, 0, cb_data);
1669+
ret = do_for_each_ref(get_ref_cache(NULL), buf.buf, fn, 0, 0, cb_data);
16711670
strbuf_release(&buf);
16721671
return ret;
16731672
}
@@ -1709,7 +1708,7 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
17091708

17101709
int for_each_rawref(each_ref_fn fn, void *cb_data)
17111710
{
1712-
return do_for_each_ref(NULL, "", fn, 0,
1711+
return do_for_each_ref(get_ref_cache(NULL), "", fn, 0,
17131712
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
17141713
}
17151714

@@ -2104,7 +2103,7 @@ int pack_refs(unsigned int flags)
21042103

21052104
write_or_die(cbdata.fd, PACKED_REFS_HEADER, strlen(PACKED_REFS_HEADER));
21062105

2107-
do_for_each_entry(NULL, "", pack_one_ref, &cbdata);
2106+
do_for_each_entry(get_ref_cache(NULL), "", pack_one_ref, &cbdata);
21082107
if (commit_lock_file(&packlock) < 0)
21092108
die_errno("unable to overwrite old ref-pack file");
21102109
prune_refs(cbdata.ref_to_prune);

0 commit comments

Comments
 (0)