changeset 537:6e05aa1b536d

Optimize get_git_author Pre-compile regular expression. Prevent extra key lookup in author_map.
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 21 Sep 2012 19:28:46 -0700
parents 3b82cf6ac73a
children a38abdbab77c
files hggit/git_handler.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -29,6 +29,8 @@
 import util
 from overlay import overlayrepo
 
+RE_GIT_AUTHOR = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
+
 class GitProgress(object):
     """convert git server progress strings into mercurial progress"""
     def __init__(self, ui):
@@ -433,12 +435,10 @@
         author = ctx.user()
 
         # see if a translation exists
-        if author in self.author_map:
-            author = self.author_map[author]
+        author = self.author_map.get(author, author)
 
         # check for git author pattern compliance
-        regex = re.compile('^(.*?) ?\<(.*?)(?:\>(.*))?$')
-        a = regex.match(author)
+        a = RE_GIT_AUTHOR.match(author)
 
         if a:
             name = self.get_valid_git_username_email(a.group(1))