@@ -587,14 +587,28 @@ def blame(self, rev, file):
587587 A list of tuples associating a Commit object with a list of lines that
588588 changed within the given commit. The Commit objects will be given in order
589589 of appearance."""
590- data = self .git .blame (rev , '--' , file , p = True )
590+ data = self .git .blame (rev , '--' , file , p = True , stdout_as_string = False )
591591 commits = dict ()
592592 blames = list ()
593593 info = None
594594
595- for line in data .splitlines (False ):
596- parts = self .re_whitespace .split (line , 1 )
597- firstpart = parts [0 ]
595+ keepends = True
596+ for line in data .splitlines (keepends ):
597+ try :
598+ line = line .rstrip ().decode (defenc )
599+ except UnicodeDecodeError :
600+ firstpart = ''
601+ is_binary = True
602+ else :
603+ # As we don't have an idea when the binary data ends, as it could contain multiple newlines
604+ # in the process. So we rely on being able to decode to tell us what is is.
605+ # This can absolutely fail even on text files, but even if it does, we should be fine treating it
606+ # as binary instead
607+ parts = self .re_whitespace .split (line , 1 )
608+ firstpart = parts [0 ]
609+ is_binary = False
610+ # end handle decode of line
611+
598612 if self .re_hexsha_only .search (firstpart ):
599613 # handles
600614 # 634396b2f541a9f2d58b00be1a07f0c358b999b3 1 1 7 - indicates blame-data start
@@ -651,10 +665,18 @@ def blame(self, rev, file):
651665 message = info ['summary' ])
652666 commits [sha ] = c
653667 # END if commit objects needs initial creation
654- m = self .re_tab_full_line .search (line )
655- text , = m .groups ()
668+ if not is_binary :
669+ if line and line [0 ] == '\t ' :
670+ line = line [1 :]
671+ else :
672+ # NOTE: We are actually parsing lines out of binary data, which can lead to the
673+ # binary being split up along the newline separator. We will append this to the blame
674+ # we are currently looking at, even though it should be concatenated with the last line
675+ # we have seen.
676+ pass
677+ # end handle line contents
656678 blames [- 1 ][0 ] = c
657- blames [- 1 ][1 ].append (text )
679+ blames [- 1 ][1 ].append (line )
658680 info = {'id' : sha }
659681 # END if we collected commit info
660682 # END distinguish filename,summary,rest
0 commit comments