Commit 23e38fd378f747c6c9ff4ce54123857812e6dfcd

Edward Thomson 2020-04-05T17:02:17

mailmap: use GIT_ASSERT

diff --git a/src/mailmap.c b/src/mailmap.c
index 409cdbd..347b433 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -43,7 +43,8 @@ static int mailmap_entry_cmp(const void *a_raw, const void *b_raw)
 	const git_mailmap_entry *b = (const git_mailmap_entry *)b_raw;
 	int cmp;
 
-	assert(a && b && a->replace_email && b->replace_email);
+	GIT_ASSERT_ARG(a && a->replace_email);
+	GIT_ASSERT_ARG(b && b->replace_email);
 
 	cmp = git__strcmp(a->replace_email, b->replace_email);
 	if (cmp)
@@ -185,7 +186,8 @@ static int mailmap_add_entry_unterminated(
 	git_mailmap_entry *entry = git__calloc(1, sizeof(git_mailmap_entry));
 	GIT_ERROR_CHECK_ALLOC(entry);
 
-	assert(mm && replace_email && *replace_email);
+	GIT_ASSERT_ARG(mm);
+	GIT_ASSERT_ARG(replace_email && *replace_email);
 
 	if (real_name_size > 0) {
 		entry->real_name = git__substrdup(real_name, real_name_size);
@@ -290,7 +292,8 @@ static int mailmap_add_blob(
 	git_buf content = GIT_BUF_INIT;
 	int error;
 
-	assert(mm && repo);
+	GIT_ASSERT_ARG(mm);
+	GIT_ASSERT_ARG(repo);
 
 	error = git_revparse_single(&object, repo, rev);
 	if (error < 0)
@@ -350,8 +353,6 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
 	const char *rev = NULL;
 	const char *path = NULL;
 
-	assert(mm && repo);
-
 	/* If we're in a bare repo, default blob to 'HEAD:.mailmap' */
 	if (repo->is_bare)
 		rev = MM_BLOB_DEFAULT;
@@ -389,9 +390,14 @@ static void mailmap_add_from_repository(git_mailmap *mm, git_repository *repo)
 
 int git_mailmap_from_repository(git_mailmap **out, git_repository *repo)
 {
-	int error = git_mailmap_new(out);
-	if (error < 0)
+	int error;
+
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(repo);
+
+	if ((error = git_mailmap_new(out)) < 0)
 		return error;
+
 	mailmap_add_from_repository(*out, repo);
 	return 0;
 }
@@ -408,7 +414,7 @@ const git_mailmap_entry *git_mailmap_entry_lookup(
 	git_mailmap_entry needle = { NULL };
 	needle.replace_email = (char *)email;
 
-	assert(email);
+	GIT_ASSERT_ARG_WITH_RETVAL(email, NULL);
 
 	if (!mm)
 		return NULL;
@@ -431,7 +437,8 @@ const git_mailmap_entry *git_mailmap_entry_lookup(
 		if (git__strcmp(entry->replace_email, email))
 			break; /* it's a different email, so we're done looking */
 
-		assert(entry->replace_name); /* should be specific */
+		 /* should be specific */
+		GIT_ASSERT_WITH_RETVAL(entry->replace_name, NULL);
 		if (!name || !git__strcmp(entry->replace_name, name))
 			return entry;
 	}
@@ -447,7 +454,9 @@ int git_mailmap_resolve(
 	const char *name, const char *email)
 {
 	const git_mailmap_entry *entry = NULL;
-	assert(name && email);
+
+	GIT_ASSERT(name);
+	GIT_ASSERT(email);
 
 	*real_name = name;
 	*real_email = email;