|
8 | 8 | """ |
9 | 9 | import re |
10 | 10 | from collections import deque as Deque |
11 | | -from git.actor import Actor |
12 | 11 | import platform |
13 | 12 |
|
14 | 13 | from string import digits |
|
19 | 18 | 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz', |
20 | 19 | 'verify_utctz') |
21 | 20 |
|
| 21 | +#{ Functions |
| 22 | + |
22 | 23 | def get_object_type_by_name(object_type_name): |
23 | 24 | """ |
24 | 25 | Returns |
@@ -180,6 +181,60 @@ def parse_actor_and_date(line): |
180 | 181 | actor, epoch, offset = m.groups() |
181 | 182 | return (Actor._from_string(actor), int(epoch), utctz_to_altz(offset)) |
182 | 183 |
|
| 184 | + |
| 185 | +#} END functions |
| 186 | + |
| 187 | + |
| 188 | +#{ Classes |
| 189 | + |
| 190 | +class Actor(object): |
| 191 | + """Actors hold information about a person acting on the repository. They |
| 192 | + can be committers and authors or anything with a name and an email as |
| 193 | + mentioned in the git log entries.""" |
| 194 | + # precompiled regex |
| 195 | + name_only_regex = re.compile( r'<(.+)>' ) |
| 196 | + name_email_regex = re.compile( r'(.*) <(.+?)>' ) |
| 197 | + |
| 198 | + def __init__(self, name, email): |
| 199 | + self.name = name |
| 200 | + self.email = email |
| 201 | + |
| 202 | + def __eq__(self, other): |
| 203 | + return self.name == other.name and self.email == other.email |
| 204 | + |
| 205 | + def __ne__(self, other): |
| 206 | + return not (self == other) |
| 207 | + |
| 208 | + def __hash__(self): |
| 209 | + return hash((self.name, self.email)) |
| 210 | + |
| 211 | + def __str__(self): |
| 212 | + return self.name |
| 213 | + |
| 214 | + def __repr__(self): |
| 215 | + return '<git.Actor "%s <%s>">' % (self.name, self.email) |
| 216 | + |
| 217 | + @classmethod |
| 218 | + def _from_string(cls, string): |
| 219 | + """Create an Actor from a string. |
| 220 | + :param string: is the string, which is expected to be in regular git format |
| 221 | +
|
| 222 | + John Doe <jdoe@example.com> |
| 223 | + |
| 224 | + :return: Actor """ |
| 225 | + m = cls.name_email_regex.search(string) |
| 226 | + if m: |
| 227 | + name, email = m.groups() |
| 228 | + return Actor(name, email) |
| 229 | + else: |
| 230 | + m = cls.name_only_regex.search(string) |
| 231 | + if m: |
| 232 | + return Actor(m.group(1), None) |
| 233 | + else: |
| 234 | + # assume best and use the whole string as name |
| 235 | + return Actor(string, None) |
| 236 | + # END special case name |
| 237 | + # END handle name/email matching |
183 | 238 |
|
184 | 239 |
|
185 | 240 | class ProcessStreamAdapter(object): |
|
0 commit comments