Rev 4506: Take review comments into account. in file:///home/vila/src/bzr/experimental/tree-has-changes/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Jul 8 14:36:29 BST 2009
At file:///home/vila/src/bzr/experimental/tree-has-changes/
------------------------------------------------------------
revno: 4506
revision-id: v.ladeuil+lp at free.fr-20090708133629-hb2ipu8s13ek0bm7
parent: v.ladeuil+lp at free.fr-20090702130714-hsyqfusi8vn3a11m
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: tree-has-changes
timestamp: Wed 2009-07-08 15:36:29 +0200
message:
Take review comments into account.
* bzrlib/tests/intertree_implementations/test_compare.py:
(TestIterChanges.check_has_changes): Test has_changes only if one
the trees is mutable.
* bzrlib/tree.py:
(Tree.has_changes): Moved to MutableTree.
* bzrlib/mutabletree.py:
(MutableTree.has_changes): Moved from Tree as required.
-------------- next part --------------
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/mutabletree.py 2009-07-08 13:36:29 +0000
@@ -233,6 +233,23 @@
raise NotImplementedError(self._gather_kinds)
@needs_read_lock
+ def has_changes(self, from_tree):
+ """Quickly check that the tree contains at least one change.
+
+ :return: True if a change is found. False otherwise
+ """
+ changes = self.iter_changes(from_tree)
+ try:
+ change = changes.next()
+ # Exclude root (talk about black magic... --vila 20090629)
+ if change[4] == (None, None):
+ change = changes.next()
+ return True
+ except StopIteration:
+ # No changes
+ return False
+
+ @needs_read_lock
def last_revision(self):
"""Return the revision id of the last commit performed in this tree.
=== modified file 'bzrlib/tests/intertree_implementations/test_compare.py'
--- a/bzrlib/tests/intertree_implementations/test_compare.py 2009-07-02 10:28:58 +0000
+++ b/bzrlib/tests/intertree_implementations/test_compare.py 2009-07-08 13:36:29 +0000
@@ -21,6 +21,7 @@
from bzrlib import (
errors,
+ mutabletree,
tests,
workingtree_4,
)
@@ -367,11 +368,21 @@
tree1.unlock()
tree2.unlock()
- def do_has_changes(self, tree1, tree2, **extra_args):
+ def check_has_changes(self, expected, tree1, tree2):
+ # has_changes is defined for mutable trees only
+ print '\nt1, t2: %r, %r' % (type(tree1), type(tree2))
+ if not isinstance(tree2, mutabletree.MutableTree):
+ if isinstance(tree1, mutabletree.MutableTree):
+ # Let's switch the trees since has_changes() is commutative
+ # (where we can apply it)
+ tree2, tree1 = tree1, tree2
+ else:
+ # Neither tree can be used
+ return
tree1.lock_read()
tree2.lock_read()
try:
- return tree1.has_changes(tree2)
+ return tree2.has_changes(tree1)
finally:
tree1.unlock()
tree2.unlock()
@@ -445,7 +456,7 @@
tree2 = self.get_tree_no_parents_no_content(tree2)
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
self.assertEqual([], self.do_iter_changes(tree1, tree2))
- self.assertEquals(False, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(False, tree1, tree2)
def added(self, tree, file_id):
path, entry = self.get_path_entry(tree, file_id)
@@ -529,7 +540,7 @@
self.added(tree2, 'c-id'),
self.deleted(tree1, 'empty-root-id')])
self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_empty_specific_files(self):
tree1 = self.make_branch_and_tree('1')
@@ -553,7 +564,7 @@
self.added(tree2, 'c-id'),
self.deleted(tree1, 'empty-root-id')])
self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_empty_to_abc_content_a_only(self):
tree1 = self.make_branch_and_tree('1')
@@ -605,7 +616,7 @@
self.assertEqual(
expected_results,
self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_content_modification(self):
tree1 = self.make_branch_and_tree('1')
@@ -618,7 +629,7 @@
(root_id, root_id), ('a', 'a'),
('file', 'file'), (False, False))],
self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_meta_modification(self):
tree1 = self.make_branch_and_tree('1')
@@ -848,7 +859,7 @@
self.content_changed(tree2, 'c-id'),
])
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_unversioned_paths_in_tree(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1066,7 +1077,7 @@
self.assertEqual(expected,
self.do_iter_changes(tree1, tree2, include_unchanged=True,
want_unversioned=True))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_versioned_symlinks_specific_files(self):
self.requireFeature(tests.SymlinkFeature)
@@ -1088,20 +1099,20 @@
self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
specific_files=['added', 'changed', 'fromdir', 'fromfile',
'removed', 'unchanged', 'todir', 'tofile']))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_tree_with_special_names(self):
tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_trees_with_special_names(self):
tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
if f_id.endswith('_f-id'))
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_trees_with_deleted_dir(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1125,7 +1136,7 @@
self.deleted(tree1, 'e-id'),
])
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_added_unicode(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1154,7 +1165,7 @@
self.assertEqual([self.added(tree2, added_id)],
self.do_iter_changes(tree1, tree2,
specific_files=[u'\u03b1']))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_deleted_unicode(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1183,7 +1194,7 @@
self.assertEqual([self.deleted(tree1, deleted_id)],
self.do_iter_changes(tree1, tree2,
specific_files=[u'\u03b1']))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_modified_unicode(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1213,7 +1224,7 @@
self.assertEqual([self.content_changed(tree1, mod_id)],
self.do_iter_changes(tree1, tree2,
specific_files=[u'\u03b1']))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_renamed_unicode(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1244,7 +1255,7 @@
self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
self.do_iter_changes(tree1, tree2,
specific_files=[u'\u03b1']))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_unchanged_unicode(self):
tree1 = self.make_branch_and_tree('tree1')
@@ -1333,7 +1344,7 @@
want_unversioned=True))
self.assertEqual([], # Without want_unversioned we should get nothing
self.do_iter_changes(tree1, tree2))
- self.assertEquals(False, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(False, tree1, tree2)
# We should also be able to select just a subset
expected = sorted([
@@ -1414,7 +1425,7 @@
])
self.assertEqual(expected,
self.do_iter_changes(tree1, tree2))
- self.assertEquals(True, self.do_has_changes(tree1, tree2))
+ self.check_has_changes(True, tree1, tree2)
def test_deleted_and_unknown(self):
"""Test a file marked removed, but still present on disk."""
=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py 2009-07-02 10:28:58 +0000
+++ b/bzrlib/tree.py 2009-07-08 13:36:29 +0000
@@ -104,24 +104,6 @@
return intertree.iter_changes(include_unchanged, specific_files, pb,
extra_trees, require_versioned, want_unversioned=want_unversioned)
-
- @needs_read_lock
- def has_changes(self, from_tree):
- """Quickly check that the tree contains at least one change.
-
- :return: True if a change is found. False otherwise
- """
- changes = self.iter_changes(from_tree)
- try:
- change = changes.next()
- # Exclude root (talk about black magic... --vila 20090629)
- if change[4] == (None, None):
- change = changes.next()
- return True
- except StopIteration:
- # No changes
- return False
-
def conflicts(self):
"""Get a list of the conflicts in the tree.
More information about the bazaar-commits
mailing list