Rev 3786: CommitBuilder unmodified items are not spuriously recorded as changing. in http://people.ubuntu.com/~robertc/baz2.0/commit-iterchanges
Robert Collins
robertc at robertcollins.net
Tue Nov 18 04:54:57 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/commit-iterchanges
------------------------------------------------------------
revno: 3786
revision-id: robertc at robertcollins.net-20081118045452-yez2rt18bozvsv27
parent: robertc at robertcollins.net-20081118042340-iwb4oeouxbkfmrxk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit-iterchanges
timestamp: Tue 2008-11-18 15:54:52 +1100
message:
CommitBuilder unmodified items are not spuriously recorded as changing.
modified:
bzrlib/tests/per_repository/test_commit_builder.py test_commit_builder.py-20060606110838-76e3ra5slucqus81-1
=== modified file 'bzrlib/tests/per_repository/test_commit_builder.py'
--- a/bzrlib/tests/per_repository/test_commit_builder.py 2008-11-18 04:23:40 +0000
+++ b/bzrlib/tests/per_repository/test_commit_builder.py 2008-11-18 04:54:52 +0000
@@ -413,6 +413,9 @@
def test_root_entry_has_revision(self):
# test the root revision created and put in the basis
# has the right rev id.
+ # XXX: RBC 20081118 - this test is too big, it depends on the exact
+ # behaviour of tree methods and so on; it should be written to the
+ # commit builder interface directly.
tree = self.make_branch_and_tree('.')
rev_id = tree.commit('message')
basis_tree = tree.basis_tree()
@@ -444,9 +447,11 @@
else:
self.assertEqual(rev2, tree2.inventory.root.revision)
- def _add_commit_check_unchanged(self, tree, name):
+ def _add_commit_check_unchanged(self, tree, name, mini_commit=None):
tree.add([name], [name + 'id'])
rev1 = tree.commit('')
+ if mini_commit is None:
+ mini_commit = self.mini_commit
rev2 = self.mini_commit(tree, name, name, False, False)
tree1, tree2 = self._get_revtrees(tree, [rev1, rev2])
self.assertEqual(rev1, tree1.inventory[name + 'id'].revision)
@@ -462,6 +467,13 @@
self.build_tree(['dir/'])
self._add_commit_check_unchanged(tree, 'dir')
+ def test_last_modified_revision_after_commit_dir_unchanged_ric(self):
+ # committing without changing a dir does not change the last modified.
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['dir/'])
+ self._add_commit_check_unchanged(tree, 'dir',
+ mini_commit=self.mini_commit_record_iter_changes)
+
def test_last_modified_revision_after_commit_dir_contents_unchanged(self):
# committing without changing a dir does not change the last modified
# of the dir even the dirs contents are changed.
@@ -486,6 +498,13 @@
self.build_tree(['file'])
self._add_commit_check_unchanged(tree, 'file')
+ def test_last_modified_revision_after_commit_file_unchanged_ric(self):
+ # committing without changing a file does not change the last modified.
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['file'])
+ self._add_commit_check_unchanged(tree, 'file',
+ mini_commit=self.mini_commit_record_iter_changes)
+
def test_last_modified_revision_after_commit_link_unchanged(self):
# committing without changing a link does not change the last modified.
self.requireFeature(tests.SymlinkFeature)
@@ -493,6 +512,14 @@
os.symlink('target', 'link')
self._add_commit_check_unchanged(tree, 'link')
+ def test_last_modified_revision_after_commit_link_unchanged_ric(self):
+ # committing without changing a link does not change the last modified.
+ self.requireFeature(tests.SymlinkFeature)
+ tree = self.make_branch_and_tree('.')
+ os.symlink('target', 'link')
+ self._add_commit_check_unchanged(tree, 'link',
+ mini_commit=self.mini_commit_record_iter_changes)
+
def _add_commit_renamed_check_changed(self, tree, name,
expect_fs_hash=False):
def rename():
@@ -642,6 +669,63 @@
tree.unlock()
return rev2
+ def mini_commit_record_iter_changes(self, tree, name, new_name,
+ records_version=True, delta_against_basis=True, expect_fs_hash=False):
+ """Perform a miniature commit looking for record entry results.
+
+ This version uses the record_iter_changes interface.
+
+ :param tree: The tree to commit.
+ :param name: The path in the basis tree of the tree being committed.
+ :param new_name: The path in the tree being committed.
+ :param records_version: True if the commit of new_name is expected to
+ record a new version.
+ :param delta_against_basis: True of the commit of new_name is expected
+ to have a delta against the basis.
+ :param expect_fs_hash: ignored, present for compatibility with test
+ driver code for 'mini_commit'.
+ """
+ tree.lock_write()
+ try:
+ # mini manual commit here so we can check the return of
+ # record_entry_contents.
+ parent_ids = tree.get_parent_ids()
+ builder = tree.branch.get_commit_builder(parent_ids)
+ parent_tree = tree.basis_tree()
+ parent_tree.lock_read()
+ self.addCleanup(parent_tree.unlock)
+ parent_invs = [parent_tree.inventory]
+ for parent_id in parent_ids[1:]:
+ parent_invs.append(tree.branch.repository.revision_tree(
+ parent_id).inventory)
+ changes = list(parent_tree.iter_changes(parent_tree))
+ builder.record_iter_changes(tree, parent_ids[0], changes)
+ delta = builder.basis_delta
+ delta_dict = dict((change[2], change) for change in delta)
+ version_recorded = tree.path2id(new_name) in delta_dict
+ if records_version:
+ self.assertTrue(version_recorded)
+ else:
+ self.assertFalse(version_recorded)
+ new_inventory = builder.revision_tree().inventory
+ new_entry = new_inventory[file_id]
+ if delta_against_basis:
+ expected_delta = (name, new_name, file_id, new_entry)
+ self.assertEqual(expected_delta, delta_dict[file_id])
+ else:
+ expected_delta = None
+ self.assertFalse(version_recorded)
+ builder.finish_inventory()
+ rev2 = builder.commit('')
+ tree.set_parent_ids([rev2])
+ except:
+ builder.abort()
+ tree.unlock()
+ raise
+ else:
+ tree.unlock()
+ return rev2
+
def assertFileGraph(self, expected_graph, tree, tip):
# all the changes that have occured should be in the ancestry
# (closest to a public per-file graph API we have today)
More information about the bazaar-commits
mailing list