Parse .mailmap file to get canonical name/email mappings.
(self)
| 51 | return patterns |
| 52 | |
| 53 | def _parse_mailmap(self) -> Dict[str, Tuple[str, str]]: |
| 54 | """Parse .mailmap file to get canonical name/email mappings.""" |
| 55 | mailmap_file = self.repo_root / ".mailmap" |
| 56 | mailmap = {} |
| 57 | |
| 58 | if not mailmap_file.exists(): |
| 59 | print("Warning: .mailmap file not found") |
| 60 | return mailmap |
| 61 | |
| 62 | with open(mailmap_file, "r") as f: |
| 63 | for line in f: |
| 64 | line = line.strip() |
| 65 | if not line or line.startswith("#"): |
| 66 | continue |
| 67 | |
| 68 | # Parse mailmap format: "Proper Name <proper@email.com> <commit@email.com>" |
| 69 | # or "Proper Name <proper@email.com> Commit Name <commit@email.com>" |
| 70 | if ">" in line: |
| 71 | parts = line.split(">") |
| 72 | if len(parts) >= 2: |
| 73 | proper_part = parts[0].strip() |
| 74 | commit_part = parts[1].strip() |
| 75 | |
| 76 | # Extract proper name and email |
| 77 | if "<" in proper_part: |
| 78 | proper_name = proper_part.split("<")[0].strip() |
| 79 | proper_email = proper_part.split("<")[1].strip() |
| 80 | else: |
| 81 | continue |
| 82 | |
| 83 | # Extract commit email (and possibly name) |
| 84 | if "<" in commit_part: |
| 85 | commit_email = ( |
| 86 | commit_part.split("<")[1].split(">")[0].strip() |
| 87 | ) |
| 88 | else: |
| 89 | commit_email = commit_part.strip() |
| 90 | |
| 91 | mailmap[commit_email] = (proper_name, proper_email) |
| 92 | |
| 93 | return mailmap |
| 94 | |
| 95 | def _build_company_domain_map(self) -> Dict[str, str]: |
| 96 | """Build mapping from email domains to company names.""" |