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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 22, 2013 at 21:52 UTC
65cf102bb09804929261e1f6cbd2ff5e0af9f301
1 file changed
+14
-15
refs.c
+14
-15
@@ -1504,16 +1504,15 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
1504
}
1505
1506
/*
1507
- * Call fn for each reference in the specified submodule, omitting
1507
+ * Call fn for each reference in the specified ref_cache, omitting
1508
* references not in the containing_dir of base. fn is called for all
1509
* references, including broken ones. If fn ever returns a non-zero
1510
* value, stop the iteration and return that value; otherwise, return
1511
* 0.
1512
*/
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,
1514
each_ref_entry_fn fn, void *cb_data)
1515
{
1516
- struct ref_cache *refs = get_ref_cache(submodule);
1516
struct ref_dir *packed_dir = get_packed_refs(refs);
1517
struct ref_dir *loose_dir = get_loose_refs(refs);
1518
int retval = 0;
@@ -1542,7 +1541,7 @@ static int do_for_each_entry(const char *submodule, const char *base,
1541
}
1542
1543
/*
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
1545
* refname begins with base. If trim is non-zero, then trim that many
1546
* characters off the beginning of each refname before passing the
1547
* refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to include
@@ -1550,8 +1549,8 @@ static int do_for_each_entry(const char *submodule, const char *base,
1549
* value, stop the iteration and return that value; otherwise, return
1550
* 0.
1551
*/
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)
1554
{
1555
struct ref_entry_cb data;
1556
data.base = base;
@@ -1560,7 +1559,7 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
1559
data.fn = fn;
1560
data.cb_data = cb_data;
1561
1563
- return do_for_each_entry(submodule, base, do_one_ref, &data);
1562
+ return do_for_each_entry(refs, base, do_one_ref, &data);
1563
}
1564
1565
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)
1592
1593
int for_each_ref(each_ref_fn fn, void *cb_data)
1594
{
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);
1596
}
1597
1598
int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
1599
{
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);
1601
}
1602
1603
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
1604
{
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);
1606
}
1607
1608
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
1609
each_ref_fn fn, void *cb_data)
1610
{
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);
1612
}
1613
1614
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
1643
1644
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
1645
{
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);
1647
}
1648
1649
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)
1666
struct strbuf buf = STRBUF_INIT;
1667
int ret;
1668
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);
1670
strbuf_release(&buf);
1671
return ret;
1672
}
@@ -1709,7 +1708,7 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
1708
1709
int for_each_rawref(each_ref_fn fn, void *cb_data)
1710
{
1712
- return do_for_each_ref(NULL, "", fn, 0,
1711
+ return do_for_each_ref(get_ref_cache(NULL), "", fn, 0,
1712
DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
1713
}
1714
@@ -2104,7 +2103,7 @@ int pack_refs(unsigned int flags)
2103
2104
write_or_die(cbdata.fd, PACKED_REFS_HEADER, strlen(PACKED_REFS_HEADER));
2105
2107
- do_for_each_entry(NULL, "", pack_one_ref, &cbdata);
2106
+ do_for_each_entry(get_ref_cache(NULL), "", pack_one_ref, &cbdata);
2107
if (commit_lock_file(&packlock) < 0)
2108
die_errno("unable to overwrite old ref-pack file");
2109
prune_refs(cbdata.ref_to_prune);