summaryrefslogtreecommitdiff
path: root/lib/git/commit.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-09 16:04:54 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-09 16:04:54 +0200
commit9c0c2fc4ee2d8a5d0a2de50ba882657989dedc51 (patch)
treed7e7e227b216e451a5224d7f60b3fee1ed5be71e /lib/git/commit.py
parent52ab307935bd2bbda52f853f9fc6b49f01897727 (diff)
downloadgitpython-9c0c2fc4ee2d8a5d0a2de50ba882657989dedc51.tar.gz
finished cleaning usage of regular expressions - they are now precompiled
Diffstat (limited to 'lib/git/commit.py')
-rw-r--r--lib/git/commit.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py
index 3d383df2..961e483b 100644
--- a/lib/git/commit.py
+++ b/lib/git/commit.py
@@ -20,6 +20,9 @@ class Commit(LazyMixin):
This class will act lazily on some of its attributes and will query the
value on demand only if it involves calling the git binary.
"""
+ # precompiled regex
+ re_actor_epoch = re.compile(r'^.+? (.*) (\d+) .*$')
+
def __init__(self, repo, id, tree=None, author=None, authored_date=None,
committer=None, committed_date=None, message=None, parents=None):
"""
@@ -246,12 +249,6 @@ class Commit(LazyMixin):
"""
if not self.parents:
d = self.repo.git.show(self.id, '-M', full_index=True, pretty='raw')
- if re.search(r'diff --git a', d):
- if not re.search(r'^diff --git a', d):
- p = re.compile(r'.+?(diff --git a)', re.MULTILINE | re.DOTALL)
- d = p.sub(r'diff --git a', d, 1)
- else:
- d = ''
return diff.Diff.list_from_string(self.repo, d)
else:
return self.diff(self.repo, self.parents[0].id, self.id)
@@ -291,6 +288,6 @@ class Commit(LazyMixin):
Returns
[Actor, gmtime(acted at time)]
"""
- m = re.search(r'^.+? (.*) (\d+) .*$', line)
+ m = cls.re_actor_epoch.search(line)
actor, epoch = m.groups()
return (Actor.from_string(actor), time.gmtime(int(epoch)))