Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-05-11 13:42:49 +0400
committerEdward Thomson <ethomson@microsoft.com>2013-05-11 13:42:49 +0400
commitb6cc559a78a073f2aadd179fe40c09be7318c898 (patch)
treec40a7806c16eb133794427aa2e1ca25e86ce1d74 /tests-clar/refs
parent4a65aead2ce2003902f4b54b331af33af7340b58 (diff)
parentc58cac12c24fbb127cf1928bec20decb007a75e8 (diff)
Merge pull request #1385 from carlosmn/refs-iter
Introduce a refs iterator
Diffstat (limited to 'tests-clar/refs')
-rw-r--r--tests-clar/refs/foreachglob.c14
-rw-r--r--tests-clar/refs/iterator.c94
-rw-r--r--tests-clar/refs/list.c15
-rw-r--r--tests-clar/refs/listall.c4
4 files changed, 105 insertions, 22 deletions
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
index 4da1a15dd..2c458082f 100644
--- a/tests-clar/refs/foreachglob.c
+++ b/tests-clar/refs/foreachglob.c
@@ -37,11 +37,11 @@ static int count_cb(const char *reference_name, void *payload)
return 0;
}
-static void assert_retrieval(const char *glob, unsigned int flags, int expected_count)
+static void assert_retrieval(const char *glob, int expected_count)
{
int count = 0;
- cl_git_pass(git_reference_foreach_glob(repo, glob, flags, count_cb, &count));
+ cl_git_pass(git_reference_foreach_glob(repo, glob, count_cb, &count));
cl_assert_equal_i(expected_count, count);
}
@@ -49,17 +49,17 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_
void test_refs_foreachglob__retrieve_all_refs(void)
{
/* 12 heads (including one packed head) + 1 note + 2 remotes + 7 tags */
- assert_retrieval("*", GIT_REF_LISTALL, 22);
+ assert_retrieval("*", 22);
}
void test_refs_foreachglob__retrieve_remote_branches(void)
{
- assert_retrieval("refs/remotes/*", GIT_REF_LISTALL, 2);
+ assert_retrieval("refs/remotes/*", 2);
}
void test_refs_foreachglob__retrieve_local_branches(void)
{
- assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 12);
+ assert_retrieval("refs/heads/*", 12);
}
void test_refs_foreachglob__retrieve_partially_named_references(void)
@@ -69,7 +69,7 @@ void test_refs_foreachglob__retrieve_partially_named_references(void)
* refs/remotes/test/master, refs/tags/test
*/
- assert_retrieval("*test*", GIT_REF_LISTALL, 4);
+ assert_retrieval("*test*", 4);
}
@@ -89,7 +89,7 @@ void test_refs_foreachglob__can_cancel(void)
int count = 0;
cl_assert_equal_i(GIT_EUSER, git_reference_foreach_glob(
- repo, "*", GIT_REF_LISTALL, interrupt_cb, &count) );
+ repo, "*", interrupt_cb, &count) );
cl_assert_equal_i(11, count);
}
diff --git a/tests-clar/refs/iterator.c b/tests-clar/refs/iterator.c
new file mode 100644
index 000000000..d5555c657
--- /dev/null
+++ b/tests-clar/refs/iterator.c
@@ -0,0 +1,94 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "vector.h"
+
+static git_repository *repo;
+
+void test_refs_iterator__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+}
+
+void test_refs_iterator__cleanup(void)
+{
+ git_repository_free(repo);
+}
+
+static const char *refnames[] = {
+ "refs/heads/br2",
+ "refs/heads/cannot-fetch",
+ "refs/heads/chomped",
+ "refs/heads/haacked",
+ "refs/heads/master",
+ "refs/heads/not-good",
+ "refs/heads/packed",
+ "refs/heads/packed-test",
+ "refs/heads/subtrees",
+ "refs/heads/test",
+ "refs/heads/track-local",
+ "refs/heads/trailing",
+ "refs/notes/fanout",
+ "refs/remotes/test/master",
+ "refs/tags/annotated_tag_to_blob",
+ "refs/tags/e90810b",
+ "refs/tags/hard_tag",
+ "refs/tags/point_to_blob",
+ "refs/tags/taggerless",
+ "refs/tags/test",
+ "refs/tags/wrapped_tag",
+};
+
+void test_refs_iterator__list(void)
+{
+ git_reference_iterator *iter;
+ git_vector output;
+ char *refname;
+ int error;
+ size_t i;
+
+ cl_git_pass(git_vector_init(&output, 32, git__strcmp_cb));
+ cl_git_pass(git_reference_iterator_new(&iter, repo));
+
+ do {
+ const char *name;
+ error = git_reference_next(&name, iter);
+ cl_assert(error == 0 || error == GIT_ITEROVER);
+ if (error != GIT_ITEROVER) {
+ char *dup = git__strdup(name);
+ cl_assert(dup != NULL);
+ cl_git_pass(git_vector_insert(&output, dup));
+ }
+ } while (!error);
+
+ cl_assert_equal_i(output.length, ARRAY_SIZE(refnames));
+
+ git_vector_sort(&output);
+ git_vector_foreach(&output, i, refname) {
+ cl_assert_equal_s(refname, refnames[i]);
+ }
+
+ git_reference_iterator_free(iter);
+
+ git_vector_foreach(&output, i, refname) {
+ git__free(refname);
+ }
+ git_vector_free(&output);
+}
+
+void test_refs_iterator__empty(void)
+{
+ git_reference_iterator *iter;
+ git_odb *odb;
+ const char *name;
+ git_repository *empty;
+
+ cl_git_pass(git_odb_new(&odb));
+ cl_git_pass(git_repository_wrap_odb(&empty, odb));
+
+ cl_git_pass(git_reference_iterator_new(&iter, empty));
+ cl_assert_equal_i(GIT_ITEROVER, git_reference_next(&name, iter));
+
+ git_reference_iterator_free(iter);
+ git_odb_free(odb);
+ git_repository_free(empty);
+}
diff --git a/tests-clar/refs/list.c b/tests-clar/refs/list.c
index 3948b2b7a..c9c2af4a7 100644
--- a/tests-clar/refs/list.c
+++ b/tests-clar/refs/list.c
@@ -25,7 +25,7 @@ void test_refs_list__all(void)
// try to list all the references in our test repo
git_strarray ref_list;
- cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, g_repo));
/*{
unsigned short i;
@@ -41,17 +41,6 @@ void test_refs_list__all(void)
git_strarray_free(&ref_list);
}
-void test_refs_list__symbolic_only(void)
-{
- // try to list only the symbolic references
- git_strarray ref_list;
-
- cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_SYMBOLIC));
- cl_assert(ref_list.count == 0); /* no symrefs in the test repo */
-
- git_strarray_free(&ref_list);
-}
-
void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_extension(void)
{
git_strarray ref_list;
@@ -61,7 +50,7 @@ void test_refs_list__do_not_retrieve_references_which_name_end_with_a_lock_exten
"./testrepo/.git/refs/heads/hanwen.lock",
"144344043ba4d4a405da03de3844aa829ae8be0e\n");
- cl_git_pass(git_reference_list(&ref_list, g_repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, g_repo));
cl_assert_equal_i((int)ref_list.count, 13);
git_strarray_free(&ref_list);
diff --git a/tests-clar/refs/listall.c b/tests-clar/refs/listall.c
index 8f4c3746b..c696fbb2e 100644
--- a/tests-clar/refs/listall.c
+++ b/tests-clar/refs/listall.c
@@ -9,7 +9,7 @@ static void ensure_no_refname_starts_with_a_forward_slash(const char *path)
size_t i;
cl_git_pass(git_repository_open(&repo, path));
- cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, repo));
cl_assert(ref_list.count > 0);
@@ -38,7 +38,7 @@ void test_refs_listall__from_repository_opened_through_gitdir_path(void)
void test_refs_listall__from_repository_with_no_trailing_newline(void)
{
cl_git_pass(git_repository_open(&repo, cl_fixture("bad_tag.git")));
- cl_git_pass(git_reference_list(&ref_list, repo, GIT_REF_LISTALL));
+ cl_git_pass(git_reference_list(&ref_list, repo));
cl_assert(ref_list.count > 0);