Skip to content

Commit 19230ab

Browse files
committed
Merge branch 'jk/mailmap-incomplete-line' into maint
* jk/mailmap-incomplete-line: mailmap: handle mailmap blobs without trailing newlines
2 parents d5b99f3 + f972a16 commit 19230ab

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

mailmap.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,17 @@ static int read_mailmap_file(struct string_list *map, const char *filename,
193193
return 0;
194194
}
195195

196-
static void read_mailmap_buf(struct string_list *map,
197-
const char *buf, unsigned long len,
198-
char **repo_abbrev)
196+
static void read_mailmap_string(struct string_list *map, char *buf,
197+
char **repo_abbrev)
199198
{
200-
while (len) {
201-
const char *end = strchrnul(buf, '\n');
202-
unsigned long linelen = end - buf + 1;
203-
char *line = xmemdupz(buf, linelen);
199+
while (*buf) {
200+
char *end = strchrnul(buf, '\n');
204201

205-
read_mailmap_line(map, line, repo_abbrev);
202+
if (*end)
203+
*end++ = '\0';
206204

207-
free(line);
208-
buf += linelen;
209-
len -= linelen;
205+
read_mailmap_line(map, buf, repo_abbrev);
206+
buf = end;
210207
}
211208
}
212209

@@ -230,7 +227,7 @@ static int read_mailmap_blob(struct string_list *map,
230227
if (type != OBJ_BLOB)
231228
return error("mailmap is not a blob: %s", name);
232229

233-
read_mailmap_buf(map, buf, size, repo_abbrev);
230+
read_mailmap_string(map, buf, repo_abbrev);
234231

235232
free(buf);
236233
return 0;

t/t4203-mailmap.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ test_expect_success 'setup mailmap blob tests' '
202202
Blob Guy <[email protected]>
203203
Blob Guy <[email protected]>
204204
EOF
205-
git add just-bugs both &&
205+
printf "Tricky Guy <[email protected]>" >no-newline &&
206+
git add just-bugs both no-newline &&
206207
git commit -m "my mailmaps" &&
207208
echo "Repo Guy <[email protected]>" >.mailmap &&
208209
echo "Internal Guy <[email protected]>" >internal.map
@@ -286,6 +287,19 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
286287
)
287288
'
288289

290+
test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
291+
cat >expect <<-\EOF &&
292+
Tricky Guy (1):
293+
initial
294+
295+
nick1 (1):
296+
second
297+
298+
EOF
299+
git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
300+
test_cmp expect actual
301+
'
302+
289303
test_expect_success 'cleanup after mailmap.blob tests' '
290304
rm -f .mailmap
291305
'

0 commit comments

Comments
 (0)