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