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

Enrich incremental blame output#411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nvie merged 3 commits intogitpython-developers:masterfromnvie:enrich-incremental-blame-output
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletionsgit/repo/base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,12 +60,15 @@
import os
import sys
import re
from collections import namedtuple

DefaultDBType = GitCmdObjectDB
if sys.version_info[:2] < (2, 5): # python 2.4 compatiblity
DefaultDBType = GitCmdObjectDB
# END handle python 2.4

BlameEntry = namedtuple('BlameEntry', ['commit', 'linenos', 'orig_path', 'orig_linenos'])


__all__ = ('Repo', )

Expand DownExpand Up@@ -661,10 +664,10 @@ def blame_incremental(self, rev, file, **kwargs):
"""Iterator for blame information for the given file at the given revision.

Unlike .blame(), this does not return the actual file's contents, only
a stream of(commit, range) tuples.
a stream ofBlameEntry tuples.

:parm rev: revision specifier, see git-rev-parse for viable options.
:return: lazy iterator of(git.Commit, range) tuples, where the commit
:return: lazy iterator ofBlameEntry tuples, where the commit
indicates the commit to blame for the line, and range
indicates a span of line numbers in the resulting file.

Expand All@@ -678,9 +681,10 @@ def blame_incremental(self, rev, file, **kwargs):
while True:
line = next(stream) # when exhausted, casues a StopIteration, terminating this function

hexsha,_, lineno, num_lines = line.split()
hexsha,orig_lineno, lineno, num_lines = line.split()
lineno = int(lineno)
num_lines = int(num_lines)
orig_lineno = int(orig_lineno)
if hexsha not in commits:
# Now read the next few lines and build up a dict of properties
# for this commit
Expand All@@ -696,6 +700,7 @@ def blame_incremental(self, rev, file, **kwargs):
props[tag] = value
if tag == b'filename':
# "filename" formally terminates the entry for --incremental
orig_filename = value
break

c = Commit(self, hex_to_bin(hexsha),
Expand All@@ -710,9 +715,14 @@ def blame_incremental(self, rev, file, **kwargs):
else:
# Discard the next line (it's a filename end tag)
line = next(stream)
assert line.startswith(b'filename'), 'Unexpected git blame output'

yield commits[hexsha], range(lineno, lineno + num_lines)
tag, value = line.split(b' ', 1)
assert tag == b'filename', 'Unexpected git blame output'
orig_filename = value

yield BlameEntry(commits[hexsha],
range(lineno, lineno + num_lines),
safe_decode(orig_filename),
range(orig_lineno, orig_lineno + num_lines))

def blame(self, rev, file, incremental=False, **kwargs):
"""The blame information for the given file at the given revision.
Expand Down
11 changes: 9 additions & 2 deletionsgit/test/test_repo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -341,12 +341,19 @@ def test_blame_incremental(self, git):
assert len(blame_output) == 5

# Check all outputted line numbers
ranges = flatten([line_numbers for_, line_numbers in blame_output])
ranges = flatten([entry.linenos forentry in blame_output])
assert ranges == flatten([range(2, 3), range(14, 15), range(1, 2), range(3, 14), range(15, 17)]), str(ranges)

commits = [c.hexsha[:7] forc, _ in blame_output]
commits = [entry.commit.hexsha[:7] forentry in blame_output]
assert commits == ['82b8902', '82b8902', 'c76852d', 'c76852d', 'c76852d'], str(commits)

# Original filenames
assert all([entry.orig_path == u'AUTHORS' for entry in blame_output])

# Original line numbers
orig_ranges = flatten([entry.orig_linenos for entry in blame_output])
assert orig_ranges == flatten([range(2, 3), range(14, 15), range(1, 2), range(2, 13), range(13, 15)]), str(orig_ranges) # noqa

@patch.object(Git, '_call_process')
def test_blame_complex_revision(self, git):
git.return_value = fixture('blame_complex_revision')
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp