diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2011-10-22 14:47:22 -0700 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2011-10-22 14:47:22 -0700 |
commit | b652c9c28529d7d0b0d5146bb07f9253e427ab64 (patch) | |
tree | a430987e6a05a3628ed1f60892f815f964717350 | |
parent | 59c7d26570b35843c9c0f05ec8d33beead00d270 (diff) | |
parent | 23079098b160d57b04afc242d626838495cbffd3 (diff) | |
download | python-fastimport-git-b652c9c28529d7d0b0d5146bb07f9253e427ab64.tar.gz |
Merge support for squash_empty_commit argument to FilterProcessor.
-rw-r--r-- | fastimport/processors/filter_processor.py | 8 | ||||
-rw-r--r-- | fastimport/tests/test_filter_processor.py | 233 |
2 files changed, 238 insertions, 3 deletions
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py index f26e273..b84a009 100644 --- a/fastimport/processors/filter_processor.py +++ b/fastimport/processors/filter_processor.py @@ -36,16 +36,22 @@ class FilterProcessor(processor.ImportProcessor): * exclude_paths - a list of paths that should not appear in the output stream + + * squash_empty_commits - if set to False, squash commits that don't have + any changes after the filter has been applied """ known_params = [ 'include_paths', 'exclude_paths', + 'squash_empty_commits' ] def pre_process(self): self.includes = self.params.get('include_paths') self.excludes = self.params.get('exclude_paths') + self.squash_empty_commits = bool( + self.params.get('squash_empty_commits', True)) # What's the new root, if any self.new_root = helpers.common_directory(self.includes) # Buffer of blobs until we know we need them: mark -> cmd @@ -91,7 +97,7 @@ class FilterProcessor(processor.ImportProcessor): """Process a CommitCommand.""" # These pass through if they meet the filtering conditions interesting_filecmds = self._filter_filecommands(cmd.iter_files) - if interesting_filecmds: + if interesting_filecmds or not self.squash_empty_commits: # If all we have is a single deleteall, skip this commit if len(interesting_filecmds) == 1 and isinstance( interesting_filecmds[0], commands.FileDeleteAllCommand): diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py index c3ae21e..d6508f2 100644 --- a/fastimport/tests/test_filter_processor.py +++ b/fastimport/tests/test_filter_processor.py @@ -102,7 +102,6 @@ M 644 :3 doc/README.txt M 644 :4 doc/index.txt """ - class TestCaseWithFiltering(TestCase): def assertFiltering(self, input, params, expected): @@ -116,7 +115,6 @@ class TestCaseWithFiltering(TestCase): out = outf.getvalue() self.assertEquals(expected, out) - class TestNoFiltering(TestCaseWithFiltering): def test_params_not_given(self): @@ -877,3 +875,234 @@ reset refs/heads/foo reset refs/heads/bar from :101 """) + + +# A sample input stream containing empty commit +_SAMPLE_EMPTY_COMMIT = \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :2 +committer Joe <joe@example.com> 1234567890 +1000 +data 14 +Initial import +M 644 :1 COPYING +commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +empty commit +""" + +# A sample input stream containing unresolved from and merge references +_SAMPLE_FROM_MERGE_COMMIT = \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 6 +import +M 644 :1 COPYING +blob +mark :2 +data 4 +bar +commit refs/heads/master +mark :4 +committer Joe <joe@example.com> 1234567890 +1000 +data 19 +unknown from commit +from :999 +M 644 :2 data/DATA +blob +mark :99 +data 4 +bar +commit refs/heads/master +mark :5 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +merge commit +from :3 +merge :4 +merge :1001 +M 644 :99 data/DATA2 +""" + +class TestSquashEmptyCommitsFlag(TestCaseWithFiltering): + + def test_squash_empty_commit(self): + params = {'include_paths': None, 'exclude_paths': None} + self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :2 +committer Joe <joe@example.com> 1234567890 +1000 +data 14 +Initial import +M 644 :1 COPYING +""") + + def test_keep_empty_commit(self): + params = {'include_paths': None, 'exclude_paths': None, 'squash_empty_commits': False} + self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT) + + def test_squash_unresolved_references(self): + params = {'include_paths': None, 'exclude_paths': None} + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 6 +import +M 644 :1 COPYING +blob +mark :2 +data 4 +bar +commit refs/heads/master +mark :4 +committer Joe <joe@example.com> 1234567890 +1000 +data 19 +unknown from commit +from :999 +M 644 :2 data/DATA +blob +mark :99 +data 4 +bar +commit refs/heads/master +mark :5 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +merge commit +from :3 +merge :4 +merge :1001 +M 644 :99 data/DATA2 +""") + + def test_keep_unresolved_from_and_merge(self): + params = {'include_paths': None, 'exclude_paths': None, 'squash_empty_commits': False} + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT) + + def test_with_excludes(self): + params = {'include_paths': None, + 'exclude_paths': ['data/DATA'], + 'squash_empty_commits': False} + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 6 +import +M 644 :1 COPYING +commit refs/heads/master +mark :4 +committer Joe <joe@example.com> 1234567890 +1000 +data 19 +unknown from commit +from :999 +blob +mark :99 +data 4 +bar +commit refs/heads/master +mark :5 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +merge commit +from :3 +merge :4 +merge :1001 +M 644 :99 data/DATA2 +""") + + def test_with_file_includes(self): + params = {'include_paths': ['COPYING', 'data/DATA2'], + 'exclude_paths': None, + 'squash_empty_commits': False} + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ +"""blob +mark :1 +data 4 +foo +commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 6 +import +M 644 :1 COPYING +commit refs/heads/master +mark :4 +committer Joe <joe@example.com> 1234567890 +1000 +data 19 +unknown from commit +from :999 +blob +mark :99 +data 4 +bar +commit refs/heads/master +mark :5 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +merge commit +from :3 +merge :4 +merge :1001 +M 644 :99 data/DATA2 +""" +) + + def test_with_directory_includes(self): + params = {'include_paths': ['data/'], + 'exclude_paths': None, + 'squash_empty_commits': False} + self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \ +"""commit refs/heads/master +mark :3 +committer Joe <joe@example.com> 1234567890 +1000 +data 6 +import +blob +mark :2 +data 4 +bar +commit refs/heads/master +mark :4 +committer Joe <joe@example.com> 1234567890 +1000 +data 19 +unknown from commit +from :999 +M 644 :2 DATA +blob +mark :99 +data 4 +bar +commit refs/heads/master +mark :5 +committer Joe <joe@example.com> 1234567890 +1000 +data 12 +merge commit +from :3 +merge :4 +merge :1001 +M 644 :99 DATA2 +""") |