Commit d91d2968a662ee2b2120c3b44aa6956d9ac57b89

Nika Layzell 2018-06-14T16:49:48

mailmap: Hide EEXISTS to simplify git_mailmap_add_entry callers

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;