-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.py
More file actions
executable file
·41 lines (31 loc) · 1.02 KB
/
commit.py
File metadata and controls
executable file
·41 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import sys
import email
import re
name_map = {
'root': 'unchaptered',
}
email_map = {
'root@ip-172-31-3-247.ap-northeast-2.compute.internal': 'workstation19961002@gmail.com',
}
def fixup(name, email_address):
new_name = name_map.get(name)
new_email = email_map.get(email_address)
if new_name is None and new_email is None:
return None
else:
return new_name or name, new_email or email_address
def fix_name_email(line):
decoded = line.decode('utf-8')
match = re.match('^(author|committer|tagger) (.*) <(.*)>', decoded)
if not match:
return line
old_name, old_email = match.group(2), match.group(3)
new = fixup(old_name, old_email)
if not new:
return line
new_name, new_email = new
replacement = f"{match.group(1)} {new_name} <{new_email}>"
return decoded.replace(f"{match.group(1)} {old_name} <{old_email}>", replacement).encode('utf-8')
for line in sys.stdin.buffer:
sys.stdout.buffer.write(fix_name_email(line))