From 3f87027ed1f16a667731778f719d4c790a6d6ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 25 Aug 2019 22:52:05 +0000 Subject: [PATCH] Avoid re module. --- dulwich/repo.py | 9 ++------- dulwich/tests/test_repository.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dulwich/repo.py b/dulwich/repo.py index aaa066e6b..dbd6417b8 100644 --- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -34,7 +34,6 @@ import sys import stat import time -import re from dulwich.errors import ( NoIndexPresent, @@ -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 '""" @@ -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">") diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py index 368f943de..1529917ab 100644 --- a/dulwich/tests/test_repository.py +++ b/dulwich/tests/test_repository.py @@ -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 ", + r[commit_sha].author) + self.assertEqual( + b"Jelmer ", + 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"") c.write_to_path() commit_sha = r.do_commit(b'message')