@@ -15,22 +15,12 @@ class Object(LazyMixin):
1515
1616 This Object also serves as a constructor for instances of the correct type::
1717
18- inst = Object(repo,id)
18+ inst = Object.new (repo,id)
1919 """
2020 TYPES = ("blob" , "tree" , "commit" , "tag" )
2121 __slots__ = ("repo" , "id" , "size" , "data" )
2222 type = None # to be set by subclass
2323
24- def __new__ (cls , repo , id , * args , ** kwargs ):
25- if cls is Object :
26- hexsha , typename , size = repo .git .get_object_header (id )
27- obj_type = utils .get_object_type_by_name (typename )
28- inst = super (Object ,cls ).__new__ (obj_type , repo , hexsha , * args , ** kwargs )
29- inst .size = size
30- return inst
31- else :
32- return super (Object ,cls ).__new__ (cls , repo , id , * args , ** kwargs )
33-
3424 def __init__ (self , repo , id ):
3525 """
3626 Initialize an object by identifying it by its id. All keyword arguments
@@ -45,7 +35,25 @@ def __init__(self, repo, id):
4535 super (Object ,self ).__init__ ()
4636 self .repo = repo
4737 self .id = id
48-
38+
39+ @classmethod
40+ def new (cls , repo , id ):
41+ """
42+ Return
43+ New Object instance of a type appropriate to the object type behind
44+ id. The id of the newly created object will be a hexsha even though
45+ the input id may have been a Reference or Rev-Spec
46+
47+ Note
48+ This cannot be a __new__ method as it would always call __init__
49+ with the input id which is not necessarily a hexsha.
50+ """
51+ hexsha , typename , size = repo .git .get_object_header (id )
52+ obj_type = utils .get_object_type_by_name (typename )
53+ inst = obj_type (repo , hexsha )
54+ inst .size = size
55+ return inst
56+
4957 def _set_self_from_args_ (self , args_dict ):
5058 """
5159 Initialize attributes on self from the given dict that was retrieved
0 commit comments