Skip to content

Commit

Permalink
Bugfix: avoid splitlines in blame (#1015)
Browse files Browse the repository at this point in the history
* fix: split blame output by "\n" explicitly

This avoid additional "line break" symbols in source code from being
considered as line breaks in our parser. Git seems to only ever
consider '\n' as a newline character, but python's "splitlines()" method
considers many others by default.

Refs:
https://github.com/python/cpython/blob/3.4/Objects/unicodetype_db.h#L4317-L4338
https://github.com/git/git/blob/master/blame.c#L1633-L1637

* fix: skip empty last line while parsing blame
  • Loading branch information
asfaltboy authored and randy3k committed Oct 1, 2018
1 parent f526598 commit f8b65c8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/commands/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_content(self, ignore_whitespace=False, detect_options=None, commit_hash=
commit_hash, "--", filename_at_commit
)
blame_porcelain = unicodedata.normalize('NFC', blame_porcelain)
blamed_lines, commits = self.parse_blame(blame_porcelain.splitlines())
blamed_lines, commits = self.parse_blame(blame_porcelain.split('\n'))

commit_infos = {
commit_hash: self.short_commit_info(commit)
Expand Down Expand Up @@ -250,6 +250,9 @@ def get_content(self, ignore_whitespace=False, detect_options=None, commit_hash=
return spacer.join(partitions_with_commits_iter)

def parse_blame(self, blame_porcelain):
if blame_porcelain[-1] == '':
blame_porcelain = blame_porcelain[:-1]

lines_iter = iter(blame_porcelain)

blamed_lines = []
Expand Down

0 comments on commit f8b65c8

Please sign in to comment.