diff --git a/vcsserver/remote/git_remote.py b/vcsserver/remote/git_remote.py --- a/vcsserver/remote/git_remote.py +++ b/vcsserver/remote/git_remote.py @@ -40,7 +40,7 @@ from dulwich.repo import Repo as Dulwich import rhodecode from vcsserver import exceptions, settings, subprocessio -from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes, convert_to_str +from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes, convert_to_str, splitnewlines from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, store_archive_in_cache, BytesEnvelope, BinaryEnvelope from vcsserver.hgcompat import ( hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) @@ -1347,7 +1347,8 @@ class GitRemote(RemoteBase): with repo_init as repo: commit = repo[commit_id] blame_obj = repo.blame(path, newest_commit=commit_id) - for i, line in enumerate(commit.tree[path].data.splitlines()): + file_content = commit.tree[path].data + for i, line in enumerate(splitnewlines(file_content)): line_no = i + 1 hunk = blame_obj.for_line(line_no) blame_commit_id = hunk.final_commit_id.hex diff --git a/vcsserver/str_utils.py b/vcsserver/str_utils.py --- a/vcsserver/str_utils.py +++ b/vcsserver/str_utils.py @@ -142,3 +142,17 @@ def convert_to_str(data): return list(convert_to_str(item) for item in data) else: return data + + +def splitnewlines(text: bytes): + """ + like splitlines, but only split on newlines. + """ + + lines = [_l + b'\n' for _l in text.split(b'\n')] + if lines: + if lines[-1] == b'\n': + lines.pop() + else: + lines[-1] = lines[-1][:-1] + return lines