7
7
import logging
8
8
import os
9
9
import re
10
- from dataclasses import dataclass
11
10
import shlex
12
11
import warnings
13
12
from gitdb .db .loose import LooseObjectDB
@@ -890,7 +889,7 @@ def blame(self, rev: Union[str, HEAD], file: str, incremental: bool = False, **k
890
889
commits :Dict [str ,Commit ]= {}
891
890
blames :List [List [Commit | List [str | bytes ]| None ]]= []
892
891
893
- class InfoTC (TypedDict ,total = False ):
892
+ class InfoTD (TypedDict ,total = False ):
894
893
sha :str
895
894
id :str
896
895
filename :str
@@ -902,29 +901,15 @@ class InfoTC(TypedDict, total=False):
902
901
committer_email :str
903
902
committer_date :int
904
903
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 = {}
920
905
921
906
keepends = True
922
907
for line_bytes in data .splitlines (keepends ):
923
908
try :
924
909
line_str = line_bytes .rstrip ().decode (defenc )
925
910
except UnicodeDecodeError :
926
911
firstpart = ''
927
- parts = ['' ]
912
+ parts = []
928
913
is_binary = True
929
914
else :
930
915
# 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]]):
943
928
# another line of blame with the same data
944
929
digits = parts [- 1 ].split (" " )
945
930
if len (digits )== 3 :
946
- info . id = firstpart
931
+ info = { 'id' : firstpart }
947
932
blames .append ([None , []])
948
- elif info . id != firstpart :
949
- info . id = firstpart
933
+ elif info [ 'id' ] != firstpart :
934
+ info = { 'id' : firstpart }
950
935
blames .append ([commits .get (firstpart ), []])
951
936
# END blame data initialization
952
937
else :
@@ -962,12 +947,20 @@ class InfoDC(Dict[str, Union[str, int]]):
962
947
# committer-time 1192271832
963
948
# committer-tz -0700 - IGNORED BY US
964
949
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 ]
971
964
# END distinguish mail,time,name
972
965
else :
973
966
# handle
@@ -980,32 +973,34 @@ class InfoDC(Dict[str, Union[str, int]]):
980
973
info ['summary' ]= parts [- 1 ]
981
974
elif firstpart == '' :
982
975
if info :
983
- sha = info . id
976
+ sha = info [ 'id' ]
984
977
c = commits .get (sha )
985
978
if c is None :
986
979
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' ])
991
985
commits [sha ]= c
992
986
blames [- 1 ][0 ]= c
993
987
# END if commit objects needs initial creation
988
+
994
989
if blames [- 1 ][1 ]is not None :
990
+ line :str | bytes
995
991
if not is_binary :
996
992
if line_str and line_str [0 ]== '\t ' :
997
993
line_str = line_str [1 :]
998
-
999
- blames [- 1 ][1 ].append (line_str )
994
+ line = line_str
1000
995
else :
996
+ line = line_bytes
1001
997
# NOTE: We are actually parsing lines out of binary data, which can lead to the
1002
998
# binary being split up along the newline separator. We will append this to the
1003
999
# blame we are currently looking at, even though it should be concatenated with
1004
1000
# the last line we have seen.
1005
- blames [- 1 ][1 ].append (line_bytes )
1006
- # end handle line contents
1001
+ blames [- 1 ][1 ].append (line )
1007
1002
1008
- info . id = sha
1003
+ info = { 'id' : sha }
1009
1004
# END if we collected commit info
1010
1005
# END distinguish filename,summary,rest
1011
1006
# END distinguish author|committer vs filename,summary,rest