Commit 86f5fa7810c5675d5c789450c9c140330432bbbb

schu 2011-05-11T14:00:38

Move vector.c to the new error handling Remove "redundant" check for v->_cmp in wrapper function git_vector_bsearch(). Signed-off-by: schu <schu-github@schulog.org>

diff --git a/src/vector.c b/src/vector.c
index d0b0c5c..1ddc26e 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -106,7 +106,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
 
 	/* need comparison function to sort the vector */
 	if (v->_cmp == NULL)
-		return GIT_ENOTFOUND;
+		return git__throw(GIT_ENOTFOUND, "Can't sort vector. No comparison function set");
 
 	git_vector_sort(v);
 
@@ -114,7 +114,7 @@ int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *ke
 	if (find != NULL)
 		return (int)(find - v->contents);
 
-	return GIT_ENOTFOUND;
+	return git__throw(GIT_ENOTFOUND, "Can't find element");
 }
 
 int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key)
@@ -128,7 +128,7 @@ int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key
 			return i;
 	}
 
-	return GIT_ENOTFOUND;
+	return git__throw(GIT_ENOTFOUND, "Can't find element");
 }
 
 static int strict_comparison(const void *a, const void *b)
@@ -143,9 +143,6 @@ int git_vector_search(git_vector *v, const void *entry)
 
 int git_vector_bsearch(git_vector *v, const void *key)
 {
-	if (v->_cmp == NULL)
-		return GIT_ENOTFOUND;
-
 	return git_vector_bsearch2(v, v->_cmp, key);
 }
 
@@ -156,7 +153,7 @@ int git_vector_remove(git_vector *v, unsigned int idx)
 	assert(v);
 
 	if (idx >= v->length || v->length == 0)
-		return GIT_ENOTFOUND;
+		return git__throw(GIT_ENOTFOUND, "Can't remove element. Index out of bounds");
 
 	for (i = idx; i < v->length - 1; ++i)
 		v->contents[i] = v->contents[i + 1];