Skip to content

Commit

Permalink
Merge branch 'jk/mailmap-incomplete-line'
Browse files Browse the repository at this point in the history
* jk/mailmap-incomplete-line:
  mailmap: handle mailmap blobs without trailing newlines
  • Loading branch information
Junio C Hamano committed Sep 9, 2013
2 parents a23274e + f972a16 commit af226bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
21 changes: 9 additions & 12 deletions mailmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,17 @@ static int read_mailmap_file(struct string_list *map, const char *filename,
return 0;
}

static void read_mailmap_buf(struct string_list *map,
const char *buf, unsigned long len,
char **repo_abbrev)
static void read_mailmap_string(struct string_list *map, char *buf,
char **repo_abbrev)
{
while (len) {
const char *end = strchrnul(buf, '\n');
unsigned long linelen = end - buf + 1;
char *line = xmemdupz(buf, linelen);
while (*buf) {
char *end = strchrnul(buf, '\n');

read_mailmap_line(map, line, repo_abbrev);
if (*end)
*end++ = '\0';

free(line);
buf += linelen;
len -= linelen;
read_mailmap_line(map, buf, repo_abbrev);
buf = end;
}
}

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

read_mailmap_buf(map, buf, size, repo_abbrev);
read_mailmap_string(map, buf, repo_abbrev);

free(buf);
return 0;
Expand Down
16 changes: 15 additions & 1 deletion t/t4203-mailmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ test_expect_success 'setup mailmap blob tests' '
Blob Guy <author@example.com>
Blob Guy <bugs@company.xx>
EOF
git add just-bugs both &&
printf "Tricky Guy <author@example.com>" >no-newline &&
git add just-bugs both no-newline &&
git commit -m "my mailmaps" &&
echo "Repo Guy <author@example.com>" >.mailmap &&
echo "Internal Guy <author@example.com>" >internal.map
Expand Down Expand Up @@ -286,6 +287,19 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
)
'

test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
cat >expect <<-\EOF &&
Tricky Guy (1):
initial
nick1 (1):
second
EOF
git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
test_cmp expect actual
'

test_expect_success 'cleanup after mailmap.blob tests' '
rm -f .mailmap
'
Expand Down

0 comments on commit af226bf

Please sign in to comment.