Commit 95727245fd4f08aa77d1077901976ab3bd7472e1

Carlos Martín Nieto 2013-05-04T16:03:17

refs: implement _foreach with the iterator

diff --git a/src/refs.c b/src/refs.c
index 547bd57..4ee6235 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)