Rev 6107: Add ``basename`` as a section local option in file:///home/vila/src/bzr/bugs/843211-basename-option/

Vincent Ladeuil v.ladeuil+lp at free.fr
Mon Nov 14 16:36:31 UTC 2011


At file:///home/vila/src/bzr/bugs/843211-basename-option/

------------------------------------------------------------
revno: 6107
revision-id: v.ladeuil+lp at free.fr-20111114163631-wj99n1ha7bxmbqno
parent: v.ladeuil+lp at free.fr-20111105161211-b4b82psc3mw23i37
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 843211-basename-option
timestamp: Mon 2011-11-14 17:36:31 +0100
message:
  Add ``basename`` as a section local option
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-10-31 22:11:59 +0000
+++ b/bzrlib/config.py	2011-11-14 16:36:31 +0000
@@ -3008,7 +3008,8 @@
         super(LocationSection, self).__init__(section.id, section.options)
         self.length = length
         self.extra_path = extra_path
-        self.locals = {'relpath': extra_path}
+        self.locals = {'relpath': extra_path,
+                       'basename': urlutils.basename(extra_path)}
 
     def get(self, name, default=None):
         value = super(LocationSection, self).get(name, default)

=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt	2011-11-05 16:12:11 +0000
+++ b/bzrlib/help_topics/en/configuration.txt	2011-11-14 16:36:31 +0000
@@ -318,6 +318,21 @@
    $ bzr config mypush
    lp:~vila/bzr/832013-expand-in-stack
 
+Another such option is ``basename`` which can be used like this::
+
+  [/home/vila/src/bzr]
+  mypush = lp:~vila/bzr/{basename}
+
+When used in a directory like
+``/home/vila/src/bzr/bugs/832013-expand-in-stack`` we'll get::
+
+   $ bzr config mypush
+   lp:~vila/bzr/832013-expand-in-stack
+
+Note that ``basename`` here refers to the base name of ``relpath`` which
+itself is defined as the relative path between the section name and the
+location it matches.
+
 When an option is local to a Section, it cannot be referred to from option
 values in any other section from the same ``Store`` nor from any other
 ``Store``.

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-10-31 22:11:59 +0000
+++ b/bzrlib/tests/test_config.py	2011-11-14 16:36:31 +0000
@@ -3660,6 +3660,28 @@
 
 class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
 
+    def test_expand_locals_empty(self):
+        l_store = config.LocationStore()
+        l_store._load_from_string('''
+[/home/user/project]
+base = {basename}
+rel = {relpath}
+''')
+        l_store.save()
+        stack = config.LocationStack('/home/user/project/')
+        self.assertEquals('', stack.get('base', expand=True))
+        self.assertEquals('', stack.get('rel', expand=True))
+
+    def test_expand_basename_locally(self):
+        l_store = config.LocationStore()
+        l_store._load_from_string('''
+[/home/user/project]
+bfoo = {basename}
+''')
+        l_store.save()
+        stack = config.LocationStack('/home/user/project/branch')
+        self.assertEquals('branch', stack.get('bfoo', expand=True))
+
     def test_expand_relpath_locally(self):
         l_store = config.LocationStore()
         l_store._load_from_string('''

=== modified file 'doc/developers/configuration.txt'
--- a/doc/developers/configuration.txt	2011-11-05 16:12:11 +0000
+++ b/doc/developers/configuration.txt	2011-11-14 16:36:31 +0000
@@ -98,10 +98,12 @@
 defined in ``LocationSection`` as an alternative to the ``appendpath``
 policy.
 
-For ``appendpath``, the ``LocationSection`` will carry ``extra_path`` as
-``832013-expand-in-stack`` and ``relpath`` will be available as a
-``Section`` local option with the same value. Note that such options can
-only be expanded inside the section that defines them.
+For ``appendpath``, the ``LocationSection`` will carry ``extra_path`` as the
+relative path between the section name and the location used. ``relpath``
+will be available as a ``Section`` local option with the same
+value. ``basename`` will carry the location base name and be available as a
+local option with the same name. Note that such options can only be expanded
+inside the section that defines them.
 
 Specific section matchers can be implemented by overriding ``get_sections``
 or just ``match``.



More information about the bazaar-commits mailing list