Rev 5967: Cleanups and fixes for merging into null tree. (Aaron Bentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Jun 10 16:20:01 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5967 [merge]
revision-id: pqm at pqm.ubuntu.com-20110610161957-hh5ni839m7r3wsan
parent: pqm at pqm.ubuntu.com-20110609164645-q3ix2ryp0a2qd0de
parent: aaron at aaronbentley.com-20110610150641-mtdo60oui07hezsc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-06-10 16:19:57 +0000
message:
Cleanups and fixes for merging into null tree. (Aaron Bentley)
modified:
bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
bzrlib/tests/blackbox/test_update.py test_update.py-20060212125639-c4dad1a5c56d5919
bzrlib/tests/test_mutabletree.py test_mutabletree.py-20080405014429-2v0cdi3re320p8db-1
bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
bzrlib/tests/test_shelf_ui.py test_shelf_ui.py-20081027155203-wtcuazg85wp9u4fv-1
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py 2011-02-26 15:39:49 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py 2011-06-10 15:06:41 +0000
@@ -19,6 +19,7 @@
from bzrlib import (
branchbuilder,
tag,
+ transform,
)
from bzrlib.branch import (
Branch,
@@ -123,10 +124,11 @@
def make_fork(self, branch):
fork = branch.create_clone_on_transport(self.get_transport('fork'))
- builder = branchbuilder.BranchBuilder(branch=fork)
- builder.build_commit(message='Commit in fork.', rev_id='fork-0')
- fork.set_last_revision_info(1, 'rev-1')
- builder.build_commit(message='Commit in fork.', rev_id='fork-1')
+ self.addCleanup(fork.lock_write().unlock)
+ with transform.TransformPreview(fork.basis_tree()) as tt:
+ tt.commit(fork, message='Commit in fork.', revision_id='fork-0')
+ with transform.TransformPreview(fork.basis_tree()) as tt:
+ tt.commit(fork, message='Commit in fork.', revision_id='fork-1')
return fork
def test_merge_without_commit_does_not_propagate_tags_to_master(self):
=== modified file 'bzrlib/tests/blackbox/test_update.py'
--- a/bzrlib/tests/blackbox/test_update.py 2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/blackbox/test_update.py 2011-06-10 08:11:44 +0000
@@ -140,10 +140,9 @@
# smoke test for doing an update of a checkout of a bound
# branch with local commits.
master = self.make_branch_and_tree('master')
+ master.commit('first commit')
# make a bound branch
self.run_bzr('checkout master child')
- # get an object form of child
- child = workingtree.WorkingTree.open('child')
# check that out
self.run_bzr('checkout --lightweight child checkout')
# get an object form of the checkout to manipulate
@@ -158,6 +157,8 @@
a_file = file('child/file_b', 'wt')
a_file.write('Foo')
a_file.close()
+ # get an object form of child
+ child = workingtree.WorkingTree.open('child')
child.add(['file_b'])
child_tip = child.commit('add file_b', local=True)
# check checkout
@@ -174,7 +175,7 @@
All changes applied successfully.
+N file
All changes applied successfully.
-Updated to revision 1 of branch %s
+Updated to revision 2 of branch %s
Your local commits will now show as pending merges with 'bzr status', and can be committed with 'bzr commit'.
""" % osutils.pathjoin(self.test_dir, 'master',),
err)
=== modified file 'bzrlib/tests/test_mutabletree.py'
--- a/bzrlib/tests/test_mutabletree.py 2011-03-30 11:45:54 +0000
+++ b/bzrlib/tests/test_mutabletree.py 2011-06-09 18:46:24 +0000
@@ -55,9 +55,8 @@
self.assertTrue(self.tree.has_changes())
def test_with_pending_merges(self):
+ self.tree.commit('first commit')
other_tree = self.tree.bzrdir.sprout('other').open_workingtree()
- self.build_tree(['other/file'])
- other_tree.add('file')
- other_tree.commit('added file')
+ other_tree.commit('mergeable commit')
self.tree.merge_from_branch(other_tree.branch)
self.assertTrue(self.tree.has_changes())
=== modified file 'bzrlib/tests/test_reconfigure.py'
--- a/bzrlib/tests/test_reconfigure.py 2009-10-06 14:40:37 +0000
+++ b/bzrlib/tests/test_reconfigure.py 2011-06-10 08:11:44 +0000
@@ -46,10 +46,9 @@
def test_tree_with_pending_merge_to_branch(self):
tree = self.make_branch_and_tree('tree')
+ tree.commit('unchanged')
other_tree = tree.bzrdir.sprout('other').open_workingtree()
- self.build_tree(['other/file'])
- other_tree.add('file')
- other_tree.commit('file added')
+ other_tree.commit('mergeable commit')
tree.merge_from_branch(other_tree.branch)
reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
=== modified file 'bzrlib/tests/test_shelf_ui.py'
--- a/bzrlib/tests/test_shelf_ui.py 2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/test_shelf_ui.py 2011-06-09 14:40:22 +0000
@@ -63,7 +63,7 @@
LINES_AY = 'a\nb\nc\nd\ne\nf\ng\nh\ni\ny\n'
-class TestShelver(tests.TestCaseWithTransport):
+class ShelfTestCase(tests.TestCaseWithTransport):
def create_shelvable_tree(self):
tree = self.make_branch_and_tree('tree')
@@ -73,6 +73,9 @@
self.build_tree_contents([('tree/foo', LINES_ZY)])
return tree
+
+class TestShelver(ShelfTestCase):
+
def test_unexpected_prompt_failure(self):
tree = self.create_shelvable_tree()
tree.lock_tree_write()
@@ -327,7 +330,7 @@
outer_tree, rev2)
-class TestApplyReporter(TestShelver):
+class TestApplyReporter(ShelfTestCase):
def test_shelve_not_diff(self):
tree = self.create_shelvable_tree()
=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py 2011-06-02 07:25:33 +0000
+++ b/bzrlib/tests/test_transform.py 2011-06-10 16:19:57 +0000
@@ -1599,6 +1599,38 @@
return template % ('<' * 7, tree, '=' * 7, merge, '>' * 7)
+class TestInventoryAltered(tests.TestCaseWithTransport):
+
+ def test_inventory_altered_unchanged(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/foo'])
+ tree.add('foo', 'foo-id')
+ with TransformPreview(tree) as tt:
+ self.assertEqual([], tt._inventory_altered())
+
+ def test_inventory_altered_changed_parent_id(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/foo'])
+ tree.add('foo', 'foo-id')
+ with TransformPreview(tree) as tt:
+ tt.unversion_file(tt.root)
+ tt.version_file('new-id', tt.root)
+ foo_trans_id = tt.trans_id_tree_file_id('foo-id')
+ foo_tuple = ('foo', foo_trans_id)
+ root_tuple = ('', tt.root)
+ self.assertEqual([root_tuple, foo_tuple], tt._inventory_altered())
+
+ def test_inventory_altered_noop_changed_parent_id(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/foo'])
+ tree.add('foo', 'foo-id')
+ with TransformPreview(tree) as tt:
+ tt.unversion_file(tt.root)
+ tt.version_file(tree.get_root_id(), tt.root)
+ foo_trans_id = tt.trans_id_tree_file_id('foo-id')
+ self.assertEqual([], tt._inventory_altered())
+
+
class TestTransformMerge(TestCaseInTempDir):
def test_text_merge(self):
=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py 2011-06-02 07:25:33 +0000
+++ b/bzrlib/transform.py 2011-06-10 16:19:57 +0000
@@ -137,6 +137,14 @@
# A counter of how many files have been renamed
self.rename_count = 0
+ def __enter__(self):
+ """Support Context Manager API."""
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Support Context Manager API."""
+ self.finalize()
+
def finalize(self):
"""Release the working tree lock, if held.
@@ -384,18 +392,44 @@
return sorted(FinalPaths(self).get_paths(new_ids))
def _inventory_altered(self):
- """Get the trans_ids and paths of files needing new inv entries."""
- new_ids = set()
- for id_set in [self._new_name, self._new_parent, self._new_id,
+ """Determine which trans_ids need new Inventory entries.
+
+ An new entry is needed when anything that would be reflected by an
+ inventory entry changes, including file name, file_id, parent file_id,
+ file kind, and the execute bit.
+
+ Some care is taken to return entries with real changes, not cases
+ where the value is deleted and then restored to its original value,
+ but some actually unchanged values may be returned.
+
+ :returns: A list of (path, trans_id) for all items requiring an
+ inventory change. Ordered by path.
+ """
+ changed_ids = set()
+ # Find entries whose file_ids are new (or changed).
+ new_file_id = set(t for t in self._new_id
+ if self._new_id[t] != self.tree_file_id(t))
+ for id_set in [self._new_name, self._new_parent, new_file_id,
self._new_executability]:
- new_ids.update(id_set)
+ changed_ids.update(id_set)
+ # removing implies a kind change
changed_kind = set(self._removed_contents)
+ # so does adding
changed_kind.intersection_update(self._new_contents)
- changed_kind.difference_update(new_ids)
+ # Ignore entries that are already known to have changed.
+ changed_kind.difference_update(changed_ids)
+ # to keep only the truly changed ones
changed_kind = (t for t in changed_kind
if self.tree_kind(t) != self.final_kind(t))
- new_ids.update(changed_kind)
- return sorted(FinalPaths(self).get_paths(new_ids))
+ # all kind changes will alter the inventory
+ changed_ids.update(changed_kind)
+ # To find entries with changed parent_ids, find parents which existed,
+ # but changed file_id.
+ changed_file_id = set(t for t in new_file_id if t in self._removed_id)
+ # Now add all their children to the set.
+ for parent_trans_id in new_file_id:
+ changed_ids.update(self.iter_tree_children(parent_trans_id))
+ return sorted(FinalPaths(self).get_paths(changed_ids))
def final_kind(self, trans_id):
"""Determine the final file kind, after any changes applied.
More information about the bazaar-commits
mailing list