diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2010-11-24 19:48:59 +0100 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2010-11-24 19:48:59 +0100 |
| commit | 3175b5b21194bcc8f4448abe0a03a98d3a4a1360 (patch) | |
| tree | f1a098c4b38ae3b7cf52600e9fc9c357cdd7c353 /objects | |
| parent | fca367548e365f93c58c47dea45507025269f59a (diff) | |
| parent | 3203cd7629345d32806f470a308975076b2b4686 (diff) | |
| download | GitPython-3175b5b21194bcc8f4448abe0a03a98d3a4a1360.tar.gz GitPython-3175b5b21194bcc8f4448abe0a03a98d3a4a1360.zip | |
Merge branch 'reflog'
Diffstat (limited to 'objects')
| -rw-r--r-- | objects/__init__.py | 2 | ||||
| -rw-r--r-- | objects/base.py | 4 | ||||
| -rw-r--r-- | objects/commit.py | 27 | ||||
| -rw-r--r-- | objects/submodule/base.py | 10 | ||||
| -rw-r--r-- | objects/submodule/root.py | 3 | ||||
| -rw-r--r-- | objects/util.py | 75 |
6 files changed, 20 insertions, 101 deletions
diff --git a/objects/__init__.py b/objects/__init__.py index e8e0ef39..77f69d29 100644 --- a/objects/__init__.py +++ b/objects/__init__.py @@ -7,6 +7,7 @@ from base import * # imported by the submodule.base import submodule.util submodule.util.IndexObject = IndexObject +submodule.util.Object = Object from submodule.base import * from submodule.root import * @@ -15,7 +16,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/base.py b/objects/base.py index b8cec47f..5f2f7809 100644 --- a/objects/base.py +++ b/objects/base.py @@ -57,6 +57,10 @@ class Object(LazyMixin): :return: new object instance of a type appropriate to represent the given binary sha1 :param sha1: 20 byte binary sha1""" + if sha1 == cls.NULL_BIN_SHA: + # the NULL binsha is always the root commit + return get_object_type_by_name('commit')(repo, sha1) + #END handle special case oinfo = repo.odb.info(sha1) inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha) inst.size = oinfo.size 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/submodule/base.py b/objects/submodule/base.py index 4f4223b6..5d32d600 100644 --- a/objects/submodule/base.py +++ b/objects/submodule/base.py @@ -14,6 +14,7 @@ from git.util import ( join_path_native, to_native_path_linux ) + from git.config import SectionConstraint from git.exc import ( InvalidGitRepositoryError, @@ -339,14 +340,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): # have a valid branch, but no checkout - make sure we can figure # that out by marking the commit with a null_sha - # have to write it directly as .commit = NULLSHA tries to resolve the sha - # This will bring the branch into existance - refpath = join_path_native(mrepo.git_dir, local_branch.path) - refdir = os.path.dirname(refpath) - if not os.path.isdir(refdir): - os.makedirs(refdir) - #END handle directory - open(refpath, 'w').write(self.NULL_HEX_SHA) + local_branch.set_object(util.Object(mrepo, self.NULL_BIN_SHA)) # END initial checkout + branch creation # make sure HEAD is not detached diff --git a/objects/submodule/root.py b/objects/submodule/root.py index 2e3cc775..d194cd5b 100644 --- a/objects/submodule/root.py +++ b/objects/submodule/root.py @@ -48,8 +48,7 @@ class RootModule(Submodule): :param previous_commit: If set to a commit'ish, the commit we should use as the previous commit the HEAD pointed to before it was set to the commit it points to now. - If None, it defaults to ORIG_HEAD otherwise, or the parent of the current - commit if it is not given + If None, it defaults to HEAD@{1} otherwise :param recursive: if True, the children of submodules will be updated as well using the same technique :param force_remove: If submodules have been deleted, they will be forcibly removed. diff --git a/objects/util.py b/objects/util.py index a9e1143c..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,21 +59,9 @@ 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 timezon which has the opposite sign as well, + returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200""" return -1 * int(float(utctz)/100*3600) @@ -193,56 +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'(.*) <(.+?)>' ) - - 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. @@ -359,6 +299,7 @@ class Traversable(object): class Serializable(object): """Defines methods to serialize and deserialize objects from and into a data stream""" + __slots__ = tuple() def _serialize(self, stream): """Serialize the data of this object into the given data stream |
