Rev 6278: (vila) Add {basename} as a section local configuration option. (Vincent in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Fri Nov 18 09:48:48 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6278 [merge]
revision-id: pqm at pqm.ubuntu.com-20111118094847-wje27baymgcvl9m2
parent: pqm at pqm.ubuntu.com-20111118054148-blm76siz9s4y51dw
parent: v.ladeuil+lp at free.fr-20111118072920-76q1ho772bkmnno2
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2011-11-18 09:48:47 +0000
message:
  (vila) Add {basename} as a section local configuration option. (Vincent
   Ladeuil)
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
  doc/developers/configuration.txt configuration.txt-20110408142435-korjxxnskvq44sta-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-11-16 17:19:13 +0000
+++ b/bzrlib/config.py	2011-11-18 07:29:20 +0000
@@ -3027,7 +3027,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, expand=True):
         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-11-16 17:19:13 +0000
+++ b/bzrlib/tests/test_config.py	2011-11-18 07:29:20 +0000
@@ -3671,6 +3671,38 @@
 
 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_basename_locally_longer_path(self):
+        l_store = config.LocationStore()
+        l_store._load_from_string('''
+[/home/user]
+bfoo = {basename}
+''')
+        l_store.save()
+        stack = config.LocationStack('/home/user/project/dir/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``.

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-17 18:42:24 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-18 07:29:20 +0000
@@ -39,15 +39,20 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* A new section local option ``basename`` is available to help support some
+  ``bzr-pipeline`` workflows and more generally help mapping local paths to
+  remote ones. See ``bzr help configuration`` for more details.
+  (Vincent Ladeuil, #843211)
+
 * Resolve regression from colocated branch path handling, by ensuring that
   unreserved characters are unquoted in URLs. (Martin Packman, #842223)
 
+* Support looking up revision numbers by revision id in empty branches.
+  (Jelmer Vernooij, #535031)
+
 * Support verifying signatures on remote repositories.
   (Jelmer Vernooij, #889694)
 
-* Support looking up revision numbers by revision id in empty branches.
-  (Jelmer Vernooij, #535031)
-
 Documentation
 *************
 




More information about the bazaar-commits mailing list