summaryrefslogtreecommitdiff
path: root/src/odb_loose.c
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 /src/odb_loose.c
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 'src/odb_loose.c')
-rw-r--r--src/odb_loose.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index ae772b425..78cd792bd 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -547,8 +547,7 @@ static int locate_object_short_oid(
/* Explore directory to find a unique object matching short_oid */
error = git_path_direach(
object_location, 0, fn_locate_object_short_oid, &state);
-
- if (error && error != GIT_EUSER)
+ if (error < 0 && error != GIT_EAMBIGUOUS)
return error;
if (!state.found)
@@ -696,7 +695,6 @@ struct foreach_state {
size_t dir_len;
git_odb_foreach_cb cb;
void *data;
- git_error_state cb_error;
};
GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
@@ -735,19 +733,15 @@ static int foreach_object_dir_cb(void *_state, git_buf *path)
if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0)
return 0;
- if (state->cb(&oid, state->data))
- return giterr_user_cancel();
-
- return 0;
+ return giterr_set_callback(
+ state->cb(&oid, state->data), "git_odb_foreach");
}
static int foreach_cb(void *_state, git_buf *path)
{
struct foreach_state *state = (struct foreach_state *) _state;
- return giterr_capture(
- &state->cb_error,
- git_path_direach(path, 0, foreach_object_dir_cb, state));
+ return git_path_direach(path, 0, foreach_object_dir_cb, state);
}
static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
@@ -762,9 +756,10 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
objects_dir = backend->objects_dir;
- if (git_buf_sets(&buf, objects_dir) < 0)
- return -1;
+ git_buf_sets(&buf, objects_dir);
git_path_to_dir(&buf);
+ if (git_buf_oom(&buf))
+ return -1;
memset(&state, 0, sizeof(state));
state.cb = cb;
@@ -773,9 +768,6 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
error = git_path_direach(&buf, 0, foreach_cb, &state);
- if (error == GIT_EUSER)
- error = giterr_restore(&state.cb_error);
-
git_buf_free(&buf);
return error;