diff options
author | Russell Belfer <rb@github.com> | 2013-12-06 15:07:57 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-12-11 10:57:49 -0800 |
commit | 25e0b1576d5f9e5248603f81d3198a65bfccf0ed (patch) | |
tree | dac0da29acfbd6478bed93bcab3557e2877dabaa /src/odb_pack.c | |
parent | fcd324c625d8be3f368c924d787e945e5812d8dd (diff) | |
download | libgit2-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_pack.c')
-rw-r--r-- | src/odb_pack.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c index 2c0319fb6..903b00d26 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -190,15 +190,9 @@ static int packfile_sort__cb(const void *a_, const void *b_) } -struct packfile_load_data { - struct pack_backend *backend; - git_error_state error; -}; - -static int packfile_load__cb(void *_data, git_buf *path) +static int packfile_load__cb(void *data, git_buf *path) { - struct packfile_load_data *data = _data; - struct pack_backend *backend = data->backend; + struct pack_backend *backend = data; struct git_pack_file *pack; const char *path_str = git_buf_cstr(path); size_t i, cmp_len = git_buf_len(path); @@ -227,7 +221,7 @@ static int packfile_load__cb(void *_data, git_buf *path) if (!error) error = git_vector_insert(&backend->packs, pack); - return giterr_capture(&data->error, error); + return error; } @@ -328,32 +322,26 @@ static int pack_entry_find_prefix( * Implement the git_odb_backend API calls * ***********************************************************/ -static int pack_backend__refresh(git_odb_backend *backend) +static int pack_backend__refresh(git_odb_backend *backend_) { - struct packfile_load_data data; int error; struct stat st; git_buf path = GIT_BUF_INIT; + struct pack_backend *backend = (struct pack_backend *)backend_; - memset(&data, 0, sizeof(data)); - data.backend = (struct pack_backend *)backend; - - if (data.backend->pack_folder == NULL) + if (backend->pack_folder == NULL) return 0; - if (p_stat(data.backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode)) + if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode)) return git_odb__error_notfound("failed to refresh packfiles", NULL); - git_buf_sets(&path, data.backend->pack_folder); + git_buf_sets(&path, backend->pack_folder); /* reload all packs */ - error = git_path_direach(&path, 0, packfile_load__cb, &data); - - if (error == GIT_EUSER) - error = giterr_restore(&data.error); + error = git_path_direach(&path, 0, packfile_load__cb, backend); git_buf_free(&path); - git_vector_sort(&data.backend->packs); + git_vector_sort(&backend->packs); return error; } |