mailmap: Hide EEXISTS to simplify git_mailmap_add_entry callers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/include/git2/mailmap.h b/include/git2/mailmap.h
index b22a00c..c6ed481 100644
--- a/include/git2/mailmap.h
+++ b/include/git2/mailmap.h
@@ -47,7 +47,7 @@ GIT_EXTERN(void) git_mailmap_free(git_mailmap *mm);
* @param real_email the real email to use, or NULL
* @param replace_name the name to replace, or NULL
* @param replace_email the email to replace
- * @return 0 if it was added, EEXISTS if it replaced an entry, or an error code
+ * @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_mailmap_add_entry(
git_mailmap *mm, const char *real_name, const char *real_email,
diff --git a/src/mailmap.c b/src/mailmap.c
index e4b924c..f249c52 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -203,7 +203,9 @@ static int mailmap_add_entry_unterminated(
GITERR_CHECK_ALLOC(entry->replace_email);
error = git_vector_insert_sorted(&mm->entries, entry, mailmap_entry_replace);
- if (error < 0 && error != GIT_EEXISTS)
+ if (error == GIT_EEXISTS)
+ error = GIT_OK;
+ else if (error < 0)
mailmap_entry_free(entry);
return error;
@@ -256,7 +258,7 @@ int git_mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
error = mailmap_add_entry_unterminated(
mm, real_name.ptr, real_name.size, real_email.ptr, real_email.size,
replace_name.ptr, replace_name.size, replace_email.ptr, replace_email.size);
- if (error < 0 && error != GIT_EEXISTS)
+ if (error < 0)
goto cleanup;
error = 0;