Rev 2795: Merge rename_one fix which fixes a test suite api violation allowing more commit refactoring. in http://people.ubuntu.com/~robertc/baz2.0/commit
Robert Collins
robertc at robertcollins.net
Mon Sep 17 07:10:47 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/commit
------------------------------------------------------------
revno: 2795
revision-id: robertc at robertcollins.net-20070917061036-fzr1h7zs9b3rr573
parent: robertc at robertcollins.net-20070917014525-s9rxjft45ka581fg
parent: robertc at robertcollins.net-20070917053356-05fyvmd1b3xalx6h
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit
timestamp: Mon 2007-09-17 16:10:36 +1000
message:
Merge rename_one fix which fixes a test suite api violation allowing more commit refactoring.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
bzrlib/tests/workingtree_implementations/test_rename_one.py test_rename_one.py-20070226161242-2d8ibdedl700jgio-1
------------------------------------------------------------
revno: 2776.2.18.1.32
revision-id: robertc at robertcollins.net-20070917053356-05fyvmd1b3xalx6h
parent: pqm at pqm.ubuntu.com-20070917005035-cshdkpzbj63id1uw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: rename_one
timestamp: Mon 2007-09-17 15:33:56 +1000
message:
* ``WorkingTree.rename_one`` will now raise an error if normalisation of the
new path causes bzr to be unable to access the file. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/tests/test_workingtree_4.py test_workingtree_4.p-20070223025758-531n3tznl3zacv2o-1
bzrlib/tests/workingtree_implementations/test_rename_one.py test_rename_one.py-20070226161242-2d8ibdedl700jgio-1
=== modified file 'NEWS'
--- a/NEWS 2007-09-17 01:45:25 +0000
+++ b/NEWS 2007-09-17 06:10:36 +0000
@@ -39,6 +39,9 @@
longer throws away the profiling data if this command is run with
``--lsprof-file callgrind.out.ci`` say. (Ian Clatworthy)
+ * ``WorkingTree.rename_one`` will now raise an error if normalisation of the
+ new path causes bzr to be unable to access the file. (Robert Collins)
+
API BREAKS:
* The ``VersionedFile`` interface now allows content checks to be bypassed
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-09-14 02:25:32 +0000
+++ b/bzrlib/dirstate.py 2007-09-17 05:33:56 +0000
@@ -365,7 +365,7 @@
# find the location in the block.
# check its not there
# add it.
- #------- copied from inventory.make_entry
+ #------- copied from inventory.ensure_normalized_name - keep synced.
# --- normalized_filename wants a unicode basename only, so get one.
dirname, basename = osutils.split(path)
# we dont import normalized_filename directly because we want to be
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2007-09-11 09:09:40 +0000
+++ b/bzrlib/inventory.py 2007-09-17 06:10:36 +0000
@@ -1301,6 +1301,7 @@
This does not move the working file.
"""
file_id = osutils.safe_file_id(file_id)
+ new_name = ensure_normalized_name(new_name)
if not is_valid_name(new_name):
raise BzrError("not an acceptable filename: %r" % new_name)
@@ -1348,7 +1349,21 @@
file_id = generate_ids.gen_file_id(name)
else:
file_id = osutils.safe_file_id(file_id)
-
+ name = ensure_normalized_name(name)
+ try:
+ factory = entry_factory[kind]
+ except KeyError:
+ raise BzrError("unknown kind %r" % kind)
+ return factory(file_id, name, parent_id)
+
+
+def ensure_normalized_name(name):
+ """Normalize name.
+
+ :raises InvalidNormalization: When name is not normalized, and cannot be
+ accessed on this platform by the normalized path.
+ :return: The NFC/NFKC normalised version of name.
+ """
#------- This has been copied to bzrlib.dirstate.DirState.add, please
# keep them synchronised.
# we dont import normalized_filename directly because we want to be
@@ -1356,17 +1371,12 @@
norm_name, can_access = osutils.normalized_filename(name)
if norm_name != name:
if can_access:
- name = norm_name
+ return norm_name
else:
# TODO: jam 20060701 This would probably be more useful
# if the error was raised with the full path
raise errors.InvalidNormalization(name)
-
- try:
- factory = entry_factory[kind]
- except KeyError:
- raise BzrError("unknown kind %r" % kind)
- return factory(file_id, name, parent_id)
+ return name
_NAME_RE = None
=== modified file 'bzrlib/tests/test_workingtree_4.py'
--- a/bzrlib/tests/test_workingtree_4.py 2007-04-26 22:56:01 +0000
+++ b/bzrlib/tests/test_workingtree_4.py 2007-09-17 05:33:56 +0000
@@ -419,12 +419,12 @@
tree.add(['b'], ['b-id'])
try:
- tree.rename_one('a', u'b\xb5rry')
- new_path = u'b\xb5rry'
+ new_path = u'b\u03bcrry'
+ tree.rename_one('a', new_path)
except UnicodeEncodeError:
# support running the test on non-unicode platforms
- tree.rename_one('a', 'c')
new_path = 'c'
+ tree.rename_one('a', new_path)
self.assertEqual(new_path, tree.id2path('a-id'))
tree.commit(u'b\xb5rry')
tree.unversion(['a-id'])
=== modified file 'bzrlib/tests/workingtree_implementations/test_rename_one.py'
--- a/bzrlib/tests/workingtree_implementations/test_rename_one.py 2007-02-26 16:19:02 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_rename_one.py 2007-09-17 05:33:56 +0000
@@ -308,3 +308,10 @@
('c', 'c-id')], tree)
self.assertTreeLayout([('', root_id), ('a', 'a-id'), ('c', 'c-id'),
('a/b', 'b-id')], tree.basis_tree())
+
+ def test_rename_to_denormalised_fails(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree(['a'])
+ tree.add(['a'])
+ self.assertRaises((errors.InvalidNormalization, UnicodeEncodeError),
+ tree.rename_one, 'a', u'b\xb5rry')
More information about the bazaar-commits
mailing list