From 73ab28744df3fc292a71c3099ff1f3a20471f188 Mon Sep 17 00:00:00 2001 From: Jonathan Chu Date: Tue, 24 May 2016 11:19:14 -0400 Subject: Split lines by new line characters Opt to split lines by the new line character instead of letting `splitlines()` do this. This helps catch the issue when there are special characters in the line, particular the commit summary section. --- git/repo/base.py | 6 ++++-- git/test/fixtures/blame_incremental | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/git/repo/base.py b/git/repo/base.py index c2bd2a62..af3050bf 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -682,10 +682,12 @@ class Repo(object): data = self.git.blame(rev, '--', file, p=True, incremental=True, stdout_as_string=False, **kwargs) commits = dict() - stream = iter(data.splitlines()) + stream = iter(data.split(b'\n')) while True: line = next(stream) # when exhausted, casues a StopIteration, terminating this function - + if line.strip() == '': + # Skip over empty lines + continue hexsha, orig_lineno, lineno, num_lines = line.split() lineno = int(lineno) num_lines = int(num_lines) diff --git a/git/test/fixtures/blame_incremental b/git/test/fixtures/blame_incremental index 9a0d9e35..67310aec 100644 --- a/git/test/fixtures/blame_incremental +++ b/git/test/fixtures/blame_incremental @@ -7,7 +7,7 @@ committer Sebastian Thiel committer-mail committer-time 1270634931 committer-tz +0200 -summary Used this release for a first beta of the 0.2 branch of development +summary Used this release for a first beta of the 0.2 branch of development previous 501bf602abea7d21c3dbb409b435976e92033145 AUTHORS filename AUTHORS 82b8902e033430000481eb355733cd7065342037 14 14 1 -- cgit v1.2.1 From 903826a50d401d8829912e4bcd8412b8cdadac02 Mon Sep 17 00:00:00 2001 From: Jonathan Chu Date: Tue, 24 May 2016 12:02:13 -0400 Subject: Check if byte string is empty for py3 compatibility --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/repo/base.py b/git/repo/base.py index af3050bf..32ee830e 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -685,7 +685,7 @@ class Repo(object): stream = iter(data.split(b'\n')) while True: line = next(stream) # when exhausted, casues a StopIteration, terminating this function - if line.strip() == '': + if line.strip() == '' or line.strip() == b'': # Skip over empty lines continue hexsha, orig_lineno, lineno, num_lines = line.split() -- cgit v1.2.1 From 187fe114585be2d367a81997509b40e62fdbc18e Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 24 May 2016 19:27:32 +0200 Subject: Ignore trailing last empty string in .split() output --- git/repo/base.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/git/repo/base.py b/git/repo/base.py index 32ee830e..bc5a7c35 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -682,12 +682,9 @@ class Repo(object): data = self.git.blame(rev, '--', file, p=True, incremental=True, stdout_as_string=False, **kwargs) commits = dict() - stream = iter(data.split(b'\n')) + stream = (line for line in data.split(b'\n') if line) while True: line = next(stream) # when exhausted, casues a StopIteration, terminating this function - if line.strip() == '' or line.strip() == b'': - # Skip over empty lines - continue hexsha, orig_lineno, lineno, num_lines = line.split() lineno = int(lineno) num_lines = int(num_lines) -- cgit v1.2.1