Skip to content

Commit d4a9eab

Browse files
committed
Make Commit.message bytes | str
1 parent da7c4aa commit d4a9eab

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

‎git/objects/commit.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, tree: 'Tree' = None,
8787
committer: Union[Actor, None] =None,
8888
committed_date: Union[int, None] =None,
8989
committer_tz_offset: Union[None, float] =None,
90-
message: Union[str, None] =None,
90+
message: Union[str, bytes, None] =None,
9191
parents: Union[Sequence['Commit'], None] =None,
9292
encoding: Union[str, None] =None,
9393
gpgsig: Union[str, None] =None) ->None:
@@ -209,9 +209,12 @@ def committed_datetime(self) -> 'datetime.datetime':
209209
returnfrom_timestamp(self.committed_date, self.committer_tz_offset)
210210

211211
@property
212-
defsummary(self) ->str:
212+
defsummary(self) ->Union[str, bytes]:
213213
""":return: First line of the commit message"""
214-
returnself.message.split('\n', 1)[0]
214+
ifisinstance(self.message, str):
215+
returnself.message.split('\n', 1)[0]
216+
else:
217+
returnself.message.split(b'\n', 1)[0]
215218

216219
defcount(self, paths: Union[PathLike, Sequence[PathLike]] ='', **kwargs: Any) ->int:
217220
"""Count the number of commits reachable from this commit
@@ -590,12 +593,12 @@ def _deserialize(self, stream: BytesIO) -> 'Commit':
590593

591594
# a stream from our data simply gives us the plain message
592595
# The end of our message stream is marked with a newline that we strip
593-
self.message_bytes=stream.read()
596+
self.message=stream.read()
594597
try:
595-
self.message=self.message_bytes.decode(self.encoding, 'replace')
598+
self.message=self.message.decode(self.encoding, 'replace')
596599
exceptUnicodeDecodeError:
597600
log.error("Failed to decode message '%s' using encoding %s",
598-
self.message_bytes, self.encoding, exc_info=True)
601+
self.message, self.encoding, exc_info=True)
599602
# END exception handling
600603

601604
returnself

0 commit comments

Comments
(0)