summaryrefslogtreecommitdiff
path: root/lib/git/objects/base.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-18 14:25:14 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-18 14:25:14 +0200
commit225999e9442c746333a8baa17a6dbf7341c135ca (patch)
tree82e4bdf8a59fae869bae41aa6b9b048fee2d3e09 /lib/git/objects/base.py
parent919164df96d9f956c8be712f33a9a037b097745b (diff)
parent9acc7806d6bdb306a929c460437d3d03e5e48dcd (diff)
downloadgitpython-225999e9442c746333a8baa17a6dbf7341c135ca.tar.gz
Merge branch 'diffing' into improvements
* diffing: DiffIndex implemented including test diff: implemented raw diff parsing which appears to be able to handle possible input types, DiffIndex still requires implementation though resolved cyclic inclusion issue by moving the Diffable interface into the diff module, which probably is the right thing to do anyway repo: fixed untracked files function which used git-commit before, it can open vim to get a message though which makes the program appear to freeze - using git-status now implemented diff tests, but will have to move the diff module as it needs to create objects, whose import would create a dependency cycle Removed a few diff-related test cases that fail now as the respective method is missing - these tests have to be redone in test-diff module accordingly added Diffable interface to objects.base, its used by Commit and Tree objects. Fixed object bug that would cause object ids not to be resolved to sha's as this was assumed - now there is a test for it as well
Diffstat (limited to 'lib/git/objects/base.py')
-rw-r--r--lib/git/objects/base.py33
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py
index 3b48e066..ab1da7b0 100644
--- a/lib/git/objects/base.py
+++ b/lib/git/objects/base.py
@@ -15,22 +15,12 @@ class Object(LazyMixin):
This Object also serves as a constructor for instances of the correct type::
- inst = Object(repo,id)
+ inst = Object.new(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
@@ -45,7 +35,25 @@ class Object(LazyMixin):
super(Object,self).__init__()
self.repo = repo
self.id = id
-
+
+ @classmethod
+ def new(cls, repo, id):
+ """
+ Return
+ New Object instance of a type appropriate to the object type behind
+ id. The id of the newly created object will be a hexsha even though
+ the input id may have been a Reference or Rev-Spec
+
+ Note
+ This cannot be a __new__ method as it would always call __init__
+ with the input id which is not necessarily a hexsha.
+ """
+ hexsha, typename, size = repo.git.get_object_header(id)
+ obj_type = utils.get_object_type_by_name(typename)
+ inst = obj_type(repo, hexsha)
+ inst.size = size
+ return inst
+
def _set_self_from_args_(self, args_dict):
"""
Initialize attributes on self from the given dict that was retrieved
@@ -162,5 +170,4 @@ class IndexObject(Object):
mode += int(char) << iteration*3
# END for each char
return mode
-