summaryrefslogtreecommitdiff
path: root/lib/git/objects
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git/objects')
-rw-r--r--lib/git/objects/__init__.py1
-rw-r--r--lib/git/objects/commit.py14
-rw-r--r--lib/git/objects/utils.py57
3 files changed, 65 insertions, 7 deletions
diff --git a/lib/git/objects/__init__.py b/lib/git/objects/__init__.py
index ef6b2ea4..209d8b51 100644
--- a/lib/git/objects/__init__.py
+++ b/lib/git/objects/__init__.py
@@ -8,6 +8,7 @@ from blob import *
from tree import *
from commit import *
from submodule import *
+from utils import Actor
__all__ = [ name for name, obj in locals().items()
if not (name.startswith('_') or inspect.ismodule(obj)) ] \ No newline at end of file
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py
index 3b20e314..f30a6dea 100644
--- a/lib/git/objects/commit.py
+++ b/lib/git/objects/commit.py
@@ -4,10 +4,12 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.utils import Iterable
+from git.utils import (
+ Iterable,
+ Stats,
+ )
+
import git.diff as diff
-import git.stats as stats
-from git.actor import Actor
from tree import Tree
from gitdb import IStream
from cStringIO import StringIO
@@ -223,7 +225,7 @@ class Commit(base.Object, Iterable, diff.Diffable, utils.Traversable, utils.Seri
text = text2
else:
text = self.repo.git.diff(self.parents[0].sha, self.sha, '--', numstat=True)
- return stats.Stats._list_from_string(self.repo, text)
+ return Stats._list_from_string(self.repo, text)
@classmethod
def _iter_from_process_or_stream(cls, repo, proc_or_stream):
@@ -332,8 +334,8 @@ class Commit(base.Object, Iterable, diff.Diffable, utils.Traversable, utils.Seri
enc_section, enc_option = cls.conf_encoding.split('.')
conf_encoding = cr.get_value(enc_section, enc_option, cls.default_encoding)
- author = Actor(author_name, author_email)
- committer = Actor(committer_name, committer_email)
+ author = utils.Actor(author_name, author_email)
+ committer = utils.Actor(committer_name, committer_email)
# CREATE NEW COMMIT
diff --git a/lib/git/objects/utils.py b/lib/git/objects/utils.py
index c93f2091..072662ee 100644
--- a/lib/git/objects/utils.py
+++ b/lib/git/objects/utils.py
@@ -8,7 +8,6 @@ Module for general utility functions
"""
import re
from collections import deque as Deque
-from git.actor import Actor
import platform
from string import digits
@@ -19,6 +18,8 @@ __all__ = ('get_object_type_by_name', 'get_user_id', 'parse_date', 'parse_actor_
'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',
'verify_utctz')
+#{ Functions
+
def get_object_type_by_name(object_type_name):
"""
Returns
@@ -180,6 +181,60 @@ def parse_actor_and_date(line):
actor, epoch, offset = m.groups()
return (Actor._from_string(actor), int(epoch), utctz_to_altz(offset))
+
+#} END functions
+
+
+#{ Classes
+
+class Actor(object):
+ """Actors hold information about a person acting on the repository. They
+ can be committers and authors or anything with a name and an email as
+ mentioned in the git log entries."""
+ # precompiled regex
+ name_only_regex = re.compile( r'<(.+)>' )
+ name_email_regex = re.compile( r'(.*) <(.+?)>' )
+
+ def __init__(self, name, email):
+ self.name = name
+ self.email = email
+
+ def __eq__(self, other):
+ return self.name == other.name and self.email == other.email
+
+ def __ne__(self, other):
+ return not (self == other)
+
+ def __hash__(self):
+ return hash((self.name, self.email))
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return '<git.Actor "%s <%s>">' % (self.name, self.email)
+
+ @classmethod
+ def _from_string(cls, string):
+ """Create an Actor from a string.
+ :param string: is the string, which is expected to be in regular git format
+
+ John Doe <jdoe@example.com>
+
+ :return: Actor """
+ m = cls.name_email_regex.search(string)
+ if m:
+ name, email = m.groups()
+ return Actor(name, email)
+ else:
+ m = cls.name_only_regex.search(string)
+ if m:
+ return Actor(m.group(1), None)
+ else:
+ # assume best and use the whole string as name
+ return Actor(string, None)
+ # END special case name
+ # END handle name/email matching
class ProcessStreamAdapter(object):