Rev 3404: (mbp) deprecate LocableFiles.get_utf8 in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri May 2 15:08:39 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3404
revision-id:pqm at pqm.ubuntu.com-20080502140826-nhg73h31i9viu175
parent: pqm at pqm.ubuntu.com-20080502115300-98iunzq9437108n5
parent: mbp at sourcefrog.net-20080501040939-i7xw7tt9h38a9phu
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-05-02 15:08:26 +0100
message:
  (mbp) deprecate LocableFiles.get_utf8
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
  bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  bzrlib/tests/test_lockable_files.py test_lockable_files.py-20051225183927-365c7fd99591caf1
  bzrlib/tests/workingtree_implementations/test_basis_inventory.py test_basis_inventory.py-20051218151655-3650468941091309
    ------------------------------------------------------------
    revno: 3388.1.2.1.3
    revision-id:mbp at sourcefrog.net-20080501040939-i7xw7tt9h38a9phu
    parent: mbp at sourcefrog.net-20080501040041-ee778mkbhyem0eqa
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: controlfiles
    timestamp: Thu 2008-05-01 14:09:39 +1000
    message:
      Fix up more uses of LockableFiles.get_utf8 in tests
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
    ------------------------------------------------------------
    revno: 3388.1.2.1.2
    revision-id:mbp at sourcefrog.net-20080501040041-ee778mkbhyem0eqa
    parent: mbp at sourcefrog.net-20080430125504-82xdxgfirosev448
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: controlfiles
    timestamp: Thu 2008-05-01 14:00:41 +1000
    message:
      Remove long-disabled test test_create_basis_inventory
    modified:
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
    ------------------------------------------------------------
    revno: 3388.1.2.1.1
    revision-id:mbp at sourcefrog.net-20080430125504-82xdxgfirosev448
    parent: mbp at sourcefrog.net-20080430080517-bk00bm4j6jk3gcgn
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: controlfiles
    timestamp: Wed 2008-04-30 22:55:04 +1000
    message:
      Deprecate LockableFiles.get_utf8
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
      bzrlib/tests/test_lockable_files.py test_lockable_files.py-20051225183927-365c7fd99591caf1
      bzrlib/tests/workingtree_implementations/test_basis_inventory.py test_basis_inventory.py-20051218151655-3650468941091309
=== modified file 'NEWS'
--- a/NEWS	2008-05-02 11:53:00 +0000
+++ b/NEWS	2008-05-02 14:08:26 +0000
@@ -101,6 +101,10 @@
       Repository.item_keys_introduced_by() no longer take read locks.
       (Aaron Bentley)
 
+    * ``LockableFiles.get_utf8`` is deprecated, as a start towards 
+      removing LockableFiles and ``.control_files`` entirely.
+      (Martin Pool)
+
 
 bzr 1.4 2008-04-28
 ------------------

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-04-30 13:32:15 +0000
+++ b/bzrlib/branch.py	2008-05-02 14:08:26 +0000
@@ -1720,8 +1720,7 @@
         # TODO: Maybe delete old location files?
         # URLs should never be unicode, even on the local fs,
         # FIXUP this and get_parent in a future branch format bump:
-        # read and rewrite the file, and have the new format code read
-        # using .get not .get_utf8. RBC 20060125
+        # read and rewrite the file. RBC 20060125
         if url is not None:
             if isinstance(url, unicode):
                 try: 
@@ -1786,7 +1785,7 @@
 
     def get_bound_location(self):
         try:
