Rev 4735: Fix a bug in the dirstate logic for 'set_path_id'. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-dirstate-set-root-504390
John Arbash Meinel
john at arbash-meinel.com
Tue Jan 12 20:51:36 GMT 2010
At http://bazaar.launchpad.net/~jameinel/bzr/2.0.4-dirstate-set-root-504390
------------------------------------------------------------
revno: 4735
revision-id: john at arbash-meinel.com-20100112205114-wheq3y5gaxkpny2i
parent: john at arbash-meinel.com-20100112202527-d0zy7nmx0hbqjpqa
fixes bug(s): https://launchpad.net/bugs/504390
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.4-dirstate-set-root-504390
timestamp: Tue 2010-01-12 14:51:14 -0600
message:
Fix a bug in the dirstate logic for 'set_path_id'.
It was a bit tricky to sort out, because it depends on the sort order
of sets. Basically 'set_path_id' was accidentally adding the old
file-id a a location to get the entry for the new file-id.
And then the _get_entry lookup would see that the entry was
absent in the given tree (because it doesn't validate that the
file-id for the entry line actually matches the file-id supplied).
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2009-10-01 00:56:56 +0000
+++ b/bzrlib/dirstate.py 2010-01-12 20:51:14 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007, 2008 Canonical Ltd
+# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -1997,6 +1997,8 @@
entry_index, present = self._find_entry_index(key, block)
if present:
entry = self._dirblocks[block_index][1][entry_index]
+ # TODO: We might want to assert that entry[0][2] ==
+ # fileid_utf8.
if entry[1][tree_index][0] in 'fdlt':
# this is the result we are looking for: the
# real home of this file_id in this tree.
@@ -2354,8 +2356,6 @@
self.update_minimal(('', '', new_id), 'd',
path_utf8='', packed_stat=entry[1][0][4])
self._dirblock_state = DirState.IN_MEMORY_MODIFIED
- if self._id_index is not None:
- self._id_index.setdefault(new_id, set()).add(entry[0])
def set_parent_trees(self, trees, ghosts):
"""Set the parent trees for the dirstate.
=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py 2010-01-11 23:14:47 +0000
+++ b/bzrlib/tests/test_dirstate.py 2010-01-12 20:51:14 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007, 2008, 2009, 2010 Canonical Ltd
+# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -879,15 +879,15 @@
self.assertEqual(root_entry,
state._get_entry(0, fileid_utf8='TREE_ROOT'))
self.assertEqual((None, None),
- state._get_entry(0, fileid_utf8='foobarbaz'))
- state.set_path_id('', 'foobarbaz')
- new_root_entry = (('', '', 'foobarbaz'),
+ state._get_entry(0, fileid_utf8='second-root-id'))
+ state.set_path_id('', 'second-root-id')
+ new_root_entry = (('', '', 'second-root-id'),
[('d', '', 0, False, 'x'*32)])
expected_rows = [new_root_entry]
self.assertEqual(expected_rows, list(state._iter_entries()))
self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
self.assertEqual(new_root_entry,
- state._get_entry(0, fileid_utf8='foobarbaz'))
+ state._get_entry(0, fileid_utf8='second-root-id'))
self.assertEqual((None, None),
state._get_entry(0, fileid_utf8='TREE_ROOT'))
# should work across save too
@@ -913,21 +913,36 @@
state._validate()
try:
state.set_parent_trees([('parent-revid', rt)], ghosts=[])
- state.set_path_id('', 'foobarbaz')
+ root_entry = (('', '', 'TREE_ROOT'),
+ [('d', '', 0, False, 'x'*32),
+ ('d', '', 0, False, 'parent-revid')])
+ self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
+ self.assertEqual(root_entry,
+ state._get_entry(0, fileid_utf8='TREE_ROOT'))
+ self.assertEqual((None, None),
+ state._get_entry(0, fileid_utf8='Asecond-root-id'))
+ state.set_path_id('', 'Asecond-root-id')
state._validate()
# now see that it is what we expected
- expected_rows = [
- (('', '', 'TREE_ROOT'),
- [('a', '', 0, False, ''),
- ('d', '', 0, False, 'parent-revid'),
- ]),
- (('', '', 'foobarbaz'),
- [('d', '', 0, False, ''),
- ('a', '', 0, False, ''),
- ]),
- ]
+ old_root_entry = (('', '', 'TREE_ROOT'),
+ [('a', '', 0, False, ''),
+ ('d', '', 0, False, 'parent-revid')])
+ new_root_entry = (('', '', 'Asecond-root-id'),
+ [('d', '', 0, False, ''),
+ ('a', '', 0, False, '')])
+ expected_rows = [new_root_entry, old_root_entry]
state._validate()
self.assertEqual(expected_rows, list(state._iter_entries()))
+ self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
+ self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=''))
+ self.assertEqual((None, None),
+ state._get_entry(0, fileid_utf8='TREE_ROOT'))
+ self.assertEqual(old_root_entry,
+ state._get_entry(1, fileid_utf8='TREE_ROOT'))
+ self.assertEqual(new_root_entry,
+ state._get_entry(0, fileid_utf8='Asecond-root-id'))
+ self.assertEqual((None, None),
+ state._get_entry(1, fileid_utf8='Asecond-root-id'))
# should work across save too
state.save()
finally:
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2009-08-26 05:38:16 +0000
+++ b/bzrlib/workingtree.py 2010-01-12 20:51:14 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
+# Copyright (C) 2005-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -2245,8 +2245,10 @@
basis.lock_read()
try:
to_tree = self.branch.basis_tree()
- if basis.inventory.root is None:
- self.set_root_id(to_tree.get_root_id())
+ to_root_id = to_tree.get_root_id()
+ if (basis.inventory.root is None
+ or basis.inventory.root.file_id != to_root_id):
+ self.set_root_id(to_root_id)
self.flush()
result += merge.merge_inner(
self.branch,
More information about the bazaar-commits
mailing list