Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d7a40f

Browse files
committed
Merge pull request#411 from nvie/enrich-incremental-blame-output
Enrich incremental blame output
2 parents4adafc5 +8da7852 commit0d7a40f

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

‎git/repo/base.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@
6060
importos
6161
importsys
6262
importre
63+
fromcollectionsimportnamedtuple
6364

6465
DefaultDBType=GitCmdObjectDB
6566
ifsys.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 ofBlameEntry 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 ofBlameEntry 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
whileTrue:
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
ifhexshanotincommits:
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
iftag==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-
assertline.startswith(b'filename'),'Unexpected git blame output'
714-
715-
yieldcommits[hexsha],range(lineno,lineno+num_lines)
718+
tag,value=line.split(b' ',1)
719+
asserttag==b'filename','Unexpected git blame output'
720+
orig_filename=value
721+
722+
yieldBlameEntry(commits[hexsha],
723+
range(lineno,lineno+num_lines),
724+
safe_decode(orig_filename),
725+
range(orig_lineno,orig_lineno+num_lines))
716726

717727
defblame(self,rev,file,incremental=False,**kwargs):
718728
"""The blame information for the given file at the given revision.

‎git/test/test_repo.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,19 @@ def test_blame_incremental(self, git):
341341
assertlen(blame_output)==5
342342

343343
# Check all outputted line numbers
344-
ranges=flatten([line_numbersfor_,line_numbersinblame_output])
344+
ranges=flatten([entry.linenosforentryinblame_output])
345345
assertranges==flatten([range(2,3),range(14,15),range(1,2),range(3,14),range(15,17)]),str(ranges)
346346

347-
commits= [c.hexsha[:7]forc,_inblame_output]
347+
commits= [entry.commit.hexsha[:7]forentryinblame_output]
348348
assertcommits== ['82b8902','82b8902','c76852d','c76852d','c76852d'],str(commits)
349349

350+
# Original filenames
351+
assertall([entry.orig_path==u'AUTHORS'forentryinblame_output])
352+
353+
# Original line numbers
354+
orig_ranges=flatten([entry.orig_linenosforentryinblame_output])
355+
assertorig_ranges==flatten([range(2,3),range(14,15),range(1,2),range(2,13),range(13,15)]),str(orig_ranges)# noqa
356+
350357
@patch.object(Git,'_call_process')
351358
deftest_blame_complex_revision(self,git):
352359
git.return_value=fixture('blame_complex_revision')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp