60
60
import os
61
61
import sys
62
62
import re
63
+ from collections import namedtuple
63
64
64
65
DefaultDBType = GitCmdObjectDB
65
66
if sys .version_info [:2 ]< (2 ,5 ):# python 2.4 compatiblity
66
67
DefaultDBType = GitCmdObjectDB
67
68
# END handle python 2.4
68
69
70
+ BlameEntry = namedtuple ('BlameEntry' , ['commit' ,'linenos' ,'orig_path' ,'orig_linenos' ])
71
+
69
72
70
73
__all__ = ('Repo' , )
71
74
@@ -661,10 +664,10 @@ def blame_incremental(self, rev, file, **kwargs):
661
664
"""Iterator for blame information for the given file at the given revision.
662
665
663
666
Unlike .blame(), this does not return the actual file's contents, only
664
- a stream of(commit, range) tuples.
667
+ a stream ofBlameEntry tuples.
665
668
666
669
: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 ofBlameEntry tuples, where the commit
668
671
indicates the commit to blame for the line, and range
669
672
indicates a span of line numbers in the resulting file.
670
673
@@ -678,9 +681,10 @@ def blame_incremental(self, rev, file, **kwargs):
678
681
while True :
679
682
line = next (stream )# when exhausted, casues a StopIteration, terminating this function
680
683
681
- hexsha ,_ ,lineno ,num_lines = line .split ()
684
+ hexsha ,orig_lineno ,lineno ,num_lines = line .split ()
682
685
lineno = int (lineno )
683
686
num_lines = int (num_lines )
687
+ orig_lineno = int (orig_lineno )
684
688
if hexsha not in commits :
685
689
# Now read the next few lines and build up a dict of properties
686
690
# for this commit
@@ -696,6 +700,7 @@ def blame_incremental(self, rev, file, **kwargs):
696
700
props [tag ]= value
697
701
if tag == b'filename' :
698
702
# "filename" formally terminates the entry for --incremental
703
+ orig_filename = value
699
704
break
700
705
701
706
c = Commit (self ,hex_to_bin (hexsha ),
@@ -710,9 +715,14 @@ def blame_incremental(self, rev, file, **kwargs):
710
715
else :
711
716
# Discard the next line (it's a filename end tag)
712
717
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 ))
716
726
717
727
def blame (self ,rev ,file ,incremental = False ,** kwargs ):
718
728
"""The blame information for the given file at the given revision.