diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-15 18:07:04 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-15 18:07:04 +0200 |
commit | f2df1f56cccab13d5c92abbc6b18be725e7b4833 (patch) | |
tree | 3e3760e5b46095458cf75446330ba2fc25fa23e5 /lib/git/objects/base.py | |
parent | 58d692e2a1d7e3894dbed68efbcf7166d6ec3fb7 (diff) | |
parent | b67bd4c730273a9b6cce49a8444fb54e654de540 (diff) | |
download | gitpython-f2df1f56cccab13d5c92abbc6b18be725e7b4833.tar.gz |
Merge branch 'repo_interface' into improvements
* repo_interface:
Improved archive function by allowing it to directly write to an output stream - previously it would cache everything to memory and try to provide zipping functionality itself
repo: made init and clone methods less specific, previously they wanted to do it 'barely' only. New method names closely follow the default git command names
repo.commit_delta_base: removed
Object can now create objects of the proper type in case one attempts to create an object directly - this feature is used in several places now, allowing for additional type-checking
repo: removed commits_between but added a note about how this can be achieved using the iter_commits method; reorganized methods within the type as a start for more interface changes
Added Commit.iter_parents to iterate all parents
repo: removed a few methods because of redundancy or because it will be obsolete once the interface overhaul is finished. This commit is just intermediate
Diffstat (limited to 'lib/git/objects/base.py')
-rw-r--r-- | lib/git/objects/base.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index 07538ada..3b48e066 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -5,17 +5,32 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os from git.utils import LazyMixin +import utils _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" class Object(LazyMixin): """ Implements an Object which may be Blobs, Trees, Commits and Tags + + This Object also serves as a constructor for instances of the correct type:: + + inst = Object(repo,id) """ TYPES = ("blob", "tree", "commit", "tag") __slots__ = ("repo", "id", "size", "data" ) type = None # to be set by subclass + def __new__(cls, repo, id, *args, **kwargs): + if cls is Object: + hexsha, typename, size = repo.git.get_object_header(id) + obj_type = utils.get_object_type_by_name(typename) + inst = super(Object,cls).__new__(obj_type, repo, hexsha, *args, **kwargs) + inst.size = size + return inst + else: + return super(Object,cls).__new__(cls, repo, id, *args, **kwargs) + def __init__(self, repo, id): """ Initialize an object by identifying it by its id. All keyword arguments |