Show More
@@ -166,6 +166,30 b' class mailmapping(object):' | |||||
166 | email = attr.ib() |
|
166 | email = attr.ib() | |
167 | name = attr.ib(default=None) |
|
167 | name = attr.ib(default=None) | |
168 |
|
168 | |||
|
169 | def _ismailmaplineinvalid(names, emails): | |||
|
170 | '''Returns True if the parsed names and emails | |||
|
171 | in a mailmap entry are invalid. | |||
|
172 | ||||
|
173 | >>> # No names or emails fails | |||
|
174 | >>> names, emails = [], [] | |||
|
175 | >>> _ismailmaplineinvalid(names, emails) | |||
|
176 | True | |||
|
177 | >>> # Only one email fails | |||
|
178 | >>> emails = [b'email@email.com'] | |||
|
179 | >>> _ismailmaplineinvalid(names, emails) | |||
|
180 | True | |||
|
181 | >>> # One email and one name passes | |||
|
182 | >>> names = [b'Test Name'] | |||
|
183 | >>> _ismailmaplineinvalid(names, emails) | |||
|
184 | False | |||
|
185 | >>> # No names but two emails passes | |||
|
186 | >>> names = [] | |||
|
187 | >>> emails = [b'proper@email.com', b'commit@email.com'] | |||
|
188 | >>> _ismailmaplineinvalid(names, emails) | |||
|
189 | False | |||
|
190 | ''' | |||
|
191 | return not emails or not names and len(emails) < 2 | |||
|
192 | ||||
169 | def parsemailmap(mailmapcontent): |
|
193 | def parsemailmap(mailmapcontent): | |
170 | """Parses data in the .mailmap format |
|
194 | """Parses data in the .mailmap format | |
171 |
|
195 | |||
@@ -199,7 +223,7 b' def parsemailmap(mailmapcontent):' | |||||
199 |
|
223 | |||
200 | # Don't bother checking the line if it is a comment or |
|
224 | # Don't bother checking the line if it is a comment or | |
201 | # is an improperly formed author field |
|
225 | # is an improperly formed author field | |
202 |
if line.lstrip().startswith('#') |
|
226 | if line.lstrip().startswith('#'): | |
203 | continue |
|
227 | continue | |
204 |
|
228 | |||
205 | # names, emails hold the parsed emails and names for each line |
|
229 | # names, emails hold the parsed emails and names for each line | |
@@ -230,6 +254,12 b' def parsemailmap(mailmapcontent):' | |||||
230 | # We have found another word in the committers name |
|
254 | # We have found another word in the committers name | |
231 | namebuilder.append(element) |
|
255 | namebuilder.append(element) | |
232 |
|
256 | |||
|
257 | # Check to see if we have parsed the line into a valid form | |||
|
258 | # We require at least one email, and either at least one | |||
|
259 | # name or a second email | |||
|
260 | if _ismailmaplineinvalid(names, emails): | |||
|
261 | continue | |||
|
262 | ||||
233 | mailmapkey = mailmapping( |
|
263 | mailmapkey = mailmapping( | |
234 | email=emails[-1], |
|
264 | email=emails[-1], | |
235 | name=names[-1] if len(names) == 2 else None, |
|
265 | name=names[-1] if len(names) == 2 else None, |
General Comments 0
You need to be logged in to leave comments.
Login now