Skip to content

Ignore all lines of subsequent hunks until last one is found #602

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 7, 2017
Merged
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,14 @@ def blame_incremental(self, rev, file, **kwargs):
committed_date=int(props[b'committer-time']))
commits[hexsha] = c
else:
# Discard the next line (it's a filename end tag)
line = next(stream)
tag, value = line.split(b' ', 1)
assert tag == b'filename', 'Unexpected git blame output'
orig_filename = value
# Discard all lines until we find "filename" which is
# guaranteed to be the last line
while True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this loops break-condition is not clearly defined just now.
Do you think 'end-of-stream' could be another one?

What do you think of something like this:

for line in stream:
	tag, value = line.split(b' ', 1)
	if tag == b'filename':
		orig_filename = value
		break
		
# Finally handle the case of the stream being exhausted too early

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment in 77b20be to be more explicit about an unexpected EOF condition. With a for loop we'd need to raise that exception ourselves in an else block so I think the while loop works better here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now! I didn't know that next throws - iterators do that, right. Have been doing Rust for too long ;).

line = next(stream)
tag, value = line.split(b' ', 1)
if tag == b'filename':
orig_filename = value
break

yield BlameEntry(commits[hexsha],
range(lineno, lineno + num_lines),
Expand Down