Commit f98131be911df5e4c47e51ac92e6e7de79e30219

Nika Layzell 2018-06-17T00:40:25

Require the length argument to git_mailmap_from_buffer and make mailmap_add_buffer internal

diff --git a/include/git2/mailmap.h b/include/git2/mailmap.h
index c6ed481..7c3f60f 100644
--- a/include/git2/mailmap.h
+++ b/include/git2/mailmap.h
@@ -54,27 +54,11 @@ GIT_EXTERN(int) git_mailmap_add_entry(
 	const char *replace_name, const char *replace_email);
 
 /**
- * Parse mailmap entries from a buffer.
- *
- * @param mm mailmap to add the entries to
- * @param buf the buffer to read the mailmap file from
- * @param len the length of the input buffer [optional: 0 defaults to 'strlen']
- * @return 0 on success, or an error code
- */
-GIT_EXTERN(int) git_mailmap_add_buffer(
-	git_mailmap *mm, const char *buf, size_t len);
-
-/**
  * Create a new mailmap instance containing a single mailmap file
  *
- * This method is a simple utility wrapper for the following sequence
- * of calls:
- *  - git_mailmap_new
- *  - git_mailmap_add_buffer
- *
  * @param out pointer to store the new mailmap
  * @param buf buffer to parse the mailmap from
- * @param len the length of the input buffer [optional: 0 defaults to 'strlen']
+ * @param len the length of the input buffer
  * @return 0 on success, or an error code
  */
 GIT_EXTERN(int) git_mailmap_from_buffer(
diff --git a/src/mailmap.c b/src/mailmap.c
index b5fb7f6..fe4d452 100644
--- a/src/mailmap.c
+++ b/src/mailmap.c
@@ -223,7 +223,7 @@ int git_mailmap_add_entry(
 		replace_email, strlen(replace_email));
 }
 
-int git_mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
+static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
 {
 	int error;
 	git_parse_ctx ctx;
@@ -234,10 +234,6 @@ int git_mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
 	git_buf replace_name = GIT_BUF_INIT;
 	git_buf replace_email = GIT_BUF_INIT;
 
-	/* If `len` is passed as 0, use strlen to get the real length */
-	if (buf && len == 0)
-		len = strlen(buf);
-
 	/* Buffers may not contain '\0's. */
 	if (memchr(buf, '\0', len) != NULL)
 		return -1;
@@ -278,7 +274,7 @@ int git_mailmap_from_buffer(git_mailmap **out, const char *data, size_t len)
 	if (error < 0)
 		return error;
 
-	error = git_mailmap_add_buffer(*out, data, len);
+	error = mailmap_add_buffer(*out, data, len);
 	if (error < 0) {
 		git_mailmap_free(*out);
 		*out = NULL;
@@ -308,7 +304,7 @@ static int mailmap_add_blob(
 	if (error < 0)
 		goto cleanup;
 
-	error = git_mailmap_add_buffer(mm, content.ptr, content.size);
+	error = mailmap_add_buffer(mm, content.ptr, content.size);
 	if (error < 0)
 		goto cleanup;
 
@@ -335,7 +331,7 @@ static int mailmap_add_file_ondisk(
 	if (error < 0)
 		goto cleanup;
 
-	error = git_mailmap_add_buffer(mm, content.ptr, content.size);
+	error = mailmap_add_buffer(mm, content.ptr, content.size);
 	if (error < 0)
 		goto cleanup;
 
diff --git a/tests/mailmap/basic.c b/tests/mailmap/basic.c
index 20fa8be..1f8ca56 100644
--- a/tests/mailmap/basic.c
+++ b/tests/mailmap/basic.c
@@ -27,7 +27,8 @@ struct {
 
 void test_mailmap_basic__initialize(void)
 {
-	cl_git_pass(git_mailmap_from_buffer(&mailmap, TEST_MAILMAP, 0));
+	cl_git_pass(git_mailmap_from_buffer(
+		&mailmap, TEST_MAILMAP, strlen(TEST_MAILMAP)));
 }
 
 void test_mailmap_basic__cleanup(void)
diff --git a/tests/mailmap/parsing.c b/tests/mailmap/parsing.c
index d3efe40..4479e41 100644
--- a/tests/mailmap/parsing.c
+++ b/tests/mailmap/parsing.c
@@ -67,7 +67,8 @@ static const mailmap_entry resolved_untracked[] = {
 
 void test_mailmap_parsing__string(void)
 {
-	cl_git_pass(git_mailmap_from_buffer(&g_mailmap, string_mailmap, 0));
+	cl_git_pass(git_mailmap_from_buffer(
+		&g_mailmap, string_mailmap, strlen(string_mailmap)));
 
 	/* We should have parsed all of the entries */
 	check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));