Skip to content

Commit ed137cb

Browse files
committed
Test TypedDict in repo.base.blame() 2
1 parent a2a36e0 commit ed137cb

File tree

1 file changed

+36
-44
lines changed

1 file changed

+36
-44
lines changed

git/repo/base.py

+36-44
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import os
99
import re
10-
from dataclasses import dataclass
1110
import shlex
1211
import warnings
1312
from gitdb.db.loose import LooseObjectDB
@@ -902,21 +901,7 @@ class InfoTD(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):
@@ -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,34 +973,33 @@ 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(info.author + ' ' + info.author_email),
988-
authored_date=info.author_date,
980+
author=Actor._from_string(info['author'] + ' ' + info['author_email']),
981+
authored_date=info['author_date'],
989982
committer=Actor._from_string(
990-
info.committer + ' ' + info.committer_email),
991-
committed_date=info.committer_date)
983+
info['committer'] + ' ' + info['committer_email']),
984+
committed_date=info['committer_date'])
992985
commits[sha] = c
993986
blames[-1][0] = c
994987
# END if commit objects needs initial creation
995-
if not is_binary:
996-
if line_str and line_str[0] == '\t':
997-
line_str = line_str[1:]
998-
line_AnyStr: str | bytes = line_str
999-
else:
1000-
line_AnyStr = line_bytes
1001-
# NOTE: We are actually parsing lines out of binary data, which can lead to the
1002-
# binary being split up along the newline separator. We will append this to the
1003-
# blame we are currently looking at, even though it should be concatenated with
1004-
# the last line we have seen.
1005-
1006-
# end handle line contents
1007988
if blames[-1][1] is not None:
1008-
blames[-1][1].append(line_AnyStr)
989+
if not is_binary:
990+
if line_str and line_str[0] == '\t':
991+
line_str = line_str[1:]
992+
993+
blames[-1][1].append(line_str)
994+
else:
995+
# NOTE: We are actually parsing lines out of binary data, which can lead to the
996+
# binary being split up along the newline separator. We will append this to the
997+
# blame we are currently looking at, even though it should be concatenated with
998+
# the last line we have seen.
999+
blames[-1][1].append(line_bytes)
1000+
# end handle line contents
10091001

1010-
info.id = sha
1002+
info = {'id': sha}
10111003
# END if we collected commit info
10121004
# END distinguish filename,summary,rest
10131005
# END distinguish author|committer vs filename,summary,rest

0 commit comments

Comments
 (0)