diff options
author | Russell Belfer <rb@github.com> | 2013-12-03 16:45:39 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-12-11 10:57:49 -0800 |
commit | 96869a4edb2872934e0e167a726ab240f4270fea (patch) | |
tree | 2d770414acef2d1d45a609e004c0aa6fa56d06d7 /src/odb_loose.c | |
parent | 9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (diff) | |
download | libgit2-96869a4edb2872934e0e167a726ab240f4270fea.tar.gz |
Improve GIT_EUSER handling
This adds giterr_user_cancel to return GIT_EUSER and clear any
error message that is sitting around. As a result of using that
in places, we need to be more thorough with capturing errors that
happen inside a callback when used internally. To help with that,
this also adds giterr_capture and giterr_restore so that when we
internally use a foreach-type function that clears errors and
converts them to GIT_EUSER, it is easier to restore not just the
return value, but the actual error message text.
Diffstat (limited to 'src/odb_loose.c')
-rw-r--r-- | src/odb_loose.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c index ced272b33..ae772b425 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -696,7 +696,7 @@ struct foreach_state { size_t dir_len; git_odb_foreach_cb cb; void *data; - int cb_error; + git_error_state cb_error; }; GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr) @@ -735,10 +735,8 @@ 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)) { - state->cb_error = GIT_EUSER; - return -1; - } + if (state->cb(&oid, state->data)) + return giterr_user_cancel(); return 0; } @@ -747,7 +745,9 @@ static int foreach_cb(void *_state, git_buf *path) { struct foreach_state *state = (struct foreach_state *) _state; - return git_path_direach(path, 0, foreach_object_dir_cb, state); + return giterr_capture( + &state->cb_error, + 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,7 +762,8 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb objects_dir = backend->objects_dir; - git_buf_sets(&buf, objects_dir); + if (git_buf_sets(&buf, objects_dir) < 0) + return -1; git_path_to_dir(&buf); memset(&state, 0, sizeof(state)); @@ -772,9 +773,12 @@ 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 state.cb_error ? state.cb_error : error; + return error; } static int loose_backend__stream_fwrite(git_odb_stream *_stream, const git_oid *oid) |