changeset 541:df1598b722e8

Precompile Git progress regular expressions
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 21 Sep 2012 19:42:24 -0700
parents 3fb942852b1c
children c9faba7d01f4
files hggit/git_handler.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Fri Sep 21 19:39:53 2012 -0700
+++ b/hggit/git_handler.py	Fri Sep 21 19:42:24 2012 -0700
@@ -42,6 +42,9 @@
     r'^(?P<scheme>git([+]ssh)?://)(?P<host>.*?)(:(?P<port>\d+))?'
     r'(?P<sepr>[:/])(?P<path>.*)$')
 
+RE_NEWLINES = re.compile('[\r\n]')
+RE_GIT_PROGRESS = re.compile('\((\d+)/(\d+)\)')
+
 class GitProgress(object):
     """convert git server progress strings into mercurial progress"""
     def __init__(self, ui):
@@ -53,7 +56,7 @@
     def progress(self, msg):
         # 'Counting objects: 33640, done.\n'
         # 'Compressing objects:   0% (1/9955)   \r
-        msgs = re.split('[\r\n]', self.msgbuf + msg)
+        msgs = RE_NEWLINES.split(self.msgbuf + msg)
         self.msgbuf = msgs.pop()
 
         for msg in msgs:
@@ -64,7 +67,7 @@
                 continue
             topic = td[0]
 
-            m = re.search('\((\d+)/(\d+)\)', data)
+            m = RE_GIT_PROGRESS.search(data)
             if m:
                 if self.lasttopic and self.lasttopic != topic:
                     self.flush()