diff --git a/tools/update-authors.js b/tools/update-authors.js index 1c48eaec85c823..3d7fcb14b2f461 100755 --- a/tools/update-authors.js +++ b/tools/update-authors.js @@ -3,6 +3,7 @@ // Passing --dry will redirect output to stdout rather than write to 'AUTHORS'. 'use strict'; const { spawn } = require('child_process'); +const path = require('path'); const fs = require('fs'); const readline = require('readline'); @@ -22,6 +23,38 @@ else output.write('# Authors ordered by first contribution.\n\n'); +const mailmap = new Map(); +{ + const lines = fs.readFileSync(path.resolve(__dirname, '../', '.mailmap'), + { encoding: 'utf8' }).split('\n'); + for (let line of lines) { + line = line.trim(); + if (line.startsWith('#') || line === '') continue; + + let match; + // Replaced Name + if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) { + mailmap.set(match[2], { author: match[1] }); + // + } else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) { + mailmap.set(match[2], { email: match[1] }); + // Replaced Name + } else if (match = line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)) { + mailmap.set(match[3], { + author: match[1], email: match[2] + }); + // Replaced Name Original Name + } else if (match = + line.match(/^([^<]+)\s+(<[^>]+>)\s+([^<]+)\s+(<[^>]+>)$/)) { + mailmap.set(match[3] + '\0' + match[4], { + author: match[1], email: match[2] + }); + } else { + console.warn('Unknown .mailmap format:', line); + } + } +} + const seen = new Set(); // Support regular git author metadata, as well as `Author:` and @@ -34,7 +67,13 @@ rl.on('line', (line) => { const match = line.match(authorRe); if (!match) return; - const { author, email } = match.groups; + let { author, email } = match.groups; + + const replacement = mailmap.get(author + '\0' + email) || mailmap.get(email); + if (replacement) { + ({ author, email } = { author, email, ...replacement }); + } + if (seen.has(email) || /@chromium\.org/.test(email) || email === '') {