@@ -170,6 +170,14 @@ class Diff(object):
170170
171171 b_mode is None
172172 b_blob is None
173+
174+ ``Working Tree Blobs``
175+
176+ When comparing to working trees, the working tree blob will have a null hexsha
177+ as a corresponding object does not yet exist. The mode will be null as well.
178+ But the path will be available though.
179+ If it is listed in a diff the working tree version of the file must
180+ be different to the version in the index or tree, and hence has been modified.
173181 """
174182
175183 # precompiled regex
@@ -186,18 +194,20 @@ class Diff(object):
186194 (?:^index[ ](?P<a_blob_id>[0-9A-Fa-f]+)
187195 \.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
188196 """ , re .VERBOSE | re .MULTILINE )
189- re_is_null_hexsha = re .compile ( r'^0{40}$' )
197+ # can be used for comparisons
198+ null_hex_sha = "0" * 40
199+
190200 __slots__ = ("a_blob" , "b_blob" , "a_mode" , "b_mode" , "new_file" , "deleted_file" ,
191201 "rename_from" , "rename_to" , "diff" )
192202
193203 def __init__ (self , repo , a_path , b_path , a_blob_id , b_blob_id , a_mode ,
194204 b_mode , new_file , deleted_file , rename_from ,
195205 rename_to , diff ):
196- if not a_blob_id or self . re_is_null_hexsha . search ( a_blob_id ) :
206+ if a_blob_id is None :
197207 self .a_blob = None
198208 else :
199209 self .a_blob = blob .Blob (repo , a_blob_id , mode = a_mode , path = a_path )
200- if not b_blob_id or self . re_is_null_hexsha . search ( b_blob_id ) :
210+ if not b_blob_id :
201211 self .b_blob = None
202212 else :
203213 self .b_blob = blob .Blob (repo , b_blob_id , mode = b_mode , path = b_path )
@@ -301,10 +311,10 @@ def _index_from_raw_format(cls, repo, stream):
301311 # NOTE: We cannot conclude from the existance of a blob to change type
302312 # as diffs with the working do not have blobs yet
303313 if change_type == 'D' :
304- b_path = None
314+ b_blob_id = None
305315 deleted_file = True
306316 elif change_type == 'A' :
307- a_path = None
317+ a_blob_id = None
308318 new_file = True
309319 # END add/remove handling
310320
0 commit comments