9
9
import collections
10
10
11
11
12
- MANUAL_EDIT_WARNING = \
13
- """
14
- This file is generated using the %s script. DO NOT MANUALLY EDIT!!!!
12
+ MANUAL_EDIT_WARNING = """This file is generated using the %s script. DO NOT MANUALLY EDIT!!!!
15
13
Last Modified: %s
16
14
""" % (os .path .basename (__file__ ), datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M" ))
17
15
68
66
}
69
67
70
68
71
- def _get_contributions_by_email (output ):
69
+ def _get_contributions_by_canonical_email (output ):
72
70
contributions_by_email = collections .defaultdict (list )
73
71
for line in output .split ("\n " ):
74
- match = re .match (r"[\s]*([0-9]+)[ \s+] (.+)[\s] +\<(.+)\>" , line )
72
+ match = re .match (r"[\s]*([0-9]+)\s+(.+)\s +\<(.+)\>" , line )
75
73
if match is None :
76
74
continue
77
75
78
- commits , name , email = match .groups ()
76
+ commits_count , author_name , email = match .groups ()
79
77
80
- if email in email_mappings :
81
- email = email_mappings [email ]
78
+ canonical_email = email_mappings .get (email , email )
82
79
83
- if email == "" :
80
+ if canonical_email == "" :
84
81
continue # ignored
85
82
86
- contributions_by_email [email ].append ((int (commits ), name ))
83
+ contributions_by_email [canonical_email ].append ((int (commits_count ), author_name ))
87
84
return contributions_by_email
88
85
89
86
@@ -94,23 +91,21 @@ def _get_name_used_most_in_contributions(contribution_sets):
94
91
95
92
def _get_contributor_email_mapping (contributions_by_email ):
96
93
contributors = {}
97
- # We will use the most used full name
98
94
for email in contributions_by_email :
99
95
name_used_most = _get_name_used_most_in_contributions (contributions_by_email [email ])
100
- if name_used_most in name_mappings :
101
- name_used_most = name_mappings [name_used_most ]
96
+ canonical_name_used_most = name_mappings .get (name_used_most , name_used_most )
102
97
103
- contributors [name_used_most ] = email
98
+ contributors [canonical_name_used_most ] = email
104
99
return contributors
105
100
106
101
107
102
def _names_sorted_by_last_name (names ):
108
- return sorted (names , key = lambda x : x .split (" " )[ - 1 ]. upper () )
103
+ return sorted (names , key = lambda x : tuple ( n . upper () for n in x .split (" " ))[:: - 1 ])
109
104
110
105
111
106
def main ():
112
107
output = subprocess .check_output (["git" , "shortlog" , "-se" ]).decode ("utf-8" )
113
- contributions_by_email = _get_contributions_by_email (output )
108
+ contributions_by_email = _get_contributions_by_canonical_email (output )
114
109
contributors = _get_contributor_email_mapping (contributions_by_email )
115
110
116
111
contributors_md = "<!---%s--->\n \n " % MANUAL_EDIT_WARNING
0 commit comments