From f963881e53a9f0a2746a11cb9cdfa82eb1f90d8c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jul 2010 00:35:30 +0200 Subject: Initial version of the rev-parse routine, which doesn't work too bad, but its still rather slow and many tests are not yet implemented --- lib/git/objects/base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/git/objects/base.py') diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index d4a46788..21b9b1ea 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -53,6 +53,17 @@ class Object(LazyMixin): inst = get_object_type_by_name(typename)(repo, hex_to_bin(hexsha)) inst.size = size return inst + + @classmethod + def new_from_sha(cls, repo, sha1): + """ + :return: new object instance of a type appropriate to represent the given + binary sha1 + :param sha1: 20 byte binary sha1""" + oinfo = repo.odb.info(sha1) + inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha) + inst.size = oinfo.size + return inst def _set_self_from_args_(self, args_dict): """Initialize attributes on self from the given dict that was retrieved -- cgit v1.2.1 From bc31651674648f026464fd4110858c4ffeac3c18 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jul 2010 17:30:47 +0200 Subject: Adjusted previous object creators to use the rev_parse method directly. rev_parse could be adjusted not to return Objects anymore, providing better performance for those who just want a sha only. On the other hand, the method is high-level and should be convenient to use as well, its a starting point for more usually, hence its unlikely to call it in tight loops --- lib/git/objects/base.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/git/objects/base.py') diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index 21b9b1ea..41862ac2 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -49,10 +49,7 @@ class Object(LazyMixin): :note: This cannot be a __new__ method as it would always call __init__ with the input id which is not necessarily a binsha.""" - hexsha, typename, size = repo.git.get_object_header(id) - inst = get_object_type_by_name(typename)(repo, hex_to_bin(hexsha)) - inst.size = size - return inst + return repo.rev_parse(str(id)) @classmethod def new_from_sha(cls, repo, sha1): -- cgit v1.2.1