Rev 6467: Fix RegistryOption display in bzr config output in file:///home/vila/src/bzr/bugs/930182-display-reg-options/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Feb 13 17:14:34 UTC 2012


At file:///home/vila/src/bzr/bugs/930182-display-reg-options/

------------------------------------------------------------
revno: 6467
revision-id: v.ladeuil+lp at free.fr-20120213171434-i7gmmt8l45eq63l3
parent: pqm at pqm.ubuntu.com-20120207134616-4f26nutrmui7s5xp
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 930182-display-reg-options
timestamp: Mon 2012-02-13 18:14:34 +0100
message:
  Fix RegistryOption display in bzr config output
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-02-07 00:49:58 +0000
+++ b/bzrlib/config.py	2012-02-13 17:14:34 +0000
@@ -3657,7 +3657,17 @@
         self.store = store
         self.mutable_section_id = mutable_section_id
 
-    def get(self, name, expand=None):
+    def iter_sections(self):
+        """Iterate all the defined sections."""
+        # Ensuring lazy loading is achieved by delaying section matching (which
+        # implies querying the persistent storage) until it can't be avoided
+        # anymore by using callables to describe (possibly empty) section
+        # lists.
+        for sections in self.sections_def:
+            for store, section in sections():
+                yield store, section
+
+    def get(self, name, expand=None, convert=True):
         """Return the *first* option value found in the sections.
 
         This is where we guarantee that sections coming from Store are loaded
@@ -3670,6 +3680,9 @@
 
         :param expand: Whether options references should be expanded.
 
+        :param convert: Whether the option value should be converted from
+            unicode (do nothing for non-registered options).
+
         :returns: The value of the option.
         """
         # FIXME: No caching of options nor sections yet -- vila 20110503
@@ -3698,7 +3711,7 @@
                                       % (name, type(val)))
                 if opt is None:
                     val = found_store.unquote(val)
-                else:
+                elif convert:
                     val = opt.convert_from_unicode(found_store, val)
             return val
 
@@ -3708,17 +3721,10 @@
             value = opt.get_override()
             value = expand_and_convert(value)
         if value is None:
-            # Ensuring lazy loading is achieved by delaying section matching
-            # (which implies querying the persistent storage) until it can't be
-            # avoided anymore by using callables to describe (possibly empty)
-            # section lists.
-            for sections in self.sections_def:
-                for store, section in sections():
-                    value = section.get(name)
-                    if value is not None:
-                        found_store = store
-                        break
+            for store, section in self.iter_sections():
+                value = section.get(name)
                 if value is not None:
+                    found_store = store
                     break
             value = expand_and_convert(value)
             if opt is not None and value is None:
@@ -4102,12 +4108,17 @@
             except errors.NotBranchError:
                 return LocationStack(directory)
 
+    def _quote_multiline(self, value):
+        if '\n' in value:
+            value = '"""' + value + '"""'
+        return value
+
     def _show_value(self, name, directory, scope):
         conf = self._get_stack(directory, scope)
-        value = conf.get(name, expand=True)
+        value = conf.get(name, expand=True, convert=False)
         if value is not None:
             # Quote the value appropriately
-            value = _quoting_config._quote(value)
+            value = self._quote_multiline(value)
             self.outf.write('%s\n' % (value,))
         else:
             raise errors.NoSuchConfigOption(name)
@@ -4121,31 +4132,23 @@
         cur_store_id = None
         cur_section = None
         conf = self._get_stack(directory, scope)
-        for sections in conf.sections_def:
-            for store, section in sections():
-                for oname in section.iter_option_names():
-                    if name.search(oname):
-                        if cur_store_id != store.id:
-                            # Explain where the options are defined
-                            self.outf.write('%s:\n' % (store.id,))
-                            cur_store_id = store.id
-                            cur_section = None
-                        if (section.id is not None
-                            and cur_section != section.id):
-                            # Display the section id as it appears in the store
-                            # (None doesn't appear by definition)
-                            self.outf.write('  [%s]\n' % (section.id,))
-                            cur_section = section.id
-                        value = section.get(oname, expand=False)
-                        # Since we don't use the stack, we need to restore a
-                        # proper quoting.
-                        try:
-                            opt = option_registry.get(oname)
-                            value = opt.convert_from_unicode(store, value)
-                        except KeyError:
-                            value = store.unquote(value)
-                        value = _quoting_config._quote(value)
-                        self.outf.write('  %s = %s\n' % (oname, value))
+        for store, section in conf.iter_sections():
+            for oname in section.iter_option_names():
+                if name.search(oname):
+                    if cur_store_id != store.id:
+                        # Explain where the options are defined
+                        self.outf.write('%s:\n' % (store.id,))
+                        cur_store_id = store.id
+                        cur_section = None
+                    if (section.id is not None and cur_section != section.id):
+                        # Display the section id as it appears in the store
+                        # (None doesn't appear by definition)
+                        self.outf.write('  [%s]\n' % (section.id,))
+                        cur_section = section.id
+                    value = section.get(oname, expand=False)
+                    # Quote the value appropriately
+                    value = self._quote_multiline(value)
+                    self.outf.write('  %s = %s\n' % (oname, value))
 
     def _set_config_option(self, name, value, directory, scope):
         conf = self._get_stack(directory, scope)

=== modified file 'bzrlib/tests/blackbox/test_config.py'
--- a/bzrlib/tests/blackbox/test_config.py	2012-01-03 12:56:06 +0000
+++ b/bzrlib/tests/blackbox/test_config.py	2012-02-13 17:14:34 +0000
@@ -95,7 +95,7 @@
             """
             ''')
 
-    def test_list_all_values(self):
+    def test_list_value_all(self):
         config.option_registry.register(config.ListOption('list'))
         self.addCleanup(config.option_registry.remove, 'list')
         self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
@@ -106,7 +106,7 @@
               list = 1, a, "with, a comma"
             ''')
 
-    def test_list_value_only(self):
+    def test_list_value_one(self):
         config.option_registry.register(config.ListOption('list'))
         self.addCleanup(config.option_registry.remove, 'list')
         self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
@@ -115,6 +115,24 @@
             1, a, "with, a comma"
             ''')
 
+    def test_registry_value_all(self):
+        self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
+                                           u'move')
+        script.run_script(self, '''\
+            $ bzr config -d tree
+            bazaar:
+              [DEFAULT]
+              bzr.transform.orphan_policy = move
+            ''')
+
+    def test_registry_value_one(self):
+        self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
+                                           u'move')
+        script.run_script(self, '''\
+            $ bzr config -d tree bzr.transform.orphan_policy
+            move
+            ''')
+
     def test_bazaar_config(self):
         self.bazaar_config.set_user_option('hello', 'world')
         script.run_script(self, '''\

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-02-03 10:28:47 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-02-13 17:14:34 +0000
@@ -37,6 +37,9 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* Fix ``bzr config`` display for ``RegistryOption`` values.
+  (Vincent Ladeuil, #930182)
+
 Documentation
 *************
 



More information about the bazaar-commits mailing list