@@ -38,9 +38,9 @@ class Tree(base.IndexObject, diff.Diffable):
3838 __slots__ = "_cache"
3939
4040 # using ascii codes for comparison
41- ascii_commit_id = ( 0x31 << 4 ) + 0x36
42- ascii_blob_id = ( 0x31 << 4 ) + 0x30
43- ascii_tree_id = ( 0x34 << 4 ) + 0x30
41+ commit_id = 016
42+ blob_id = 010
43+ tree_id = 040
4444
4545
4646 def __init__ (self , repo , id , mode = 0 , path = None ):
@@ -88,8 +88,8 @@ def _iter_from_data(self):
8888 mode = 0
8989 mode_boundary = i + 6
9090
91- # keep it ascii - we compare against the respective values
92- type_id = (ord (data [i ])<< 4 ) + ord (data [i + 1 ])
91+ # read type
92+ type_id = (( ord (data [i ])- ord_zero ) << 3 ) + ( ord (data [i + 1 ]) - ord_zero )
9393 i += 2
9494
9595 while data [i ] != ' ' :
@@ -115,12 +115,13 @@ def _iter_from_data(self):
115115 sha = data [i :i + 20 ]
116116 i = i + 20
117117
118+ mode |= type_id << 12
118119 hexsha = sha_to_hex (sha )
119- if type_id == self .ascii_blob_id :
120+ if type_id == self .blob_id :
120121 yield blob .Blob (self .repo , hexsha , mode , name )
121- elif type_id == self .ascii_tree_id :
122+ elif type_id == self .tree_id :
122123 yield Tree (self .repo , hexsha , mode , name )
123- elif type_id == self .ascii_commit_id :
124+ elif type_id == self .commit_id :
124125 # todo
125126 yield None
126127 else :
0 commit comments