Commit 0d5d5190 by Vicent Marti

refs: Reword errors

parent 5bdf7b9f
...@@ -1489,16 +1489,15 @@ int git_reference_resolve(git_reference **resolved_ref, git_reference *ref) ...@@ -1489,16 +1489,15 @@ int git_reference_resolve(git_reference **resolved_ref, git_reference *ref)
*resolved_ref = ref; *resolved_ref = ref;
if (ref->type & GIT_REF_OID) { if (ref->type & GIT_REF_OID)
return GIT_SUCCESS; return GIT_SUCCESS;
}
ref_sym = (reference_symbolic *)ref; ref_sym = (reference_symbolic *)ref;
if ((error = git_reference_lookup(&ref, repo, ref_sym->target)) < GIT_SUCCESS) if ((error = git_reference_lookup(&ref, repo, ref_sym->target)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to resolve reference"); return error;
} }
return git__throw(GIT_ETOONESTEDSYMREF, "Failed to resolve reference. Reference is too nested"); return git__throw(GIT_ENOMEM, "Failed to resolve reference. Reference is too nested");
} }
int git_reference_packall(git_repository *repo) int git_reference_packall(git_repository *repo)
...@@ -1533,7 +1532,7 @@ int git_reference_listcb(git_repository *repo, unsigned int list_flags, int (*ca ...@@ -1533,7 +1532,7 @@ int git_reference_listcb(git_repository *repo, unsigned int list_flags, int (*ca
GIT_HASHTABLE_FOREACH(repo->references.packfile, ref_name, _unused, GIT_HASHTABLE_FOREACH(repo->references.packfile, ref_name, _unused,
if ((error = callback(ref_name, payload)) < GIT_SUCCESS) if ((error = callback(ref_name, payload)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to list references"); return git__throw(error, "Failed to list references. User callback failed");
); );
} }
...@@ -1573,7 +1572,7 @@ int git_reference_listall(git_strarray *array, git_repository *repo, unsigned in ...@@ -1573,7 +1572,7 @@ int git_reference_listall(git_strarray *array, git_repository *repo, unsigned in
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
git_vector_free(&ref_list); git_vector_free(&ref_list);
return git__rethrow(error, "Failed to list references"); return error;
} }
array->strings = (char **)ref_list.contents; array->strings = (char **)ref_list.contents;
...@@ -1632,7 +1631,7 @@ void git_repository__refcache_free(git_refcache *refs) ...@@ -1632,7 +1631,7 @@ void git_repository__refcache_free(git_refcache *refs)
static int check_valid_ref_char(char ch) static int check_valid_ref_char(char ch)
{ {
if (ch <= ' ') if (ch <= ' ')
return git__throw(GIT_ERROR, "Not a valid reference char"); return GIT_ERROR;
switch (ch) { switch (ch) {
case '~': case '~':
...@@ -1642,7 +1641,7 @@ static int check_valid_ref_char(char ch) ...@@ -1642,7 +1641,7 @@ static int check_valid_ref_char(char ch)
case '?': case '?':
case '[': case '[':
case '*': case '*':
return git__throw(GIT_ERROR, "Not a valid reference char"); return GIT_ERROR;
break; break;
default: default:
...@@ -1652,7 +1651,6 @@ static int check_valid_ref_char(char ch) ...@@ -1652,7 +1651,6 @@ static int check_valid_ref_char(char ch)
static int normalize_name(char *buffer_out, const char *name, int is_oid_ref) static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)
{ {
int error = GIT_SUCCESS;
const char *name_end, *buffer_out_start; const char *name_end, *buffer_out_start;
char *current; char *current;
int contains_a_slash = 0; int contains_a_slash = 0;
...@@ -1673,7 +1671,7 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref) ...@@ -1673,7 +1671,7 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)
while (current < name_end) { while (current < name_end) {
if (check_valid_ref_char(*current)) if (check_valid_ref_char(*current))
return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains invalid characters"); return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains invalid characters");
if (buffer_out > buffer_out_start) { if (buffer_out > buffer_out_start) {
char prev = *(buffer_out - 1); char prev = *(buffer_out - 1);
...@@ -1703,11 +1701,11 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref) ...@@ -1703,11 +1701,11 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)
* for HEAD in a detached state or MERGE_HEAD if we're in the * for HEAD in a detached state or MERGE_HEAD if we're in the
* middle of a merge */ * middle of a merge */
if (is_oid_ref && !contains_a_slash && (strcmp(name, GIT_HEAD_FILE) && strcmp(name, GIT_MERGE_HEAD_FILE))) if (is_oid_ref && !contains_a_slash && (strcmp(name, GIT_HEAD_FILE) && strcmp(name, GIT_MERGE_HEAD_FILE)))
return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains no slashes"); return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains no slashes");
/* A refname can not end with ".lock" */ /* A refname can not end with ".lock" */
if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION)) if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION))
return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name ends with '.lock'"); return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name ends with '.lock'");
*buffer_out = '\0'; *buffer_out = '\0';
...@@ -1715,12 +1713,11 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref) ...@@ -1715,12 +1713,11 @@ static int normalize_name(char *buffer_out, const char *name, int is_oid_ref)
* For object id references, name has to start with refs/. Again, * For object id references, name has to start with refs/. Again,
* we need to allow HEAD to be in a detached state. * we need to allow HEAD to be in a detached state.
*/ */
if (is_oid_ref && if (is_oid_ref && !(git__prefixcmp(buffer_out_start, GIT_REFS_DIR) ||
!(git__prefixcmp(buffer_out_start, GIT_REFS_DIR) || strcmp(buffer_out_start, GIT_HEAD_FILE)))
strcmp(buffer_out_start, GIT_HEAD_FILE)))
return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name does not start with 'refs/'"); return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name does not start with 'refs/'");
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to normalize name"); return GIT_SUCCESS;
} }
int git_reference__normalize_name(char *buffer_out, const char *name) int git_reference__normalize_name(char *buffer_out, const char *name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment