summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksandr Usov <oleksandr.usov@tibra.com>2011-10-21 10:35:03 +0100
committerOleksandr Usov <oleksandr.usov@tibra.com>2011-10-21 10:35:03 +0100
commitab6fdb93582f85ccf482d6d1bfefad7a54384e2f (patch)
treea0b81d1be960e391db1c8be9dc4ce8c83d607ea0
parent415445fe306084a2ea0c1f5a204646e8728c2e76 (diff)
downloadpython-fastimport-ab6fdb93582f85ccf482d6d1bfefad7a54384e2f.tar.gz
Rename flag to squash_empty_commits and add few more tests with includes/excludes
-rw-r--r--fastimport/processors/filter_processor.py16
-rw-r--r--fastimport/tests/test_filter_processor.py127
2 files changed, 126 insertions, 17 deletions
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py
index e007046..5076519 100644
--- a/fastimport/processors/filter_processor.py
+++ b/fastimport/processors/filter_processor.py
@@ -37,22 +37,22 @@ class FilterProcessor(processor.ImportProcessor):
* exclude_paths - a list of paths that should not appear in the output
stream
- * preserve_all_history - if True filter processeor will be much more conservative
- w.r.t. history handling -- it will preserve all commits and links between them,
- including those to unknown revisions. This is primarily usefull for filtering
- incremental streams
+ * squash_empty_commits - if set to False, filter processor will be much more
+ conservative w.r.t. history handling -- it will preserve all commits and
+ links between them, including those to unknown revisions. This is primarily
+ usefull for filtering incremental streams
"""
known_params = [
'include_paths',
'exclude_paths',
- 'preserve_all_history'
+ 'squash_empty_commits'
]
def pre_process(self):
self.includes = self.params.get('include_paths')
self.excludes = self.params.get('exclude_paths')
- self.preserve_all_history = bool(self.params.get('preserve_all_history'))
+ 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
@@ -98,7 +98,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 or self.preserve_all_history:
+ 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):
@@ -116,7 +116,7 @@ class FilterProcessor(processor.ImportProcessor):
self.referenced_blobs.append(fc.dataref)
# Update from and merges to refer to commits in the output
- if not self.preserve_all_history:
+ if self.squash_empty_commits:
cmd.from_ = self._find_interesting_from(cmd.from_)
cmd.merges = self._find_interesting_merges(cmd.merges)
self.interesting_commits.add(cmd.id)
diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py
index 4472424..53d82a0 100644
--- a/fastimport/tests/test_filter_processor.py
+++ b/fastimport/tests/test_filter_processor.py
@@ -917,7 +917,7 @@ committer Joe <joe@example.com> 1234567890 +1000
data 19
unknown from commit
from :999
-M 644 :2 DATA
+M 644 :2 data/DATA
blob
mark :99
data 4
@@ -930,12 +930,12 @@ merge commit
from :3
merge :4
merge :1001
-M 644 :99 DATA2
+M 644 :99 data/DATA2
"""
-class TestPreserveHistoryFlag(TestCaseWithFiltering):
+class TestSquashEmptyCommitsFlag(TestCaseWithFiltering):
- def test_squashing_empty_commits(self):
+ def test_squash_empty_commit(self):
params = {'include_paths': None, 'exclude_paths': None}
self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \
"""blob
@@ -950,8 +950,8 @@ Initial import
M 644 :1 COPYING
""")
- def test_keep_empty_commits(self):
- params = {'include_paths': None, 'exclude_paths': None, 'preserve_all_history': True}
+ 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):
@@ -976,7 +976,7 @@ mark :4
committer Joe <joe@example.com> 1234567890 +1000
data 19
unknown from commit
-M 644 :2 DATA
+M 644 :2 data/DATA
blob
mark :99
data 4
@@ -988,9 +988,118 @@ data 12
merge commit
from :3
merge :4
-M 644 :99 DATA2
+M 644 :99 data/DATA2
""")
def test_keep_unresolved_from_and_merge(self):
- params = {'include_paths': None, 'exclude_paths': None, 'preserve_all_history': True}
+ 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
+""")