6060import os
6161import sys
6262import re
63+ from collections import namedtuple
6364
6465DefaultDBType = GitCmdObjectDB
6566if sys .version_info [:2 ] < (2 , 5 ): # python 2.4 compatiblity
6667 DefaultDBType = GitCmdObjectDB
6768# END handle python 2.4
6869
70+ BlameEntry = namedtuple ('BlameEntry' , ['commit' , 'linenos' , 'orig_path' , 'orig_linenos' ])
71+
6972
7073__all__ = ('Repo' , )
7174
@@ -661,10 +664,10 @@ def blame_incremental(self, rev, file, **kwargs):
661664 """Iterator for blame information for the given file at the given revision.
662665
663666 Unlike .blame(), this does not return the actual file's contents, only
664- a stream of (commit, range) tuples.
667+ a stream of BlameEntry tuples.
665668
666669 :parm rev: revision specifier, see git-rev-parse for viable options.
667- :return: lazy iterator of (git.Commit, range) tuples, where the commit
670+ :return: lazy iterator of BlameEntry tuples, where the commit
668671 indicates the commit to blame for the line, and range
669672 indicates a span of line numbers in the resulting file.
670673
@@ -678,9 +681,10 @@ def blame_incremental(self, rev, file, **kwargs):
678681 while True :
679682 line = next (stream ) # when exhausted, casues a StopIteration, terminating this function
680683
681- hexsha , _ , lineno , num_lines = line .split ()
684+ hexsha , orig_lineno , lineno , num_lines = line .split ()
682685 lineno = int (lineno )
683686 num_lines = int (num_lines )
687+ orig_lineno = int (orig_lineno )
684688 if hexsha not in commits :
685689 # Now read the next few lines and build up a dict of properties
686690 # for this commit
@@ -696,6 +700,7 @@ def blame_incremental(self, rev, file, **kwargs):
696700 props [tag ] = value
697701 if tag == b'filename' :
698702 # "filename" formally terminates the entry for --incremental
703+ orig_filename = value
699704 break
700705
701706 c = Commit (self , hex_to_bin (hexsha ),
@@ -710,9 +715,14 @@ def blame_incremental(self, rev, file, **kwargs):
710715 else :
711716 # Discard the next line (it's a filename end tag)
712717 line = next (stream )
713- assert line .startswith (b'filename' ), 'Unexpected git blame output'
714-
715- yield commits [hexsha ], range (lineno , lineno + num_lines )
718+ tag , value = line .split (b' ' , 1 )
719+ assert tag == b'filename' , 'Unexpected git blame output'
720+ orig_filename = value
721+
722+ yield BlameEntry (commits [hexsha ],
723+ range (lineno , lineno + num_lines ),
724+ safe_decode (orig_filename ),
725+ range (orig_lineno , orig_lineno + num_lines ))
716726
717727 def blame (self , rev , file , incremental = False , ** kwargs ):
718728 """The blame information for the given file at the given revision.
0 commit comments