summaryrefslogtreecommitdiff
path: root/src/refs.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-05-04 16:03:17 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2013-05-11 11:20:37 +0200
commit95727245fd4f08aa77d1077901976ab3bd7472e1 (patch)
tree38986d17bc5538b85df9b5886f069a567f2b3e8b /src/refs.c
parent932af0e9eb35e37b2cf993c0806d6ea46476cf39 (diff)
downloadlibgit2-95727245fd4f08aa77d1077901976ab3bd7472e1.tar.gz
refs: implement _foreach with the iterator
Diffstat (limited to 'src/refs.c')
-rw-r--r--src/refs.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/refs.c b/src/refs.c
index 547bd570c..4ee6235cf 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -562,10 +562,28 @@ int git_reference_foreach(
git_reference_foreach_cb callback,
void *payload)
{
- git_refdb *refdb;
- git_repository_refdb__weakptr(&refdb, repo);
+ git_reference_iterator *iter;
+ const char *name;
+ int error;
+
+ GIT_UNUSED(list_flags);
+
+ if (git_reference_iterator_new(&iter, repo) < 0)
+ return -1;
- return git_refdb_foreach(refdb, list_flags, callback, payload);
+ while ((error = git_reference_next(&name, iter)) == 0) {
+ if (callback(name, payload)) {
+ error = GIT_EUSER;
+ goto out;
+ }
+ }
+
+ if (error == GIT_ITEROVER)
+ error = 0;
+
+out:
+ git_reference_iterator_free(iter);
+ return error;
}
int git_reference_iterator_new(git_reference_iterator **out, git_repository *repo)