Skip to content

Commit

Permalink
tools: add mailmap support for Co-authored-by tags
Browse files Browse the repository at this point in the history
Support `.mailmap` for manually added `Author:` and
`Co-authored-by:` tags.

PR-URL: #26383
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
addaleax authored and BridgeAR committed Mar 12, 2019
1 parent dc2119a commit 55b8304
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tools/update-authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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 <original@example.com>
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
mailmap.set(match[2], { author: match[1] });
// <replaced@example.com> <original@example.com>
} else if (match = line.match(/^<([^>]+)>\s+(<[^>]+>)$/)) {
mailmap.set(match[2], { email: match[1] });
// Replaced Name <replaced@example.com> <original@example.com>
} else if (match = line.match(/^([^<]+)\s+(<[^>]+>)\s+(<[^>]+>)$/)) {
mailmap.set(match[3], {
author: match[1], email: match[2]
});
// Replaced Name <replaced@example.com> Original Name <original@example.com>
} 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
Expand All @@ -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 === '<erik.corry@gmail.com>') {
Expand Down

0 comments on commit 55b8304

Please sign in to comment.