Skip to content

Commit

Permalink
tools: warn about duplicates when generating AUTHORS file
Browse files Browse the repository at this point in the history
PR-URL: #40304
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
  • Loading branch information
Trott committed Oct 9, 2021
1 parent 0d50dfd commit d6d6b05
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tools/update-authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CaseIndifferentMap {
_map = new Map();

get(key) { return this._map.get(key.toLowerCase()); }
has(key) { return this._map.has(key.toLowerCase()); }
set(key, value) { return this._map.set(key.toLowerCase(), value); }
}

Expand Down Expand Up @@ -64,6 +65,30 @@ const mailmap = new CaseIndifferentMap();
}
}

const previousAuthors = new CaseIndifferentMap();
{
const lines = fs.readFileSync(path.resolve(__dirname, '../', 'AUTHORS'),
{ encoding: 'utf8' }).split('\n');
for (let line of lines) {
line = line.trim();
if (line.startsWith('#') || line === '') continue;

let match;
if (match = line.match(/^([^<]+)\s+(<[^>]+>)$/)) {
const name = match[1];
const email = match[2];
if (previousAuthors.has(name)) {
const emails = previousAuthors.get(name);
emails.push(email);
} else {
previousAuthors.set(name, [email]);
}
} else {
console.warn('Unknown AUTHORS format:', line);
}
}
}

const seen = new Set();

// Support regular git author metadata, as well as `Author:` and
Expand Down Expand Up @@ -93,6 +118,11 @@ rl.on('line', (line) => {

seen.add(email);
output.write(`${author} ${email}\n`);
const duplicate = previousAuthors.get(author);
if (duplicate && !duplicate.includes(email)) {
console.warn('Author name already in AUTHORS file. Possible duplicate:');
console.warn(` ${author} <${email}>`);
}
});

rl.on('close', () => {
Expand Down

0 comments on commit d6d6b05

Please sign in to comment.