Commit f98131be by Nika Layzell

Require the length argument to git_mailmap_from_buffer and make mailmap_add_buffer internal

parent 9faf36a6
......@@ -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(
......
......@@ -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;
......
......@@ -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)
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment