summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-06-25 21:35:58 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-06-25 21:35:58 +0200
commitc19b1c0442b52e07f1c9f48b65ef0b3823eaa526 (patch)
treefe3b26bdc719e7a74083476007b1a2fc326f8ee3
parent966fb207021830819aad9fce098b4a63838def4d (diff)
downloadlibgit2-c19b1c0442b52e07f1c9f48b65ef0b3823eaa526.tar.gz
pack: clean up error returns
Set a message when we fail to lock. Also make the put function void, since it's called from free, which cannot report errors. The only errors we can experience here are internal state corruption, so we assert that we are trying to put a pack which we have previously got.
-rw-r--r--src/mwindow.c22
-rw-r--r--src/mwindow.h2
2 files changed, 11 insertions, 13 deletions
diff --git a/src/mwindow.c b/src/mwindow.c
index a03a6597e..1d64d26a4 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -62,8 +62,10 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
if ((error = git_packfile__name(&packname, path)) < 0)
return error;
- if (git_mutex_lock(&git__mwindow_mutex) < 0)
+ if (git_mutex_lock(&git__mwindow_mutex) < 0) {
+ giterr_set(GITERR_OS, "failed to lock mwindow mutex");
return -1;
+ }
if (git_mwindow_files_init() < 0) {
git_mutex_unlock(&git__mwindow_mutex);
@@ -103,24 +105,20 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
return 0;
}
-int git_mwindow_put_pack(struct git_pack_file *pack)
+void git_mwindow_put_pack(struct git_pack_file *pack)
{
int count;
git_strmap_iter pos;
if (git_mutex_lock(&git__mwindow_mutex) < 0)
- return -1;
+ return;
- if (git_mwindow_files_init() < 0) {
- git_mutex_unlock(&git__mwindow_mutex);
- return -1;
- }
+ /* put before get would be a corrupted state */
+ assert(git__pack_cache);
pos = git_strmap_lookup_index(git__pack_cache, pack->pack_name);
- if (!git_strmap_valid_index(git__pack_cache, pos)) {
- git_mutex_unlock(&git__mwindow_mutex);
- return GIT_ENOTFOUND;
- }
+ /* if we cannot find it, the state is corrupted */
+ assert(git_strmap_valid_index(git__pack_cache, pos));
count = git_atomic_dec(&pack->refcount);
if (count == 0) {
@@ -129,7 +127,7 @@ int git_mwindow_put_pack(struct git_pack_file *pack)
}
git_mutex_unlock(&git__mwindow_mutex);
- return 0;
+ return;
}
void git_mwindow_free_all(git_mwindow_file *mwf)
diff --git a/src/mwindow.h b/src/mwindow.h
index 57fabae70..63418e458 100644
--- a/src/mwindow.h
+++ b/src/mwindow.h
@@ -48,6 +48,6 @@ void git_mwindow_files_free(void);
struct git_pack_file; /* just declaration to avoid cyclical includes */
int git_mwindow_get_pack(struct git_pack_file **out, const char *path);
-int git_mwindow_put_pack(struct git_pack_file *pack);
+void git_mwindow_put_pack(struct git_pack_file *pack);
#endif