1#!/usr/bin/env python3
2
3# script to extract commit author's name from standard input.  The
4# input should be <AUTHOR>:<EMAIL>, one per line.
5# This script expects the input is created by git-log command:
6#
7#   git log --format=%aN:%aE
8#
9# This script removes duplicates based on email address, breaking a
10# tie with longer author name.  Among the all author names extract the
11# previous step, we remove duplicate by case-insensitive match.
12#
13# So we can do this in one line:
14#
15#   git log --format=%aN:%aE | sort | uniq | ./author.py > authors
16
17import sys
18
19edict = {}
20
21for line in sys.stdin:
22    author, email = line.strip().split(':', 1)
23    if email in edict:
24        an = edict[email]
25        if len(an) < len(author) or an > author:
26            sys.stderr.write(
27                'eliminated {} in favor of {}\n'.format(an, author))
28            edict[email] = author
29        else:
30            sys.stderr.write(
31                'eliminated {} in favor of {}\n'.format(author, an))
32    else:
33        edict[email] = author
34
35names = list(sorted(edict.values()))
36
37ndict = {}
38
39for name in names:
40    lowname = name.lower()
41    if lowname in ndict:
42        an = ndict[lowname]
43        if an > name:
44            sys.stderr.write('eliminated {} in favor of {}\n'.format(an, name))
45            ndict[lowname] = name
46        else:
47            sys.stderr.write('eliminated {} in favor of {}\n'.format(name, an))
48    else:
49        ndict[lowname] = name
50
51for name in sorted(ndict.values()):
52    print(name)
53