From 7506ef9e3745ccbdcbafddeaa1f7ff1d4ecae703 Mon Sep 17 00:00:00 2001 From: Sushant Mimani Date: Wed, 20 Oct 2021 11:59:49 -0700 Subject: [PATCH] Revert _iter_diff_index rename --- docs/source/api.rst | 2 +- tartufo/scanner.py | 8 ++++---- tests/test_git_repo_scanner.py | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index f1dfc06d..c1ea98b3 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -17,7 +17,7 @@ tartufo.scanner .. automodule:: tartufo.scanner :inherited-members: :members: - :private-members: _iter_diff + :private-members: _iter_diff_index :show-inheritance: :undoc-members: diff --git a/tartufo/scanner.py b/tartufo/scanner.py index 947f56d1..825dea8d 100755 --- a/tartufo/scanner.py +++ b/tartufo/scanner.py @@ -481,7 +481,7 @@ def __init__(self, global_options: types.GlobalOptions, repo_path: str) -> None: super().__init__(global_options) self._repo = self.load_repo(self.repo_path) - def _iter_diff(self, diff: pygit2.Diff) -> Generator[Tuple[str, str], None, None]: + def _iter_diff_index(self, diff: pygit2.Diff) -> Generator[Tuple[str, str], None, None]: """Iterate over a "diff index", yielding the individual file changes. A "diff index" is essentially analogous to a single commit in the git @@ -648,7 +648,7 @@ def chunks(self) -> Generator[types.Chunk, None, None]: if diff_hash in already_searched: continue already_searched.add(diff_hash) - for blob, file_path in self._iter_diff(diff): + for blob, file_path in self._iter_diff_index(diff): yield types.Chunk( blob, file_path, @@ -659,7 +659,7 @@ def chunks(self) -> Generator[types.Chunk, None, None]: if curr_commit: tree: pygit2.Tree = self._repo.revparse_single(curr_commit.hex).tree tree_diff: pygit2.Diff = tree.diff_to_tree() - iter_diff = self._iter_diff(tree_diff) + iter_diff = self._iter_diff_index(tree_diff) for blob, file_path in iter_diff: yield types.Chunk( blob, @@ -693,7 +693,7 @@ def chunks(self): :rtype: Generator[Chunk, None, None] """ diff_index = self._repo.diff("HEAD") - for blob, file_path in self._iter_diff(diff_index): + for blob, file_path in self._iter_diff_index(diff_index): yield types.Chunk(blob, file_path, {}) diff --git a/tests/test_git_repo_scanner.py b/tests/test_git_repo_scanner.py index 0a99153a..ef7845fe 100644 --- a/tests/test_git_repo_scanner.py +++ b/tests/test_git_repo_scanner.py @@ -191,7 +191,7 @@ def test_explicit_exception_is_raised_if_fetch_fails( for _ in test_scanner.chunks: pass - @mock.patch("tartufo.scanner.GitScanner._iter_diff") + @mock.patch("tartufo.scanner.GitScanner._iter_diff_index") @mock.patch("pygit2.Repository") def test_all_branches_are_scanned_for_commits( self, mock_repo: mock.MagicMock, mock_iter_diff: mock.MagicMock @@ -236,7 +236,7 @@ def test_all_branches_are_scanned_for_commits( ) ) - @mock.patch("tartufo.scanner.GitRepoScanner._iter_diff") + @mock.patch("tartufo.scanner.GitRepoScanner._iter_diff_index") @mock.patch("pygit2.Repository") def test_all_commits_are_scanned_for_files( self, @@ -277,7 +277,7 @@ def test_all_commits_are_scanned_for_files( ) ) - @mock.patch("tartufo.scanner.GitRepoScanner._iter_diff") + @mock.patch("tartufo.scanner.GitRepoScanner._iter_diff_index") @mock.patch("tartufo.util.extract_commit_metadata") @mock.patch("pygit2.Repository") def test_all_files_are_yielded_as_chunks( @@ -325,7 +325,7 @@ def test_binary_files_are_skipped(self): test_scanner = scanner.GitRepoScanner( self.global_options, self.git_options, "." ) - diffs = list(test_scanner._iter_diff([mock_diff])) + diffs = list(test_scanner._iter_diff_index([mock_diff])) self.assertEqual(diffs, []) @mock.patch("pygit2.Repository", new=mock.MagicMock()) @@ -337,7 +337,7 @@ def test_excluded_files_are_not_scanned(self, mock_should: mock.MagicMock): test_scanner = scanner.GitRepoScanner( self.global_options, self.git_options, "." ) - diffs = list(test_scanner._iter_diff([mock_diff])) + diffs = list(test_scanner._iter_diff_index([mock_diff])) self.assertEqual(diffs, []) mock_should.assert_called_once() @@ -360,7 +360,7 @@ def test_all_files_are_yielded(self, mock_should: mock.MagicMock): test_scanner = scanner.GitRepoScanner( self.global_options, self.git_options, "." ) - diffs = list(test_scanner._iter_diff([mock_diff_1, mock_diff_2])) + diffs = list(test_scanner._iter_diff_index([mock_diff_1, mock_diff_2])) self.assertEqual( diffs, [