Rev 6380: Migrate location options to config stacks. in file:///home/vila/src/bzr/experimental/config-location-options/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Dec 20 14:04:21 UTC 2011


At file:///home/vila/src/bzr/experimental/config-location-options/

------------------------------------------------------------
revno: 6380
revision-id: v.ladeuil+lp at free.fr-20111220140421-8fkarrusrynweiah
parent: pqm at pqm.ubuntu.com-20111216140401-s72dizm37u8q660i
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-location-options
timestamp: Tue 2011-12-20 15:04:21 +0100
message:
  Migrate location options to config stacks.
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2011-12-14 23:43:20 +0000
+++ b/bzrlib/branch.py	2011-12-20 14:04:21 +0000
@@ -1163,18 +1163,20 @@
     def _set_config_location(self, name, url, config=None,
                              make_relative=False):
         if config is None:
-            config = self.get_config()
+            config = self.get_config_stack()
         if url is None:
             url = ''
         elif make_relative:
             url = urlutils.relative_url(self.base, url)
-        config.set_user_option(name, url, warn_masked=True)
+        config.set(name, url)
 
     def _get_config_location(self, name, config=None):
         if config is None:
-            config = self.get_config()
-        location = config.get_user_option(name)
-        if location == '':
+            config = self.get_config_stack()
+        location = config.get(name)
+        # FIXME: There is a glitch around quoting/unquoting in config stores:
+        # an empty string can be seen as '""' instead of '' -- vila 2011-12-20
+        if location in ('', '""') :
             location = None
         return location
 
@@ -2961,28 +2963,27 @@
         """See Branch.set_push_location."""
         self._master_branch_cache = None
         result = None
-        config = self.get_config()
+        conf = self.get_config_stack()
         if location is None:
-            if config.get_user_option('bound') != 'True':
+            if not conf.get('bound'):
                 return False
             else:
-                config.set_user_option('bound', 'False', warn_masked=True)
+                conf.set('bound', 'False')
                 return True
         else:
             self._set_config_location('bound_location', location,
-                                      config=config)
-            config.set_user_option('bound', 'True', warn_masked=True)
+                                      config=conf)
+            conf.set('bound', 'True')
         return True
 
     def _get_bound_location(self, bound):
         """Return the bound location in the config file.
 
         Return None if the bound parameter does not match"""
-        config = self.get_config()
-        config_bound = (config.get_user_option('bound') == 'True')
-        if config_bound != bound:
+        conf = self.get_config_stack()
+        if conf.get('bound') != bound:
             return None
-        return self._get_config_location('bound_location', config=config)
+        return self._get_config_location('bound_location', config=conf)
 
     def get_bound_location(self):
         """See Branch.set_push_location."""
@@ -2998,9 +2999,9 @@
         ## self._check_stackable_repo()
         # stacked_on_location is only ever defined in branch.conf, so don't
         # waste effort reading the whole stack of config files.
-        config = self.get_config()._get_branch_data_config()
+        conf = _mod_config._BranchOnlyStack(self)
         stacked_url = self._get_config_location('stacked_on_location',
-            config=config)
+                                                config=conf)
         if stacked_url is None:
             raise errors.NotStacked(self)
         return stacked_url

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-12-16 14:04:01 +0000
+++ b/bzrlib/config.py	2011-12-20 14:04:21 +0000
@@ -2474,7 +2474,6 @@
     _list_converter_config.reset()
     _list_converter_config._parse([u"list=%s" % (unicode_str,)])
     maybe_list = _list_converter_config['list']
-    # ConfigObj return '' instead of u''. Use 'str' below to catch all cases.
     if isinstance(maybe_list, basestring):
         if maybe_list:
             # A single value, most probably the user forgot (or didn't care to
