Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitecb1f79

Browse files
committed
Choose TypedDict!
1 parentad417ba commitecb1f79

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

‎git/repo/base.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
importlogging
88
importos
99
importre
10-
fromdataclassesimportdataclass
1110
importshlex
1211
importwarnings
1312
fromgitdb.db.looseimportLooseObjectDB
@@ -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-
classInfoTC(TypedDict,total=False):
892+
classInfoTD(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-
classInfoDC(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
forline_bytesindata.splitlines(keepends):
923908
try:
924909
line_str=line_bytes.rstrip().decode(defenc)
925910
exceptUnicodeDecodeError:
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
iflen(digits)==3:
946-
info.id=firstpart
931+
info={'id':firstpart}
947932
blames.append([None, []])
948-
elifinfo.id!=firstpart:
949-
info.id=firstpart
933+
elifinfo['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-
iffirstpart.endswith('-mail'):
966-
info[f"{role}_email"]=parts[-1]
967-
eliffirstpart.endswith('-time'):
968-
info[f"{role}_date"]=int(parts[-1])
969-
elifrole==firstpart:
970-
info[role]=parts[-1]
950+
ifrole=='author':
951+
iffirstpart.endswith('-mail'):
952+
info["author_email"]=parts[-1]
953+
eliffirstpart.endswith('-time'):
954+
info["author_date"]=int(parts[-1])
955+
elifrole==firstpart:
956+
info["author"]=parts[-1]
957+
elifrole=='committer':
958+
iffirstpart.endswith('-mail'):
959+
info["committer_email"]=parts[-1]
960+
eliffirstpart.endswith('-time'):
961+
info["committer_date"]=int(parts[-1])
962+
elifrole==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
eliffirstpart=='':
982975
ifinfo:
983-
sha=info.id
976+
sha=info['id']
984977
c=commits.get(sha)
985978
ifcisNone:
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
ifblames[-1][1]isnotNone:
990+
line:str|bytes
995991
ifnotis_binary:
996992
ifline_strandline_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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp