|
15 | 15 | from collections import OrderedDict |
16 | 16 | from datetime import datetime |
17 | 17 |
|
18 | | -EMAIL_RE = re.compile(r"^(\"?)(?P<name>.*)\1\s+<(?P<email>.*)>$") |
19 | | - |
20 | 18 | # see git-diff-tree 'RAW OUTPUT FORMAT' |
21 | 19 | # https://git-scm.com/docs/git-diff-tree#_raw_output_format |
22 | 20 | DIFF_TREE_RE = re.compile( |
@@ -96,14 +94,32 @@ def get_repo_description(): |
96 | 94 | return "" |
97 | 95 |
|
98 | 96 |
|
99 | | -def extract_name_email(s): |
100 | | - p = EMAIL_RE |
101 | | - _ = p.search(s.strip()) |
102 | | - if not _: |
103 | | - return (None, None) |
104 | | - name = (_.group("name") or "").strip() |
105 | | - email = (_.group("email") or "").strip() |
106 | | - return (name, email) |
| 97 | +_STRIP_QUOTED_NAME_RE = re.compile(r"^\s*([\"'])\s*(?P<value>.*?)\s*\1\s*$") |
| 98 | + |
| 99 | + |
| 100 | +def _strip_quoted_name(val): |
| 101 | + # I can't think of why it would come through with \' beyond presumably git CLI escaping, but |
| 102 | + # whatever, cover that base too. |
| 103 | + if m := _STRIP_QUOTED_NAME_RE.match(val): |
| 104 | + return m.groupdict()["value"] |
| 105 | + return val |
| 106 | + |
| 107 | + |
| 108 | +_EMAIL_RE = re.compile(r"\s*(?P<name>[^<]+?)\s*<\s*(?P<email>[^>]+?)\s*>\s*$") |
| 109 | + |
| 110 | + |
| 111 | +def extract_name_email(s, default_missing=""): |
| 112 | + s = s.strip() |
| 113 | + |
| 114 | + if m := _EMAIL_RE.match(s): |
| 115 | + g = m.groupdict() |
| 116 | + # compatability: strip out quotation, since the original code tried to do this. |
| 117 | + |
| 118 | + return (_strip_quoted_name(g["name"]), g["email"]) |
| 119 | + # guess a bit |
| 120 | + if "@" in s: |
| 121 | + return default_missing, s |
| 122 | + return (_strip_quoted_name(s) if s else default_missing, default_missing) |
107 | 123 |
|
108 | 124 |
|
109 | 125 | def get_repo_owner(): |
@@ -237,12 +253,8 @@ def get_revisions( |
237 | 253 | tzstr = props["date"][-5:] |
238 | 254 | props["date"] = basetime.strftime("%Y-%m-%dT%H:%M:%S") + tzstr |
239 | 255 |
|
240 | | - m = EMAIL_RE.match(props["author"]) |
241 | | - if m: |
242 | | - props["author"] = AuthorData(name=m.group(1), email=m.group(2)) |
243 | | - else: |
244 | | - props["author"] = AuthorData(name="unknown", email="unkown") |
245 | | - |
| 256 | + (name, email) = extract_name_email(props["author"], "unknown") |
| 257 | + props["author"] = AuthorData(name=name, email=email) |
246 | 258 | yield CommitData(**props) |
247 | 259 | s += 2 |
248 | 260 |
|
|
0 commit comments