Rev 2480: Test adding of roots to trees, it was broken on WorkingTree4. in http://bazaar.launchpad.net/~bzr/bzr/dirstate
Robert Collins
robertc at robertcollins.net
Thu Mar 1 11:18:08 GMT 2007
At http://bazaar.launchpad.net/~bzr/bzr/dirstate
------------------------------------------------------------
revno: 2480
revision-id: robertc at robertcollins.net-20070301111653-xz97hibpktk2y5co
parent: robertc at robertcollins.net-20070301095035-qq2jbr6p4ggdlu1t
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate.dogfood
timestamp: Thu 2007-03-01 22:16:53 +1100
message:
Test adding of roots to trees, it was broken on WorkingTree4.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/tests/workingtree_implementations/test_add.py test_add.py-20070226165239-4vo178spkrnhavc7-1
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-02-27 21:32:16 +0000
+++ b/bzrlib/dirstate.py 2007-03-01 11:16:53 +0000
@@ -331,10 +331,18 @@
kind = DirState._minikind_to_kind[file_id_entry[1][0][0]]
info = '%s:%s' % (kind, path)
raise errors.DuplicateFileId(file_id, info)
- entry_key = (dirname, basename, file_id)
- self._read_dirblocks_if_needed()
- block_index, present = self._find_block_index_from_key(entry_key)
- if not present:
+ first_key = (dirname, basename, '')
+ block_index, present = self._find_block_index_from_key(first_key)
+ if present:
+ # check the path is not in the tree
+ block = self._dirblocks[block_index][1]
+ entry_index, _ = self._find_entry_index(first_key, block)
+ while (entry_index < len(block) and
+ block[entry_index][0][0:2] == first_key[0:2]):
+ if block[entry_index][1][0][0] not in 'ar':
+ # this path is in the dirstate in the current tree.
+ raise Exception, "adding already added path!"
+ else:
# The block where we want to put the file is not present. But it
# might be because the directory was empty, or not loaded yet. Look
# for a parent entry, if not found, raise NotVersionedError
@@ -345,6 +353,7 @@
raise errors.NotVersionedError(path, str(self))
self._ensure_block(parent_block_idx, parent_entry_idx, dirname)
block = self._dirblocks[block_index][1]
+ entry_key = (dirname, basename, file_id)
if stat is None:
size = 0
packed_stat = DirState.NULLSTAT
=== modified file 'bzrlib/tests/workingtree_implementations/test_add.py'
--- a/bzrlib/tests/workingtree_implementations/test_add.py 2007-02-26 22:11:07 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_add.py 2007-03-01 11:16:53 +0000
@@ -20,6 +20,7 @@
from bzrlib import (
errors,
+ inventory,
osutils,
)
@@ -146,3 +147,14 @@
tree.unversion(['dir-id'])
self.assertRaises(errors.NotVersionedError,
tree.add, ['dir/subdir'])
+
+ def test_add_root(self):
+ # adding the root should be a no-op, or at least not
+ # do anything whacky.
+ tree = self.make_branch_and_tree('.')
+ tree.lock_write()
+ tree.add('')
+ self.assertEqual([tree.path2id('')], list(tree))
+ # the root should have been changed to be a new unique root.
+ self.assertNotEqual(inventory.ROOT_ID, tree.path2id(''))
+ tree.unlock()
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-03-01 09:34:26 +0000
+++ b/bzrlib/workingtree_4.py 2007-03-01 11:16:53 +0000
@@ -172,6 +172,11 @@
f = f.strip('/')
assert '//' not in f
assert '..' not in f
+ if self.path2id(f):
+ # special case tree root handling.
+ if f == '' and self.path2id(f) == ROOT_ID:
+ state.set_path_id('', generate_ids.gen_file_id(f))
+ continue
if file_id is None:
file_id = generate_ids.gen_file_id(f)
# deliberately add the file with no cached stat or sha1
@@ -227,6 +232,14 @@
self._control_files.break_lock()
self.branch.break_lock()
+ @needs_write_lock
+ def commit(self, message=None, revprops=None, *args, **kwargs):
+ # mark the tree as dirty post commit - commit
+ # can change the current versioned list by doing deletes.
+ result = WorkingTree3.commit(self, message, revprops, *args, **kwargs)
+ self._make_dirty(reset_inventory=True)
+ return result
+
def current_dirstate(self):
"""Return the current dirstate object.
More information about the bazaar-commits
mailing list