summaryrefslogtreecommitdiff
path: root/tests/online
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-06 15:07:57 -0800
committerRussell Belfer <rb@github.com>2013-12-11 10:57:49 -0800
commit25e0b1576d5f9e5248603f81d3198a65bfccf0ed (patch)
treedac0da29acfbd6478bed93bcab3557e2877dabaa /tests/online
parentfcd324c625d8be3f368c924d787e945e5812d8dd (diff)
downloadlibgit2-25e0b1576d5f9e5248603f81d3198a65bfccf0ed.tar.gz
Remove converting user error to GIT_EUSER
This changes the behavior of callbacks so that the callback error code is not converted into GIT_EUSER and instead we propagate the return value through to the caller. Instead of using the giterr_capture and giterr_restore functions, we now rely on all functions to pass back the return value from a callback. To avoid having a return value with no error message, the user can call the public giterr_set_str or some such function to set an error message. There is a new helper 'giterr_set_callback' that functions can invoke after making a callback which ensures that some error message was set in case the callback did not set one. In places where the sign of the callback return value is meaningful (e.g. positive to skip, negative to abort), only the negative values are returned back to the caller, obviously, since the other values allow for continuing the loop. The hardest parts of this were in the checkout code where positive return values were overloaded as meaningful values for checkout. I fixed this by adding an output parameter to many of the internal checkout functions and removing the overload. This added some code, but it is probably a better implementation. There is some funkiness in the network code where user provided callbacks could be returning a positive or a negative value and we want to rely on that to cancel the loop. There are still a couple places where an user error might get turned into GIT_EUSER there, I think, though none exercised by the tests.
Diffstat (limited to 'tests/online')
-rw-r--r--tests/online/clone.c5
-rw-r--r--tests/online/fetch.c4
2 files changed, 5 insertions, 4 deletions
diff --git a/tests/online/clone.c b/tests/online/clone.c
index efc76d958..be4421ae5 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -273,7 +273,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
GIT_UNUSED(payload);
if (stats->received_objects > (stats->total_objects/2))
- return 1;
+ return 4321;
return 0;
}
@@ -281,7 +281,8 @@ void test_online_clone__can_cancel(void)
{
g_options.remote_callbacks.transfer_progress = cancel_at_half;
- cl_git_fail_with(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), GIT_EUSER);
+ cl_git_fail_with(
+ git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), 4321);
}
diff --git a/tests/online/fetch.c b/tests/online/fetch.c
index 5153a7ae0..7e9dfdbbe 100644
--- a/tests/online/fetch.c
+++ b/tests/online/fetch.c
@@ -129,7 +129,7 @@ static int cancel_at_half(const git_transfer_progress *stats, void *payload)
GIT_UNUSED(payload);
if (stats->received_objects > (stats->total_objects/2))
- return -1;
+ return -4321;
return 0;
}
@@ -147,7 +147,7 @@ void test_online_fetch__can_cancel(void)
git_remote_set_callbacks(remote, &callbacks);
cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
- cl_git_fail_with(git_remote_download(remote), GIT_EUSER);
+ cl_git_fail_with(git_remote_download(remote), -4321);
git_remote_disconnect(remote);
git_remote_free(remote);
}