summaryrefslogtreecommitdiff
path: root/lib/git/objects/base.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-16 11:48:20 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-16 11:48:20 +0200
commit05d2687afcc78cd192714ee3d71fdf36a37d110f (patch)
tree3e3760e5b46095458cf75446330ba2fc25fa23e5 /lib/git/objects/base.py
parent6226720b0e6a5f7cb9223fc50363def487831315 (diff)
parentf2df1f56cccab13d5c92abbc6b18be725e7b4833 (diff)
downloadgitpython-05d2687afcc78cd192714ee3d71fdf36a37d110f.tar.gz
Merging latest improvements including a revamped Repo interface before more changes are to be done on the way diffing is handled
Merge branch 'improvements' * improvements: 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 All times are not stored as time_struct, but as simple int to consume less memory
Diffstat (limited to 'lib/git/objects/base.py')
-rw-r--r--lib/git/objects/base.py15
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