@@ -2548,6 +2547,27 @@
 List of GPG key patterns which are acceptable for verification.
 """))
 option_registry.register(
+    Option('bound',
+           default=None, from_unicode=bool_from_store,
+           help="""\
+Is the branch bound to ``bound_location``.
+
+If set to "True", the branch should act as a checkout, and push each commit to
+the bound_location.  This option is normally set by ``bind``/``unbind``.
+
+See also: bound_location.
+"""))
+option_registry.register(
+    Option('bound_location',
+           default=None,
+           help="""\
+The location that commits should go to when acting as a checkout.
+
+This option is normally set by ``bind``.
+
+See also: bound.
+"""))
+option_registry.register(
     Option('bzr.workingtree.worth_saving_limit', default=10,
            from_unicode=int_from_store,  invalid='warning',
            help='''\
@@ -2667,6 +2687,15 @@
            help= 'Unicode encoding for output'
            ' (terminal encoding if not specified).'))
 option_registry.register(
+    Option('parent_location',
+           default=None,
+           help="""\
+The location of the default branch for pull or merge.
+
+This option is normally set when creating a branch, the first ``pull`` or by
+``pull --remember``.
+"""))
+option_registry.register(
     Option('post_commit', default=None,
            help='''\
 Post commit functions.
@@ -2676,6 +2705,23 @@
 Each function takes branch, rev_id as parameters.
 '''))
 option_registry.register(
+    Option('public_branch',
+           default=None,
+           help="""\
+A publically-accessible version of this branch.
+
+This implies that the branch setting this option is not publically-accessible.
+Used and set by ``bzr send``.
+"""))
+option_registry.register(
+    Option('push_location',
+           default=None,
+           help="""\
+The location of the default branch for push.
+
+This option is normally set by the first ``push`` or ``push --remember``.
+"""))
+option_registry.register(
     Option('push_strict', default=None,
            from_unicode=bool_from_store,
            help='''\
@@ -2709,7 +2755,7 @@
 The default value for ``send --strict``.
 
 If present, defines the ``--strict`` option default value for checking
-uncommitted changes before pushing.
+uncommitted changes before sending a bundle.
 '''))
 
 option_registry.register(
@@ -2717,6 +2763,19 @@
            default=300.0, from_unicode=float_from_store,
            help="If we wait for a new request from a client for more than"
                 " X seconds, consider the client idle, and hangup."))
+option_registry.register(
+    Option('stacked_on_location',
+           default=None,
+           help="""The location where this branch is stacked on."""))
+option_registry.register(
+    Option('submit_branch',
+           default=None,
+           help="""\
+The branch you intend to submit your current work to.
+
+This is automatically set by ``bzr send`` and ``bzr merge``, and is also used
+by the ``submit:`` revision spec.
+"""))
 
 
 class Section(object):
@@ -3579,20 +3638,21 @@
         self.bzrdir = bzrdir
 
 
-class RemoteBranchStack(_CompatibleStack):
-    """Remote branch-only options stack."""
+class _BranchOnlyStack(_CompatibleStack):
+    """Branch-only options stack."""
 
-    # FIXME 2011-11-22 JRV This should probably be renamed to avoid confusion
-    # with the stack used for remote branches. RemoteBranchStack only uses
-    # branch.conf and is used only for the stack options.
+    # FIXME: _BranchOnlyStack only uses branch.conf and is used only for the
+    # stacked_on_location options waiting for http://pad.lv/832042 to be fixed.
+    # -- vila 2011-12-16
 
     def __init__(self, branch):
         bstore = branch._get_config_store()
-        super(RemoteBranchStack, self).__init__(
+        super(_BranchOnlyStack, self).__init__(
             [NameMatcher(bstore, None).get_sections],
             bstore)
         self.branch = branch
 
+
 # Use a an empty dict to initialize an empty configobj avoiding all
 # parsing and encoding checks
 _quoting_config = configobj.ConfigObj(

=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2011-10-11 12:01:51 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2011-12-20 14:04:21 +0000
@@ -264,7 +264,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(13, self.hpss_calls)
+        self.assertLength(14, self.hpss_calls)
         remote = branch.Branch.open('public')
         self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2011-12-15 12:59:56 +0000
+++ b/bzrlib/tests/test_branch.py	2011-12-20 14:04:21 +0000
@@ -403,22 +403,6 @@
     def test_light_checkout_with_references(self):
         self.do_checkout_test(lightweight=True)
 
-    def test_set_push(self):
-        branch = self.make_branch('source', format=self.get_format_name())
-        branch.get_config().set_user_option('push_location', 'old',
-            store=config.STORE_LOCATION)
-        warnings = []
-        def warning(*args):
-            warnings.append(args[0] % args[1:])
-        _warning = trace.warning
-        trace.warning = warning
-        try:
-            branch.set_push_location('new')
-        finally:
-            trace.warning = _warning
-        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
-                         'locations.conf')
-
 
 class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
 

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-12-15 11:53:48 +0000
+++ b/bzrlib/tests/test_config.py	2011-12-20 14:04:21 +0000
@@ -144,16 +144,16 @@
 config.test_stack_builder_registry.register('branch', build_branch_stack)
 
 
-def build_remote_branch_stack(test):
+def build_branch_only_stack(test):
     # There is only one permutation (but we won't be able to handle more with
     # this design anyway)
     (transport_class,
      server_class) = transport_remote.get_test_permutations()[0]
     build_backing_branch(test, 'branch', transport_class, server_class)
     b = branch.Branch.open(test.get_url('branch'))
-    return config.RemoteBranchStack(b)
-config.test_stack_builder_registry.register('remote_branch',
-                                            build_remote_branch_stack)
+    return config._BranchOnlyStack(b)
+config.test_stack_builder_registry.register('branch_only',
+                                            build_branch_only_stack)
 
 def build_remote_control_stack(test):
     # There is only one permutation (but we won't be able to handle more with



More information about the bazaar-commits mailing list