summaryrefslogtreecommitdiff
path: root/src/refdb_fs.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-12-03 16:45:39 -0800
committerRussell Belfer <rb@github.com>2013-12-11 10:57:49 -0800
commit96869a4edb2872934e0e167a726ab240f4270fea (patch)
tree2d770414acef2d1d45a609e004c0aa6fa56d06d7 /src/refdb_fs.c
parent9f77b3f6f5ce6944ec49dfc666ef6b8df0af0c6b (diff)
downloadlibgit2-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/refdb_fs.c')
-rw-r--r--src/refdb_fs.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 62d5c1047..938e02a78 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -264,9 +264,14 @@ done:
return error;
}
-static int _dirent_loose_load(void *data, git_buf *full_path)
+struct packed_loadloose_data {
+ refdb_fs_backend *backend;
+ git_error_state error;
+};
+
+static int _dirent_loose_load(void *data_, git_buf *full_path)
{
- refdb_fs_backend *backend = (refdb_fs_backend *)data;
+ struct packed_loadloose_data *data = data_;
const char *file_path;
if (git__suffixcmp(full_path->ptr, ".lock") == 0)
@@ -274,11 +279,12 @@ static int _dirent_loose_load(void *data, git_buf *full_path)
if (git_path_isdir(full_path->ptr))
return git_path_direach(
- full_path, backend->direach_flags, _dirent_loose_load, backend);
+ full_path, data->backend->direach_flags, _dirent_loose_load, data);
- file_path = full_path->ptr + strlen(backend->path);
+ file_path = full_path->ptr + strlen(data->backend->path);
- return loose_lookup_to_packfile(backend, file_path);
+ return giterr_capture(
+ &data->error, loose_lookup_to_packfile(data->backend, file_path));
}
/*
@@ -291,21 +297,28 @@ static int packed_loadloose(refdb_fs_backend *backend)
{
int error;
git_buf refs_path = GIT_BUF_INIT;
+ struct packed_loadloose_data data;
if (git_buf_joinpath(&refs_path, backend->path, GIT_REFS_DIR) < 0)
return -1;
+ memset(&data, 0, sizeof(data));
+ data.backend = backend;
+
/*
* Load all the loose files from disk into the Packfile table.
* This will overwrite any old packed entries with their
* updated loose versions
*/
error = git_path_direach(
- &refs_path, backend->direach_flags, _dirent_loose_load, backend);
+ &refs_path, backend->direach_flags, _dirent_loose_load, &data);
git_buf_free(&refs_path);
- return (error == GIT_EUSER) ? -1 : error;
+ if (error == GIT_EUSER)
+ error = giterr_restore(&data.error);
+
+ return error;
}
static int refdb_fs_backend__exists(