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:
authorCarlos Martín Nieto <cmn@dwim.me>2013-11-02 03:05:32 +0400
committerCarlos Martín Nieto <cmn@dwim.me>2013-11-11 18:35:51 +0400
commit359dce726d215be65aee719c7316b43e3851c031 (patch)
tree7a4a0c0af01d2d02683a3aed27eca8315f1f9ca0 /tests-clar
parent266af6d81960144334c16e061f1d30f94f8a1b46 (diff)
remote: make _ls return the list directly
The callback-based method of listing remote references dates back to the beginning of the network code's lifetime, when we didn't know any better. We need to keep the list around for update_tips() after disconnect() so let's make use of this to simply give the user a pointer to the array so they can write straightforward code instead of having to go through a callback.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/network/remote/local.c51
-rw-r--r--tests-clar/online/fetch.c19
-rw-r--r--tests-clar/online/push.c7
-rw-r--r--tests-clar/online/push_util.c15
-rw-r--r--tests-clar/online/push_util.h5
5 files changed, 42 insertions, 55 deletions
diff --git a/tests-clar/network/remote/local.c b/tests-clar/network/remote/local.c
index 6d658a2e4..309142925 100644
--- a/tests-clar/network/remote/local.c
+++ b/tests-clar/network/remote/local.c
@@ -26,26 +26,6 @@ void test_network_remote_local__cleanup(void)
cl_fixture_cleanup("remotelocal");
}
-static int count_ref__cb(git_remote_head *head, void *payload)
-{
- int *count = (int *)payload;
-
- (void)head;
- (*count)++;
-
- return 0;
-}
-
-static int ensure_peeled__cb(git_remote_head *head, void *payload)
-{
- GIT_UNUSED(payload);
-
- if(strcmp(head->name, "refs/tags/test^{}") != 0)
- return 0;
-
- return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d");
-}
-
static void connect_to_local_repository(const char *local_repository)
{
git_buf_sets(&file_path_buf, cl_git_path_url(local_repository));
@@ -65,39 +45,42 @@ void test_network_remote_local__connected(void)
void test_network_remote_local__retrieve_advertised_references(void)
{
- int how_many_refs = 0;
+ const git_remote_head **refs;
+ size_t refs_len;
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+ cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
- cl_assert_equal_i(how_many_refs, 28);
+ cl_assert_equal_i(refs_len, 28);
}
void test_network_remote_local__retrieve_advertised_references_after_disconnect(void)
{
- int how_many_refs = 0;
+ const git_remote_head **refs;
+ size_t refs_len;
connect_to_local_repository(cl_fixture("testrepo.git"));
git_remote_disconnect(remote);
- cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+ cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
- cl_assert_equal_i(how_many_refs, 28);
+ cl_assert_equal_i(refs_len, 28);
}
void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void)
{
- int how_many_refs = 0;
+ const git_remote_head **refs;
+ size_t refs_len;
cl_fixture_sandbox("testrepo.git");
cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
connect_to_local_repository("spaced testrepo.git");
- cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+ cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
- cl_assert_equal_i(how_many_refs, 28);
+ cl_assert_equal_i(refs_len, 28);
git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
remote = NULL;
@@ -107,9 +90,17 @@ void test_network_remote_local__retrieve_advertised_references_from_spaced_repos
void test_network_remote_local__nested_tags_are_completely_peeled(void)
{
+ const git_remote_head **refs;
+ size_t refs_len, i;
+
connect_to_local_repository(cl_fixture("testrepo.git"));
- cl_git_pass(git_remote_ls(remote, &ensure_peeled__cb, NULL));
+ cl_git_pass(git_remote_ls(&refs, &refs_len, remote));
+
+ for (i = 0; i < refs_len; i++) {
+ if (!strcmp(refs[i]->name, "refs/tags/test^{}"))
+ cl_git_pass(git_oid_streq(&refs[i]->oid, "e90810b8df3e80c413d903f631643c716887138d"));
+ }
}
void test_network_remote_local__shorthand_fetch_refspec0(void)
diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c
index df1b2e288..5153a7ae0 100644
--- a/tests-clar/online/fetch.c
+++ b/tests-clar/online/fetch.c
@@ -152,29 +152,20 @@ void test_online_fetch__can_cancel(void)
git_remote_free(remote);
}
-int ls_cb(git_remote_head *rhead, void *payload)
-{
- int *nr = payload;
- GIT_UNUSED(rhead);
-
- (*nr)++;
-
- return 0;
-}
-
void test_online_fetch__ls_disconnected(void)
{
+ const git_remote_head **refs;
+ size_t refs_len_before, refs_len_after;
git_remote *remote;
- int nr_before = 0, nr_after = 0;
cl_git_pass(git_remote_create(&remote, _repo, "test",
"http://github.com/libgit2/TestGitRepository.git"));
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_ls(remote, ls_cb, &nr_before));
+ cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote));
git_remote_disconnect(remote);
- cl_git_pass(git_remote_ls(remote, ls_cb, &nr_after));
+ cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote));
- cl_assert_equal_i(nr_before, nr_after);
+ cl_assert_equal_i(refs_len_before, refs_len_after);
git_remote_free(remote);
}
diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c
index 5a747bba7..9ed97174b 100644
--- a/tests-clar/online/push.c
+++ b/tests-clar/online/push.c
@@ -155,10 +155,11 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
*/
static void verify_refs(git_remote *remote, expected_ref expected_refs[], size_t expected_refs_len)
{
- git_vector actual_refs = GIT_VECTOR_INIT;
+ const git_remote_head **actual_refs;
+ size_t actual_refs_len;
- git_remote_ls(remote, record_ref_cb, &actual_refs);
- verify_remote_refs(&actual_refs, expected_refs, expected_refs_len);
+ git_remote_ls(&actual_refs, &actual_refs_len, remote);
+ verify_remote_refs(actual_refs, actual_refs_len, expected_refs, expected_refs_len);
git_vector_free(&actual_refs);
}
diff --git a/tests-clar/online/push_util.c b/tests-clar/online/push_util.c
index 2e457844d..e3f326932 100644
--- a/tests-clar/online/push_util.c
+++ b/tests-clar/online/push_util.c
@@ -69,26 +69,28 @@ int record_ref_cb(git_remote_head *head, void *payload)
return git_vector_insert(refs, head);
}
-void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len)
+void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len)
{
size_t i, j = 0;
git_buf msg = GIT_BUF_INIT;
- git_remote_head *actual;
+ const git_remote_head *actual;
char *oid_str;
bool master_present = false;
/* We don't care whether "master" is present on the other end or not */
- git_vector_foreach(actual_refs, i, actual) {
+ for (i = 0; i < actual_refs_len; i++) {
+ actual = actual_refs[i];
if (!strcmp(actual->name, "refs/heads/master")) {
master_present = true;
break;
}
}
- if (expected_refs_len + (master_present ? 1 : 0) != actual_refs->length)
+ if (expected_refs_len + (master_present ? 1 : 0) != actual_refs_len)
goto failed;
- git_vector_foreach(actual_refs, i, actual) {
+ for (i = 0; i < actual_refs_len; i++) {
+ actual = actual_refs[i];
if (master_present && !strcmp(actual->name, "refs/heads/master"))
continue;
@@ -111,7 +113,8 @@ failed:
}
git_buf_puts(&msg, "\nACTUAL:\n");
- git_vector_foreach(actual_refs, i, actual) {
+ for (i = 0; i < actual_refs_len; i++) {
+ actual = actual_refs[i];
if (master_present && !strcmp(actual->name, "refs/heads/master"))
continue;
diff --git a/tests-clar/online/push_util.h b/tests-clar/online/push_util.h
index 64f02cf2f..e6ddb7133 100644
--- a/tests-clar/online/push_util.h
+++ b/tests-clar/online/push_util.h
@@ -60,10 +60,11 @@ int record_ref_cb(git_remote_head *head, void *payload);
* Verifies that refs on remote stored by record_ref_cb match the expected
* names, oids, and order.
*
- * @param actual_refs actual refs stored by record_ref_cb()
+ * @param actual_refs actual refs in the remote
+ * @param actual_refs_len length of actual_refs
* @param expected_refs expected remote refs
* @param expected_refs_len length of expected_refs
*/
-void verify_remote_refs(git_vector *actual_refs, const expected_ref expected_refs[], size_t expected_refs_len);
+void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len);
#endif /* INCLUDE_cl_push_util_h__ */