diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-14 17:25:05 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-14 17:25:05 +0200 |
commit | c9dbf201b4f0b3c2b299464618cb4ecb624d272c (patch) | |
tree | b0267c9f527682c2c420d00350e98f7e7bbe9969 /lib/git/objects/utils.py | |
parent | 38b3cfb9b24a108e0720f7a3f8d6355f7e0bb1a9 (diff) | |
download | gitpython-c9dbf201b4f0b3c2b299464618cb4ecb624d272c.tar.gz |
Moved small types that had their own module into the utils module
Diffstat (limited to 'lib/git/objects/utils.py')
-rw-r--r-- | lib/git/objects/utils.py | 57 |
1 files changed, 56 insertions, 1 deletions
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): |