summaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
Diffstat (limited to 'objects')
-rw-r--r--objects/__init__.py1
-rw-r--r--objects/commit.py27
-rw-r--r--objects/util.py74
3 files changed, 10 insertions, 92 deletions
diff --git a/objects/__init__.py b/objects/__init__.py
index e8e0ef39..65659cd1 100644
--- a/objects/__init__.py
+++ b/objects/__init__.py
@@ -15,7 +15,6 @@ from tag import *
from blob import *
from commit import *
from tree import *
-from util 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/objects/commit.py b/objects/commit.py
index a2b6c554..9c7e66a3 100644
--- a/objects/commit.py
+++ b/objects/commit.py
@@ -4,7 +4,8 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from git.util import (
+from git.util import (
+ Actor,
Iterable,
Stats,
)
@@ -20,9 +21,7 @@ from gitdb.util import (
from util import (
Traversable,
Serializable,
- get_user_id,
parse_date,
- Actor,
altz_to_utctz_str,
parse_actor_and_date
)
@@ -43,17 +42,10 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# ENVIRONMENT VARIABLES
# read when creating new commits
- env_author_name = "GIT_AUTHOR_NAME"
- env_author_email = "GIT_AUTHOR_EMAIL"
env_author_date = "GIT_AUTHOR_DATE"
- env_committer_name = "GIT_COMMITTER_NAME"
- env_committer_email = "GIT_COMMITTER_EMAIL"
env_committer_date = "GIT_COMMITTER_DATE"
- env_email = "EMAIL"
# CONFIGURATION KEYS
- conf_name = 'name'
- conf_email = 'email'
conf_encoding = 'i18n.commitencoding'
# INVARIANTS
@@ -306,17 +298,9 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# COMMITER AND AUTHOR INFO
cr = repo.config_reader()
env = os.environ
- default_email = get_user_id()
- default_name = default_email.split('@')[0]
- conf_name = cr.get_value('user', cls.conf_name, default_name)
- conf_email = cr.get_value('user', cls.conf_email, default_email)
-
- author_name = env.get(cls.env_author_name, conf_name)
- author_email = env.get(cls.env_author_email, conf_email)
-
- committer_name = env.get(cls.env_committer_name, conf_name)
- committer_email = env.get(cls.env_committer_email, conf_email)
+ committer = Actor.committer(cr)
+ author = Actor.author(cr)
# PARSE THE DATES
unix_time = int(time())
@@ -340,9 +324,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
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)
-
# if the tree is no object, make sure we create one - otherwise
# the created commit object is invalid
diff --git a/objects/util.py b/objects/util.py
index dfaaf7c4..4c9323b8 100644
--- a/objects/util.py
+++ b/objects/util.py
@@ -4,19 +4,21 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
"""Module for general utility functions"""
-from git.util import IterableList
+from git.util import (
+ IterableList,
+ Actor
+ )
import re
from collections import deque as Deque
-import platform
from string import digits
import time
import os
-__all__ = ('get_object_type_by_name', 'get_user_id', 'parse_date', 'parse_actor_and_date',
+__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date',
'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz',
- 'verify_utctz')
+ 'verify_utctz', 'Actor')
#{ Functions
@@ -57,18 +59,6 @@ def get_object_type_by_name(object_type_name):
else:
raise ValueError("Cannot handle unknown object type: %s" % object_type_name)
-
-def get_user_id():
- """:return: string identifying the currently active system user as name@node
- :note: user can be set with the 'USER' environment variable, usually set on windows"""
- ukn = 'UNKNOWN'
- username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
- if username == ukn and hasattr(os, 'getlogin'):
- username = os.getlogin()
- # END get username from login
- return "%s@%s" % (username, platform.node())
-
-
def utctz_to_altz(utctz):
"""we convert utctz to the timezone in seconds, it is the format time.altzone
returns. Git stores it as UTC timezone which has the opposite sign as well,
@@ -193,58 +183,6 @@ def parse_actor_and_date(line):
#{ 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'(.*) <(.+?)>' )
-
- __slots__ = ('name', 'email')
-
- 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):
"""Class wireing all calls to the contained Process instance.