Skip to content

Commit

Permalink
Avoid re module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Aug 25, 2019
1 parent 1beda21 commit 3f87027
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 2 additions & 7 deletions dulwich/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import sys
import stat
import time
import re

from dulwich.errors import (
NoIndexPresent,
Expand Down Expand Up @@ -113,9 +112,6 @@

DEFAULT_REF = b'refs/heads/master'

quoted_email_re = re.compile(br"^\s*<\s*(.*)\s*>\s*$")


class InvalidUserIdentity(Exception):
"""User identity is not of the format 'user <email>'"""

Expand Down Expand Up @@ -178,9 +174,8 @@ def get_user_identity(config, kind=None):
email = default_email
if not isinstance(email, bytes):
email = email.encode('utf-8')
m = quoted_email_re.match(email)
if m:
email = m.group(1)
if email.startswith(b'<') and email.endswith(b'>'):
email = email[1:-1]
return (user + b" <" + email + b">")


Expand Down
16 changes: 16 additions & 0 deletions dulwich/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,22 @@ def test_commit_config_identity(self):
r = self._repo
c = r.get_config()
c.set((b"user", ), b"name", b"Jelmer")
c.set((b"user", ), b"email", b"jelmer@apache.org")
c.write_to_path()
commit_sha = r.do_commit(b'message')
self.assertEqual(
b"Jelmer <jelmer@apache.org>",
r[commit_sha].author)
self.assertEqual(
b"Jelmer <jelmer@apache.org>",
r[commit_sha].committer)

def test_commit_config_identity_strips_than(self):
# commit falls back to the users' identity if it wasn't specified,
# and strips superfluous <>
r = self._repo
c = r.get_config()
c.set((b"user", ), b"name", b"Jelmer")
c.set((b"user", ), b"email", b"<jelmer@apache.org>")
c.write_to_path()
commit_sha = r.do_commit(b'message')
Expand Down

0 comments on commit 3f87027

Please sign in to comment.