Rev 5857: A few more bug fixes. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-set-parent-trees-delta-282941
John Arbash Meinel
john at arbash-meinel.com
Wed May 18 09:52:47 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.4-set-parent-trees-delta-282941
------------------------------------------------------------
revno: 5857
revision-id: john at arbash-meinel.com-20110518095244-og67674lnpf6djxo
parent: john at arbash-meinel.com-20110518054743-8pmdzxrp3omroswn
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-set-parent-trees-delta-282941
timestamp: Wed 2011-05-18 11:52:44 +0200
message:
A few more bug fixes.
Handle when a location changes file_id. We were looking up the path
in the active tree, we need to look it up in the basis_tree.
Add a direct test for the 'switch' case, which is when setting
a parent_tree to something new, and the basis_tree is no longer
in the available repository.
Add a couple more direct successful delta checks. (most of the
test_inv tests were just about failing with bad deltas.)
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2011-05-17 13:17:39 +0000
+++ b/bzrlib/dirstate.py 2011-05-18 09:52:44 +0000
@@ -1416,7 +1416,8 @@
# _get_entry raises BzrError when a request is inconsistent; we
# want such errors to be shown as InconsistentDelta - and that
# fits the behaviour we trigger.
- raise errors.InconsistentDeltaDelta(delta, "error from _get_entry.")
+ raise errors.InconsistentDeltaDelta(delta,
+ "error from _get_entry. %s" % (e,))
def _apply_removals(self, removals):
for file_id, path in sorted(removals, reverse=True,
@@ -1600,11 +1601,10 @@
if 'integrity error' not in str(e):
raise
# _get_entry raises BzrError when a request is inconsistent; we
- # want such errors to be shown as InconsistentDelta - and that
- # fits the behaviour we trigger. Partof this is driven by dirstate
- # only supporting deltas that turn the basis into a closer fit to
- # the active tree.
- raise errors.InconsistentDeltaDelta(delta, "error from _get_entry.")
+ # want such errors to be shown as InconsistentDelta - and that
+ # fits the behaviour we trigger.
+ raise errors.InconsistentDeltaDelta(delta,
+ "error from _get_entry. %s" % (e,))
self._mark_modified(header_modified=True)
self._id_index = None
@@ -1650,20 +1650,21 @@
# adds is now in lexographic order, which places all parents before
# their children, so we can process it linearly.
absent = 'ar'
+ st = static_tuple.StaticTuple
for old_path, new_path, file_id, new_details, real_add in adds:
- # the entry for this file_id must be in tree 0.
- entry = self._get_entry(0, file_id, new_path)
+ entry = self._get_entry(1, file_id, new_path)
if entry[0] is None:
- # new_path is not versioned in the active WT state,
- # but we are adding it to the basis tree state, we
- # need to create a new entry record for it.
+ # entry_key (dirname, basename, file_id) doesn't exist in any
+ # tree yet, so we need to create a new record.
dirname, basename = osutils.split(new_path)
- entry_key = (dirname, basename, file_id)
+ entry_key = st(dirname, basename, file_id)
_, block = self._find_block(entry_key, add_if_missing=True)
index, _ = self._find_entry_index(entry_key, block)
entry = (entry_key, [DirState.NULL_PARENT_DETAILS]*2)
block.insert(index, entry)
elif entry[0][2] != file_id:
+ # This should never trigger, because we pass file_id in to
+ # _get_entry which will raise its own exception.
self._changes_aborted = True
raise errors.InconsistentDelta(new_path, file_id,
'working tree does not contain new entry')
@@ -2019,7 +2020,8 @@
entry_index += 1
return block_index, entry_index, True, False
- def _get_entry(self, tree_index, fileid_utf8=None, path_utf8=None, include_deleted=False):
+ def _get_entry(self, tree_index, fileid_utf8=None, path_utf8=None,
+ include_deleted=False):
"""Get the dirstate entry for path in tree tree_index.
If either file_id or path is supplied, it is used as the key to lookup.
=== modified file 'bzrlib/tests/test_inv.py'
--- a/bzrlib/tests/test_inv.py 2011-05-17 11:27:58 +0000
+++ b/bzrlib/tests/test_inv.py 2011-05-18 09:52:44 +0000
@@ -336,6 +336,13 @@
inv.root.revision = 'basis'
return inv
+ def make_file_ie(self, file_id='file-id', name='name', parent_id=None):
+ ie_file = inventory.InventoryFile(file_id, name, parent_id)
+ ie_file.revision = 'result'
+ ie_file.text_size = 0
+ ie_file.text_sha1 = ''
+ return ie_file
+
def test_empty_delta(self):
inv = self.get_empty_inventory()
delta = []
@@ -365,10 +372,8 @@
file1.revision = 'result'
file1.text_size = 0
file1.text_sha1 = ""
- file2 = inventory.InventoryFile('id', 'path2', inv.root.file_id)
- file2.revision = 'result'
- file2.text_size = 0
- file2.text_sha1 = ""
+ file2 = file1.copy()
+ file2.name = 'path2'
delta = [(None, u'path1', 'id', file1), (None, u'path2', 'id', file2)]
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
inv, delta)
@@ -379,10 +384,8 @@
file1.revision = 'result'
file1.text_size = 0
file1.text_sha1 = ""
- file2 = inventory.InventoryFile('id2', 'path', inv.root.file_id)
- file2.revision = 'result'
- file2.text_size = 0
- file2.text_sha1 = ""
+ file2 = file1.copy()
+ file2.file_id = 'id2'
delta = [(None, u'path', 'id1', file1), (None, u'path', 'id2', file2)]
self.assertRaises(errors.InconsistentDelta, self.apply_delta, self,
inv, delta)
@@ -584,18 +587,24 @@
def test_rename_file(self):
inv = self.get_empty_inventory()
- file1 = inventory.InventoryFile('file-id', 'path', inv.root.file_id)
- file1.revision = 'result'
- file1.text_size = 0
- file1.text_sha1 = ''
+ file1 = self.make_file_ie(name='path', parent_id=inv.root.file_id)
inv.add(file1)
- file2 = file1.copy()
- file2.name = 'path2'
+ file2 = self.make_file_ie(name='path2', parent_id=inv.root.file_id)
delta = [(u'path', 'path2', 'file-id', file2)]
res_inv = self.apply_delta(self, inv, delta)
self.assertEqual(None, res_inv.path2id('path'))
self.assertEqual('file-id', res_inv.path2id('path2'))
+ def test_replaced_at_new_path(self):
+ inv = self.get_empty_inventory()
+ file1 = self.make_file_ie(file_id='id1', parent_id=inv.root.file_id)
+ inv.add(file1)
+ file2 = self.make_file_ie(file_id='id2', parent_id=inv.root.file_id)
+ delta = [(u'name', None, 'id1', None),
+ (None, u'name', 'id2', file2)]
+ res_inv = self.apply_delta(self, inv, delta)
+ self.assertEqual('id2', res_inv.path2id('name'))
+
def test_is_root(self):
"""Ensure our root-checking code is accurate."""
inv = inventory.Inventory('TREE_ROOT')
=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py 2011-05-10 18:08:53 +0000
+++ b/bzrlib/tests/test_workingtree_4.py 2011-05-18 09:52:44 +0000
@@ -294,6 +294,32 @@
self.assertEqual('a-id', basis.path2id('a'))
self.assertEqual('b-id', basis.path2id('b'))
+ def test_set_parent_trees_handles_missing_basis(self):
+ builder = self.make_branch_builder('source')
+ builder.start_series()
+ self.addCleanup(builder.finish_series)
+ builder.build_snapshot('A', [], [
+ ('add', ('', 'root-id', 'directory', None)),
+ ('add', ('a', 'a-id', 'file', 'content\n'))])
+ builder.build_snapshot('B', ['A'], [
+ ('modify', ('a-id', 'new content\nfor a\n')),
+ ('add', ('b', 'b-id', 'file', 'b-content\n'))])
+ builder.build_snapshot('C', ['A'], [
+ ('add', ('c', 'c-id', 'file', 'c-content\n'))])
+ b_c = self.make_branch('branch_with_c')
+ b_c.pull(builder.get_branch(), stop_revision='C')
+ b_b = self.make_branch('branch_with_b')
+ b_b.pull(builder.get_branch(), stop_revision='B')
+ # This is reproducing some of what 'switch' does, just to isolate the
+ # set_parent_trees() step.
+ wt = b_b.create_checkout('tree', lightweight=True)
+ fmt = wt.bzrdir.find_branch_format()
+ fmt.set_reference(wt.bzrdir, None, b_c)
+ # Re-open with the new reference
+ wt = wt.bzrdir.open_workingtree()
+ wt.set_parent_trees([('C', b_c.repository.revision_tree('C'))])
+ self.assertEqual(None, wt.basis_tree().path2id('b'))
+
def test_new_dirstate_on_new_lock(self):
# until we have detection for when a dirstate can be reused, we
# want to reparse dirstate on every new lock.
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2011-05-18 05:47:43 +0000
+++ b/bzrlib/workingtree_4.py 2011-05-18 09:52:44 +0000
@@ -1158,7 +1158,9 @@
try:
basis_tree = self.branch.repository.revision_tree(basis_id)
except errors.NoSuchRevision:
- pass # Fallback to set_parent_trees
+ # Fall back to the set_parent_trees(), since we can't use
+ # _make_delta if we can't get the RevisionTree
+ pass
else:
delta = rev_tree.inventory._make_delta(basis_tree.inventory)
dirstate.update_basis_by_delta(delta, rev_id)
More information about the bazaar-commits
mailing list