Skip to content

Commit f98131b

Browse files
committed
Require the length argument to git_mailmap_from_buffer and make mailmap_add_buffer internal
1 parent 9faf36a commit f98131b

File tree

4 files changed

+9
-27
lines changed

4 files changed

+9
-27
lines changed

include/git2/mailmap.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,12 @@ GIT_EXTERN(int) git_mailmap_add_entry(
5353
git_mailmap *mm, const char *real_name, const char *real_email,
5454
const char *replace_name, const char *replace_email);
5555

56-
/**
57-
* Parse mailmap entries from a buffer.
58-
*
59-
* @param mm mailmap to add the entries to
60-
* @param buf the buffer to read the mailmap file from
61-
* @param len the length of the input buffer [optional: 0 defaults to 'strlen']
62-
* @return 0 on success, or an error code
63-
*/
64-
GIT_EXTERN(int) git_mailmap_add_buffer(
65-
git_mailmap *mm, const char *buf, size_t len);
66-
6756
/**
6857
* Create a new mailmap instance containing a single mailmap file
6958
*
70-
* This method is a simple utility wrapper for the following sequence
71-
* of calls:
72-
* - git_mailmap_new
73-
* - git_mailmap_add_buffer
74-
*
7559
* @param out pointer to store the new mailmap
7660
* @param buf buffer to parse the mailmap from
77-
* @param len the length of the input buffer [optional: 0 defaults to 'strlen']
61+
* @param len the length of the input buffer
7862
* @return 0 on success, or an error code
7963
*/
8064
GIT_EXTERN(int) git_mailmap_from_buffer(

src/mailmap.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int git_mailmap_add_entry(
223223
replace_email, strlen(replace_email));
224224
}
225225

226-
int git_mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
226+
static int mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
227227
{
228228
int error;
229229
git_parse_ctx ctx;
@@ -234,10 +234,6 @@ int git_mailmap_add_buffer(git_mailmap *mm, const char *buf, size_t len)
234234
git_buf replace_name = GIT_BUF_INIT;
235235
git_buf replace_email = GIT_BUF_INIT;
236236

237-
/* If `len` is passed as 0, use strlen to get the real length */
238-
if (buf && len == 0)
239-
len = strlen(buf);
240-
241237
/* Buffers may not contain '\0's. */
242238
if (memchr(buf, '\0', len) != NULL)
243239
return -1;
@@ -278,7 +274,7 @@ int git_mailmap_from_buffer(git_mailmap **out, const char *data, size_t len)
278274
if (error < 0)
279275
return error;
280276

281-
error = git_mailmap_add_buffer(*out, data, len);
277+
error = mailmap_add_buffer(*out, data, len);
282278
if (error < 0) {
283279
git_mailmap_free(*out);
284280
*out = NULL;
@@ -308,7 +304,7 @@ static int mailmap_add_blob(
308304
if (error < 0)
309305
goto cleanup;
310306

311-
error = git_mailmap_add_buffer(mm, content.ptr, content.size);
307+
error = mailmap_add_buffer(mm, content.ptr, content.size);
312308
if (error < 0)
313309
goto cleanup;
314310

@@ -335,7 +331,7 @@ static int mailmap_add_file_ondisk(
335331
if (error < 0)
336332
goto cleanup;
337333

338-
error = git_mailmap_add_buffer(mm, content.ptr, content.size);
334+
error = mailmap_add_buffer(mm, content.ptr, content.size);
339335
if (error < 0)
340336
goto cleanup;
341337

tests/mailmap/basic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct {
2727

2828
void test_mailmap_basic__initialize(void)
2929
{
30-
cl_git_pass(git_mailmap_from_buffer(&mailmap, TEST_MAILMAP, 0));
30+
cl_git_pass(git_mailmap_from_buffer(
31+
&mailmap, TEST_MAILMAP, strlen(TEST_MAILMAP)));
3132
}
3233

3334
void test_mailmap_basic__cleanup(void)

tests/mailmap/parsing.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ static const mailmap_entry resolved_untracked[] = {
6767

6868
void test_mailmap_parsing__string(void)
6969
{
70-
cl_git_pass(git_mailmap_from_buffer(&g_mailmap, string_mailmap, 0));
70+
cl_git_pass(git_mailmap_from_buffer(
71+
&g_mailmap, string_mailmap, strlen(string_mailmap)));
7172

7273
/* We should have parsed all of the entries */
7374
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));

0 commit comments

Comments
 (0)