Require the length argument to git_mailmap_from_buffer and make mailmap_add_buffer internal
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
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));