At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.4/ ------------------------------------------------------------ revno: 6077 [merge] revision-id: p...@pqm.ubuntu.com-20130529072208-27hyd1xzk2ygmlkh parent: p...@pqm.ubuntu.com-20130528070151-u41ave93eai032av parent: j...@arbash-meinel.com-20130529060235-d7rpolm1tx7t55ok committer: Patch Queue Manager <p...@pqm.ubuntu.com> branch nick: 2.4 timestamp: Wed 2013-05-29 07:22:08 +0000 message: (jameinel) Fix bug #855155. Dirstate.update_basis_by_delta needs to handle adding entries to directories that were otherwise empty (in all trees). (John A Meinel) modified: bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1 bzrlib/tests/blackbox/test_uncommit.py test_uncommit.py-20051027212835-84944b63adae51be bzrlib/tests/per_workingtree/test_parents.py test_set_parents.py-20060807231740-yicmnlci1mj8smu1-1 bzrlib/tests/test_dirstate.py test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2 === modified file 'bzrlib/dirstate.py' --- a/bzrlib/dirstate.py 2013-05-19 11:45:42 +0000 +++ b/bzrlib/dirstate.py 2013-05-29 07:22:08 +0000 @@ -1690,9 +1690,18 @@ entry_key = st(dirname, basename, file_id) block_index, present = self._find_block_index_from_key(entry_key) if not present: - self._raise_invalid(new_path, file_id, - "Unable to find block for this record." - " Was the parent added?") + # The block where we want to put the file is not present. + # However, it might have just been an empty directory. Look for + # the parent in the basis-so-far before throwing an error. + parent_dir, parent_base = osutils.split(dirname) + parent_block_idx, parent_entry_idx, _, parent_present = \ + self._get_block_entry_index(parent_dir, parent_base, 1) + if not parent_present: + self._raise_invalid(new_path, file_id, + "Unable to find block for this record." + " Was the parent added?") + self._ensure_block(parent_block_idx, parent_entry_idx, dirname) + block = self._dirblocks[block_index][1] entry_index, present = self._find_entry_index(entry_key, block) if real_add:
=== modified file 'bzrlib/tests/blackbox/test_uncommit.py' --- a/bzrlib/tests/blackbox/test_uncommit.py 2010-09-15 09:35:42 +0000 +++ b/bzrlib/tests/blackbox/test_uncommit.py 2013-05-28 08:11:13 +0000 @@ -280,3 +280,20 @@ tree.commit(u'\u1234 message') out, err = self.run_bzr('uncommit --force tree', encoding='ascii') self.assertContainsRe(out, r'\? message') + + +class TestInconsistentDelta(TestCaseWithTransport): + # See https://bugs.launchpad.net/bzr/+bug/855155 + # See https://bugs.launchpad.net/bzr/+bug/1100385 + # bzr uncommit may result in error + # 'An inconsistent delta was supplied involving' + + def test_inconsistent_delta(self): + # Script taken from https://bugs.launchpad.net/bzr/+bug/855155/comments/26 + wt = self.make_branch_and_tree('test') + self.build_tree(['test/a/', 'test/a/b', 'test/a/c']) + wt.add(['a', 'a/b', 'a/c']) + wt.commit('initial commit', rev_id='a1') + wt.remove(['a/b', 'a/c']) + wt.commit('remove b and c', rev_id='a2') + self.run_bzr("uncommit --force test") === modified file 'bzrlib/tests/per_workingtree/test_parents.py' --- a/bzrlib/tests/per_workingtree/test_parents.py 2011-05-08 16:02:52 +0000 +++ b/bzrlib/tests/per_workingtree/test_parents.py 2013-05-28 08:11:13 +0000 @@ -449,7 +449,7 @@ self.add_dir(new_shape, new_revid, 'root-id', None, '') def assertTransitionFromBasisToShape(self, basis_shape, basis_revid, - new_shape, new_revid, extra_parent=None): + new_shape, new_revid, extra_parent=None, set_current_inventory=True): # set the inventory revision ids. basis_shape.revision_id = basis_revid new_shape.revision_id = new_revid @@ -464,8 +464,9 @@ parents.append(extra_parent) tree.set_parent_ids(parents) self.fake_up_revision(tree, new_revid, new_shape) - # give tree an inventory of new_shape - tree._write_inventory(new_shape) + if set_current_inventory: + # give tree an inventory of new_shape + tree._write_inventory(new_shape) self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid, delta, new_shape) # The tree should be internally consistent; while this is a moderately @@ -756,3 +757,17 @@ self.add_link(new_shape, old_revid, 'link-id-C', 'dir-id-B', 'C', 'D') self.assertTransitionFromBasisToShape(basis_shape, old_revid, new_shape, new_revid) + + def test_add_files_to_empty_directory(self): + old_revid = 'old-parent' + basis_shape = Inventory(root_id=None) + self.add_dir(basis_shape, old_revid, 'root-id', None, '') + self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A') + new_revid = 'new-parent' + new_shape = Inventory(root_id=None) + self.add_new_root(new_shape, old_revid, new_revid) + self.add_dir(new_shape, old_revid, 'dir-id-A', 'root-id', 'A') + self.add_file(new_shape, new_revid, 'file-id-B', 'dir-id-A', 'B', + '1' * 32, 24) + self.assertTransitionFromBasisToShape(basis_shape, old_revid, + new_shape, new_revid, set_current_inventory=False) === modified file 'bzrlib/tests/test_dirstate.py' --- a/bzrlib/tests/test_dirstate.py 2011-05-25 13:44:28 +0000 +++ b/bzrlib/tests/test_dirstate.py 2013-05-29 06:02:35 +0000 @@ -2477,7 +2477,12 @@ def create_tree_from_shape(self, rev_id, shape): dir_ids = {'': 'root-id'} inv = inventory.Inventory('root-id', rev_id) - for path, file_id in shape: + for info in shape: + if len(info) == 2: + path, file_id = info + ie_rev_id = rev_id + else: + path, file_id, ie_rev_id = info if path == '': # Replace the root entry del inv._byid[inv.root.file_id] @@ -2485,7 +2490,7 @@ inv._byid[file_id] = inv.root dir_ids[''] = file_id continue - inv.add(self.path_to_ie(path, file_id, rev_id, dir_ids)) + inv.add(self.path_to_ie(path, file_id, ie_rev_id, dir_ids)) return revisiontree.InventoryRevisionTree(_Repo(), inv, rev_id) def create_empty_dirstate(self): @@ -2613,6 +2618,13 @@ target=[('file', 'file-id')], ) + def test_add_file_in_empty_dir_not_matching_active_state(self): + state = self.assertUpdate( + active=[], + basis=[('dir/', 'dir-id')], + target=[('dir/', 'dir-id', 'basis'), ('dir/file', 'file-id')], + ) + def test_add_file_missing_in_active_state(self): state = self.assertUpdate( active=[], -- bazaar-commits mailing list bazaar-commits@lists.canonical.com https://lists.ubuntu.com/mailman/listinfo/bazaar-commits