diff hggit/git_handler.py @ 539:7bf60690386c

Precompile Git username sanitizing regular expression
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 21 Sep 2012 19:36:57 -0700
parents a38abdbab77c
children 3fb942852b1c
line wrap: on
line diff
--- a/hggit/git_handler.py	Fri Sep 21 19:32:16 2012 -0700
+++ b/hggit/git_handler.py	Fri Sep 21 19:36:57 2012 -0700
@@ -31,6 +31,8 @@
 
 RE_GIT_AUTHOR = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
 
+RE_GIT_SANITIZE_AUTHOR = re.compile('[<>\n]')
+
 # Test for git:// and git+ssh:// URI.
 # Support several URL forms, including separating the
 # host and path with either a / or : (sepr)
@@ -435,7 +437,7 @@
         >>> g('Typo in hgrc >but.hg-git@handles.it.gracefully>')
         'Typo in hgrc ?but.hg-git@handles.it.gracefully'
         """
-        return re.sub('[<>\n]', '?', name.lstrip('< ').rstrip('> '))
+        return RE_GIT_SANITIZE_AUTHOR.sub('?', name.lstrip('< ').rstrip('> '))
 
     def get_git_author(self, ctx):
         # hg authors might not have emails