-            return self.control_files.get_utf8('bound').read()[:-1]
+            return self._transport.get_bytes('bound')[:-1]
         except errors.NoSuchFile:
             return None
 

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2008-04-13 17:38:34 +0000
+++ b/bzrlib/config.py	2008-05-01 04:09:39 +0000
@@ -643,8 +643,7 @@
         This is looked up in the email controlfile for the branch.
         """
         try:
-            return (self.branch.control_files.get_utf8("email") 
-                    .read()
+            return (self.branch.control_files._transport.get_bytes("email")
                     .decode(bzrlib.user_encoding)
                     .rstrip("\r\n"))
         except errors.NoSuchFile, e:

=== modified file 'bzrlib/lockable_files.py'
--- a/bzrlib/lockable_files.py	2008-04-09 02:32:18 +0000
+++ b/bzrlib/lockable_files.py	2008-04-30 12:55:04 +0000
@@ -25,8 +25,10 @@
 import bzrlib.errors as errors
 from bzrlib.errors import BzrError
 from bzrlib.osutils import file_iterator, safe_unicode
-from bzrlib.symbol_versioning import (deprecated_method,
-        )
+from bzrlib.symbol_versioning import (
+    deprecated_in,
+    deprecated_method,
+    )
 from bzrlib.trace import mutter, note
 import bzrlib.transactions as transactions
 import bzrlib.urlutils as urlutils
@@ -154,6 +156,7 @@
         return self._transport.get(relpath)
 
     @needs_read_lock
+    @deprecated_method(deprecated_in((1, 5, 0)))
     def get_utf8(self, relpath):
         """Get a file as a unicode stream."""
         relpath = self._escape(relpath)

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2007-12-20 20:44:45 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2008-05-01 04:09:39 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2008 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
@@ -43,7 +43,7 @@
         self.example_branch('a')
         self.run_bzr('branch a b')
         b = branch.Branch.open('b')
-        self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
+        self.assertEqual('b\n', b.control_files._transport.get_bytes('branch-name'))
         self.run_bzr('branch a c -r 1')
         b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
 

=== modified file 'bzrlib/tests/repository_implementations/test_repository.py'
--- a/bzrlib/tests/repository_implementations/test_repository.py	2008-04-26 16:34:47 +0000
+++ b/bzrlib/tests/repository_implementations/test_repository.py	2008-05-01 04:00:41 +0000
@@ -336,36 +336,6 @@
         rev_tree = tree.branch.repository.revision_tree(tree.last_revision())
         self.assertEqual('rev_id', rev_tree.inventory.root.revision)
 
-    def DISABLED_DELETE_OR_FIX_BEFORE_MERGE_test_create_basis_inventory(self):
-        # Needs testing here because differences between repo and working tree
-        # basis inventory formats can lead to bugs.
-        t = self.make_branch_and_tree('.')
-        b = t.branch
-        open('a', 'wb').write('a\n')
-        t.add('a')
-        t.commit('a', rev_id='r1')
-
-        t._control_files.get_utf8('basis-inventory-cache')
-
-        basis_inv = t.basis_tree().inventory
-        self.assertEquals('r1', basis_inv.revision_id)
-        
-        store_inv = b.repository.get_inventory('r1')
-        self.assertEquals(store_inv._byid, basis_inv._byid)
-
-        open('b', 'wb').write('b\n')
-        t.add('b')
-        t.commit('b', rev_id='r2')
-
-        t._control_files.get_utf8('basis-inventory-cache')
-
-        basis_inv_txt = t.read_basis_inventory()
-        basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
-        self.assertEquals('r2', basis_inv.revision_id)
-        store_inv = b.repository.get_inventory('r2')
-
-        self.assertEquals(store_inv._byid, basis_inv._byid)
-
     def test_upgrade_from_format4(self):
         from bzrlib.tests.test_upgrade import _upgrade_dir_template
         if self.repository_format.get_format_description() \

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2008-04-04 17:11:06 +0000
+++ b/bzrlib/tests/test_config.py	2008-05-01 04:09:39 +0000
@@ -159,23 +159,29 @@
 class FakeControlFiles(object):
 
     def __init__(self, user_id=None):
-        self.email = user_id
         self.files = {}
+        if user_id:
+            self.files['email'] = user_id
         self._transport = self
 
     def get_utf8(self, filename):
-        if filename != 'email':
-            raise NotImplementedError
-        if self.email is not None:
-            return StringIO(self.email)
-        raise errors.NoSuchFile(filename)
+        # from LockableFiles
+        raise AssertionError("get_utf8 should no longer be used")
 
     def get(self, filename):
+        # from Transport
         try:
             return StringIO(self.files[filename])
         except KeyError:
             raise errors.NoSuchFile(filename)
 
+    def get_bytes(self, filename):
+        # from Transport
+        try:
+            return self.files[filename]
+        except KeyError:
+            raise errors.NoSuchFile(filename)
+
     def put(self, filename, fileobj):
         self.files[filename] = fileobj.read()
 
@@ -965,20 +971,19 @@
         my_config = config.BranchConfig(branch)
         self.assertEqual("Robert Collins <robertc at example.net>",
                          my_config.username())
-        branch.control_files.email = "John"
+        my_config.branch.control_files.files['email'] = "John"
         my_config.set_user_option('email',
                                   "Robert Collins <robertc at example.org>")
         self.assertEqual("John", my_config.username())
-        branch.control_files.email = None
+        del my_config.branch.control_files.files['email']
         self.assertEqual("Robert Collins <robertc at example.org>",
                          my_config.username())
 
     def test_not_set_in_branch(self):
         my_config = self.get_branch_config(sample_config_text)
-        my_config.branch.control_files.email = None
         self.assertEqual(u"Erik B\u00e5gfors <erik at bagfors.nu>",
                          my_config._get_user_id())
-        my_config.branch.control_files.email = "John"
+        my_config.branch.control_files.files['email'] = "John"
         self.assertEqual("John", my_config._get_user_id())
 
     def test_BZR_EMAIL_OVERRIDES(self):

=== modified file 'bzrlib/tests/test_lockable_files.py'
--- a/bzrlib/tests/test_lockable_files.py	2007-12-13 20:17:06 +0000
+++ b/bzrlib/tests/test_lockable_files.py	2008-04-30 12:55:04 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006 Canonical Ltd
+# Copyright (C) 2005, 2006, 2008 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
@@ -24,6 +24,9 @@
     )
 from bzrlib.errors import BzrBadParameterNotString, NoSuchFile, ReadOnlyError
 from bzrlib.lockable_files import LockableFiles, TransportLock
+from bzrlib.symbol_versioning import (
+    deprecated_in,
+    )
 from bzrlib.tests import TestCaseInTempDir
 from bzrlib.tests.test_smart import TestCaseWithSmartMedium
 from bzrlib.tests.test_transactions import DummyWeave
@@ -35,11 +38,17 @@
 
 
 # these tests are applied in each parameterized suite for LockableFiles
+#
+# they use an old style of parameterization, but we want to remove this class
+# so won't modernize them now. - mbp 20080430
 class _TestLockableFiles_mixin(object):
 
     def test_read_write(self):
         self.assertRaises(NoSuchFile, self.lockable.get, 'foo')
-        self.assertRaises(NoSuchFile, self.lockable.get_utf8, 'foo')
+        self.assertRaises(NoSuchFile,
+            self.applyDeprecated,
+            deprecated_in((1, 5, 0)),
+            self.lockable.get_utf8, 'foo')
         self.lockable.lock_write()
         try:
             unicode_string = u'bar\u1234'
@@ -51,16 +60,24 @@
             self.lockable.put('foo', StringIO(byte_string))
             self.assertEqual(byte_string,
                              self.lockable.get('foo').read())
+            unicode_stream = self.applyDeprecated(
+                deprecated_in((1, 5, 0)),
+                self.lockable.get_utf8,
+                'foo')
             self.assertEqual(unicode_string,
-                             self.lockable.get_utf8('foo').read())
+                unicode_stream.read())
             self.assertRaises(BzrBadParameterNotString,
                               self.lockable.put_utf8,
                               'bar',
                               StringIO(unicode_string)
                               )
             self.lockable.put_utf8('bar', unicode_string)
+            unicode_stream = self.applyDeprecated(
+                deprecated_in((1, 5, 0)),
+                self.lockable.get_utf8,
+                'bar')
             self.assertEqual(unicode_string,
-                             self.lockable.get_utf8('bar').read())
+                unicode_stream.read())
             self.assertEqual(byte_string,
                              self.lockable.get('bar').read())
             self.lockable.put_bytes('raw', 'raw\xffbytes')

=== modified file 'bzrlib/tests/workingtree_implementations/test_basis_inventory.py'
--- a/bzrlib/tests/workingtree_implementations/test_basis_inventory.py	2007-02-22 05:51:57 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_basis_inventory.py	2008-04-30 12:55:04 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2005 Canonical Ltd
+# Copyright (C) 2004, 2005, 2008 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
@@ -16,6 +16,7 @@
 
 import os
 
+from bzrlib.tests import TestNotApplicable
 from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 from bzrlib.branch import Branch
 from bzrlib import inventory
@@ -30,7 +31,8 @@
         # not separate is mandatory.
         if isinstance(self.workingtree_format,
             bzrlib.workingtree_4.WorkingTreeFormat4):
-            return
+            raise TestNotApplicable("not applicable to %r"
+                % (self.workingtree_format,))
         # TODO: jam 20051218 this probably should add more than just
         #                    a couple files to the inventory
 
@@ -41,7 +43,7 @@
         t.add('a')
         t.commit('a', rev_id='r1')
 
-        t._control_files.get_utf8('basis-inventory-cache')
+        self.assertTrue(t._control_files._transport.has('basis-inventory-cache'))
 
         basis_inv = t.basis_tree().inventory
         self.assertEquals('r1', basis_inv.revision_id)
@@ -53,7 +55,7 @@
         t.add('b')
         t.commit('b', rev_id='r2')
 
-        t._control_files.get_utf8('basis-inventory-cache')
+        self.assertTrue(t._control_files._transport.has('basis-inventory-cache'))
 
         basis_inv_txt = t.read_basis_inventory()
         basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
@@ -68,7 +70,8 @@
         # not separate and ignorable.
         if isinstance(self.workingtree_format,
             bzrlib.workingtree_4.WorkingTreeFormat4):
-            return
+            raise TestNotApplicable("not applicable to %r"
+                % (self.workingtree_format,))
         t = self.make_branch_and_tree('.')
         b = t.branch
         open('a', 'wb').write('a\n')




More information about the bazaar-commits mailing list