Skip to content

Commit 55b8304

Browse files
addaleaxBridgeAR
authored andcommitted
tools: add mailmap support for Co-authored-by tags
Support `.mailmap` for manually added `Author:` and `Co-authored-by:` tags. PR-URL: #26383 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent dc2119a commit 55b8304

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

Diff for: tools/update-authors.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
44
'use strict';
55
const { spawn } = require('child_process');
6+
const path = require('path');
67
const fs = require('fs');
78
const readline = require('readline');
89

@@ -22,6 +23,38 @@ else
2223

2324
output.write('# Authors ordered by first contribution.\n\n');
2425

26+
const mailmap = new Map();
27+
{
28+
const lines = fs.readFileSync(path.resolve(__dirname, '../', '.mailmap'),
29+
{ encoding: 'utf8' }).split('\n');
30+
for (let line of lines) {
31+
line = line.trim();
32+
if (line.startsWith('#') || line === '') continue;
33+
34+
let match;
35+
// Replaced Name <[email protected]>
36+
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
37+
mailmap.set(match[2], { author: match[1] });
38+
39+
} else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) {
40+
mailmap.set(match[2], { email: match[1] });
41+
42+
} else if (match = line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)) {
43+
mailmap.set(match[3], {
44+
author: match[1], email: match[2]
45+
});
46+
// Replaced Name <[email protected]> Original Name <[email protected]>
47+
} else if (match =
48+
line.match(/^([^<]+)\s+(<[^>]+>)\s+([^<]+)\s+(<[^>]+>)$/)) {
49+
mailmap.set(match[3] + '\0' + match[4], {
50+
author: match[1], email: match[2]
51+
});
52+
} else {
53+
console.warn('Unknown .mailmap format:', line);
54+
}
55+
}
56+
}
57+
2558
const seen = new Set();
2659

2760
// Support regular git author metadata, as well as `Author:` and
@@ -34,7 +67,13 @@ rl.on('line', (line) => {
3467
const match = line.match(authorRe);
3568
if (!match) return;
3669

37-
const { author, email } = match.groups;
70+
let { author, email } = match.groups;
71+
72+
const replacement = mailmap.get(author + '\0' + email) || mailmap.get(email);
73+
if (replacement) {
74+
({ author, email } = { author, email, ...replacement });
75+
}
76+
3877
if (seen.has(email) ||
3978
/@chromium\.org/.test(email) ||
4079
email === '<[email protected]>') {

0 commit comments

Comments
 (0)