Skip to content

Commit 1e60e1d

Browse files
committed
Merge branch 'sa/multi-mailmap-fix'
When asking to apply mailmap to both author and committer field while showing a commit object, the field that appears later was not correctly parsed and replaced, which has been corrected. * sa/multi-mailmap-fix: cat-file: fix mailmap application for different author and committer
2 parents 1f08250 + abf94a2 commit 1e60e1d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ident.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ void apply_mailmap_to_header(struct strbuf *buf, const char **header,
412412
found_header = 1;
413413
buf_offset += endp - line;
414414
buf_offset += rewrite_ident_line(person, endp - person, buf, mailmap);
415+
/* Recompute endp after potential buffer reallocation */
416+
endp = buf->buf + buf_offset;
417+
if (*endp == '\n')
418+
buf_offset++;
415419
break;
416420
}
417421

t/t4203-mailmap.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,4 +1133,37 @@ test_expect_success 'git cat-file --batch-command returns correct size with --us
11331133
test_cmp expect actual
11341134
'
11351135

1136+
test_expect_success 'git cat-file --mailmap works with different author and committer' '
1137+
test_when_finished "rm .mailmap" &&
1138+
cat >.mailmap <<-\EOF &&
1139+
Mailmapped User <[email protected]> C O Mitter <[email protected]>
1140+
EOF
1141+
git commit --allow-empty -m "different author/committer" \
1142+
--author="Different Author <[email protected]>" &&
1143+
cat >expect <<-\EOF &&
1144+
author Different Author <[email protected]>
1145+
committer Mailmapped User <[email protected]>
1146+
EOF
1147+
git cat-file --mailmap commit HEAD >log &&
1148+
sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
1149+
test_cmp expect actual
1150+
'
1151+
1152+
test_expect_success 'git cat-file --mailmap maps both author and committer when both need mapping' '
1153+
test_when_finished "rm .mailmap" &&
1154+
cat >.mailmap <<-\EOF &&
1155+
1156+
Mapped Committer <[email protected]> C O Mitter <[email protected]>
1157+
EOF
1158+
git commit --allow-empty -m "both author and committer mapped" \
1159+
--author="Different Author <[email protected]>" &&
1160+
cat >expect <<-\EOF &&
1161+
author Mapped Author <[email protected]>
1162+
committer Mapped Committer <[email protected]>
1163+
EOF
1164+
git cat-file --mailmap commit HEAD >log &&
1165+
sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
1166+
test_cmp expect actual
1167+
'
1168+
11361169
test_done

0 commit comments

Comments
 (0)