diff --git a/ident.c b/ident.c index 967895d885033da5393a9c0c0c52d51531a64867..281e830573b74d3194f62436b15f1d1d8a33056a 100644 --- a/ident.c +++ b/ident.c @@ -412,6 +412,10 @@ void apply_mailmap_to_header(struct strbuf *buf, const char **header, found_header = 1; buf_offset += endp - line; buf_offset += rewrite_ident_line(person, endp - person, buf, mailmap); + /* Recompute endp after potential buffer reallocation */ + endp = buf->buf + buf_offset; + if (*endp == '\n') + buf_offset++; break; } diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 4a6242ff99b59ea1a46eb14ca812c94e5e620162..98dd0ae12f7da50a81f472f005b4daf5bf79e662 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -1133,4 +1133,37 @@ test_expect_success 'git cat-file --batch-command returns correct size with --us test_cmp expect actual ' +test_expect_success 'git cat-file --mailmap works with different author and committer' ' + test_when_finished "rm .mailmap" && + cat >.mailmap <<-\EOF && + Mailmapped User C O Mitter + EOF + git commit --allow-empty -m "different author/committer" \ + --author="Different Author " && + cat >expect <<-\EOF && + author Different Author + committer Mailmapped User + EOF + git cat-file --mailmap commit HEAD >log && + sed -n "/^author /s/\([^>]*>\).*/\1/p; /^committer /s/\([^>]*>\).*/\1/p" log >actual && + test_cmp expect actual +' + +test_expect_success 'git cat-file --mailmap maps both author and committer when both need mapping' ' + test_when_finished "rm .mailmap" && + cat >.mailmap <<-\EOF && + Mapped Author + Mapped Committer C O Mitter + EOF + git commit --allow-empty -m "both author and committer mapped" \ + --author="Different Author " && + cat >expect <<-\EOF && + author Mapped Author + committer Mapped Committer + EOF + git cat-file --mailmap commit HEAD >log && + sed -n "/^author /s/\([^>]*>\).*/\1/p; /^committer /s/\([^>]*>\).*/\1/p" log >actual && + test_cmp expect actual +' + test_done