Dulwich.io dulwich / 3f87027
Avoid re module. Jelmer Vernooń≥ 28 days ago
2 changed file(s) with 18 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
3333 import sys
3434 import stat
3535 import time
36 import re
3736
3837 from dulwich.errors import (
3938 NoIndexPresent,
112111
113112 DEFAULT_REF = b'refs/heads/master'
114113
115 quoted_email_re = re.compile(br"^\s*<\s*(.*)\s*>\s*$")
116
117
118114 class InvalidUserIdentity(Exception):
119115 """User identity is not of the format 'user <email>'"""
120116
177173 email = default_email
178174 if not isinstance(email, bytes):
179175 email = email.encode('utf-8')
180 m = quoted_email_re.match(email)
181 if m:
182 email = m.group(1)
176 if email.startswith(b'<') and email.endswith(b'>'):
177 email = email[1:-1]
183178 return (user + b" <" + email + b">")
184179
185180
881881 r = self._repo
882882 c = r.get_config()
883883 c.set((b"user", ), b"name", b"Jelmer")
884 c.set((b"user", ), b"email", b"jelmer@apache.org")
885 c.write_to_path()
886 commit_sha = r.do_commit(b'message')
887 self.assertEqual(
888 b"Jelmer <jelmer@apache.org>",
889 r[commit_sha].author)
890 self.assertEqual(
891 b"Jelmer <jelmer@apache.org>",
892 r[commit_sha].committer)
893
894 def test_commit_config_identity_strips_than(self):
895 # commit falls back to the users' identity if it wasn't specified,
896 # and strips superfluous <>
897 r = self._repo
898 c = r.get_config()
899 c.set((b"user", ), b"name", b"Jelmer")
884900 c.set((b"user", ), b"email", b"<jelmer@apache.org>")
885901 c.write_to_path()
886902 commit_sha = r.do_commit(b'message')