77import logging
88import os
99import re
10- from dataclasses import dataclass
1110import shlex
1211import warnings
1312from gitdb .db .loose import LooseObjectDB
@@ -890,7 +889,7 @@ def blame(self, rev: Union[str, HEAD], file: str, incremental: bool = False, **k
890889 commits : Dict [str , Commit ] = {}
891890 blames : List [List [Commit | List [str | bytes ] | None ]] = []
892891
893- class InfoTC (TypedDict , total = False ):
892+ class InfoTD (TypedDict , total = False ):
894893 sha : str
895894 id : str
896895 filename : str
@@ -902,29 +901,15 @@ class InfoTC(TypedDict, total=False):
902901 committer_email : str
903902 committer_date : int
904903
905- @dataclass
906- class InfoDC (Dict [str , Union [str , int ]]):
907- sha : str = ''
908- id : str = ''
909- filename : str = ''
910- summary : str = ''
911- author : str = ''
912- author_email : str = ''
913- author_date : int = 0
914- committer : str = ''
915- committer_email : str = ''
916- committer_date : int = 0
917-
918- # info: InfoTD = {}
919- info = InfoDC ()
904+ info : InfoTD = {}
920905
921906 keepends = True
922907 for line_bytes in data .splitlines (keepends ):
923908 try :
924909 line_str = line_bytes .rstrip ().decode (defenc )
925910 except UnicodeDecodeError :
926911 firstpart = ''
927- parts = ['' ]
912+ parts = []
928913 is_binary = True
929914 else :
930915 # As we don't have an idea when the binary data ends, as it could contain multiple newlines
@@ -943,10 +928,10 @@ class InfoDC(Dict[str, Union[str, int]]):
943928 # another line of blame with the same data
944929 digits = parts [- 1 ].split (" " )
945930 if len (digits ) == 3 :
946- info . id = firstpart
931+ info = { 'id' : firstpart }
947932 blames .append ([None , []])
948- elif info . id != firstpart :
949- info . id = firstpart
933+ elif info [ 'id' ] != firstpart :
934+ info = { 'id' : firstpart }
950935 blames .append ([commits .get (firstpart ), []])
951936 # END blame data initialization
952937 else :
@@ -962,12 +947,20 @@ class InfoDC(Dict[str, Union[str, int]]):
962947 # committer-time 1192271832
963948 # committer-tz -0700 - IGNORED BY US
964949 role = m .group (0 )
965- if firstpart .endswith ('-mail' ):
966- info [f"{ role } _email" ] = parts [- 1 ]
967- elif firstpart .endswith ('-time' ):
968- info [f"{ role } _date" ] = int (parts [- 1 ])
969- elif role == firstpart :
970- info [role ] = parts [- 1 ]
950+ if role == 'author' :
951+ if firstpart .endswith ('-mail' ):
952+ info ["author_email" ] = parts [- 1 ]
953+ elif firstpart .endswith ('-time' ):
954+ info ["author_date" ] = int (parts [- 1 ])
955+ elif role == firstpart :
956+ info ["author" ] = parts [- 1 ]
957+ elif role == 'committer' :
958+ if firstpart .endswith ('-mail' ):
959+ info ["committer_email" ] = parts [- 1 ]
960+ elif firstpart .endswith ('-time' ):
961+ info ["committer_date" ] = int (parts [- 1 ])
962+ elif role == firstpart :
963+ info ["committer" ] = parts [- 1 ]
971964 # END distinguish mail,time,name
972965 else :
973966 # handle
@@ -980,32 +973,34 @@ class InfoDC(Dict[str, Union[str, int]]):
980973 info ['summary' ] = parts [- 1 ]
981974 elif firstpart == '' :
982975 if info :
983- sha = info . id
976+ sha = info [ 'id' ]
984977 c = commits .get (sha )
985978 if c is None :
986979 c = Commit (self , hex_to_bin (sha ),
987- author = Actor ._from_string (f"{ info .author } { info .author_email } " ),
988- authored_date = info .author_date ,
989- committer = Actor ._from_string (f"{ info .committer } { info .committer_email } " ),
990- committed_date = info .committer_date )
980+ author = Actor ._from_string (f"{ info ['author' ]} { info ['author_email' ]} " ),
981+ authored_date = info ['author_date' ],
982+ committer = Actor ._from_string (
983+ f"{ info ['committer' ]} { info ['committer_email' ]} " ),
984+ committed_date = info ['committer_date' ])
991985 commits [sha ] = c
992986 blames [- 1 ][0 ] = c
993987 # END if commit objects needs initial creation
988+
994989 if blames [- 1 ][1 ] is not None :
990+ line : str | bytes
995991 if not is_binary :
996992 if line_str and line_str [0 ] == '\t ' :
997993 line_str = line_str [1 :]
998-
999- blames [- 1 ][1 ].append (line_str )
994+ line = line_str
1000995 else :
996+ line = line_bytes
1001997 # NOTE: We are actually parsing lines out of binary data, which can lead to the
1002998 # binary being split up along the newline separator. We will append this to the
1003999 # blame we are currently looking at, even though it should be concatenated with
10041000 # the last line we have seen.
1005- blames [- 1 ][1 ].append (line_bytes )
1006- # end handle line contents
1001+ blames [- 1 ][1 ].append (line )
10071002
1008- info . id = sha
1003+ info = { 'id' : sha }
10091004 # END if we collected commit info
10101005 # END distinguish filename,summary,rest
10111006 # END distinguish author|committer vs filename,summary,rest
0 commit comments