From e5b8220a1a967abdf2bae2124e3e22a9eea3729f Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 13 Apr 2016 14:52:18 +0200 Subject: Add incremental blame support This adds a sibling method to Repo's blame method: Repo.blame_incremental(rev, path, **kwargs) This can alternatively be called using: Repo.blame(rev, path, incremental=True) The main difference is that blame incremental is a bit more efficient and does not return the full file's contents, just the commits and the line number ranges. The parser is a bit more straight-forward and faster since the incremental output format is defined a little stricter. --- git/test/test_repo.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'git/test/test_repo.py') diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 177aa176..ab6c502f 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -50,6 +50,16 @@ from io import BytesIO from nose import SkipTest +def iter_flatten(lol): + for items in lol: + for item in items: + yield item + + +def flatten(lol): + return list(iter_flatten(lol)) + + class TestRepo(TestBase): @raises(InvalidGitRepositoryError) @@ -323,6 +333,20 @@ class TestRepo(TestBase): assert c, "Should have executed at least one blame command" assert nml, "There should at least be one blame commit that contains multiple lines" + @patch.object(Git, '_call_process') + def test_blame_incremental(self, git): + git.return_value = fixture('blame_incremental') + blame_output = self.rorepo.blame_incremental('9debf6b0aafb6f7781ea9d1383c86939a1aacde3', 'AUTHORS') + blame_output = list(blame_output) + assert len(blame_output) == 5 + + # Check all outputted line numbers + ranges = flatten([line_numbers for _, line_numbers 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] for c, _ in blame_output] + assert commits == ['82b8902', '82b8902', 'c76852d', 'c76852d', 'c76852d'], str(commits) + @patch.object(Git, '_call_process') def test_blame_complex_revision(self, git): git.return_value = fixture('blame_complex_revision') -- cgit v1.2.1