Rev 6526: (abentley) Add branchname config variable (Aaron Bentley) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jun 20 15:48:57 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6526 [merge]
revision-id: pqm at pqm.ubuntu.com-20120620154857-e8a2fxwsgdxm87y1
parent: pqm at pqm.ubuntu.com-20120618125919-jf2dy5p1apoljtan
parent: aaron at aaronbentley.com-20120620143526-hn40ezmorrubqphx
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2012-06-20 15:48:57 +0000
message:
(abentley) Add branchname config variable (Aaron Bentley)
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
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2012-05-16 08:54:21 +0000
+++ b/bzrlib/config.py 2012-06-19 16:36:07 +0000
@@ -3444,11 +3444,14 @@
class LocationSection(Section):
- def __init__(self, section, extra_path):
+ def __init__(self, section, extra_path, branch_name=None):
super(LocationSection, self).__init__(section.id, section.options)
self.extra_path = extra_path
+ if branch_name is None:
+ branch_name = ''
self.locals = {'relpath': extra_path,
- 'basename': urlutils.basename(extra_path)}
+ 'basename': urlutils.basename(extra_path),
+ 'branchname': branch_name}
def get(self, name, default=None, expand=True):
value = super(LocationSection, self).get(name, default)
@@ -3524,9 +3527,15 @@
def __init__(self, store, location):
super(LocationMatcher, self).__init__(store)
+ url, params = urlutils.split_segment_parameters(location)
if location.startswith('file://'):
location = urlutils.local_path_from_url(location)
self.location = location
+ branch_name = params.get('branch')
+ if branch_name is None:
+ self.branch_name = urlutils.basename(self.location)
+ else:
+ self.branch_name = urlutils.unescape(branch_name)
def _get_matching_sections(self):
"""Get all sections matching ``location``."""
@@ -3558,8 +3567,9 @@
while True:
section = iter_all_sections.next()
if section_id == section.id:
- matching_sections.append(
- (length, LocationSection(section, extra_path)))
+ section = LocationSection(section, extra_path,
+ self.branch_name)
+ matching_sections.append((length, section))
break
return matching_sections
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt 2011-11-14 16:36:31 +0000
+++ b/bzrlib/help_topics/en/configuration.txt 2012-06-20 13:58:18 +0000
@@ -333,6 +333,18 @@
itself is defined as the relative path between the section name and the
location it matches.
+Another such option is ``branchname``, which refers to the name of a colocated
+branch. For non-colocated branches, it behaves like basename. It can be used
+like this::
+
+ [/home/vila/src/bzr/bugs]
+ mypush = lp:~vila/bzr/{branchname}
+
+When used with a colocated branch named ``832013-expand-in-stack``, we'll get::
+
+ bzr config mypush
+ lp:~vila/bzr/832013-expand-in-stack
+
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 2012-06-18 11:43:07 +0000
+++ b/bzrlib/tests/test_config.py 2012-06-20 14:35:26 +0000
@@ -17,6 +17,7 @@
"""Tests for finding and reading the bzr config file[s]."""
# import system imports here
from cStringIO import StringIO
+from textwrap import dedent
import os
import sys
import threading
@@ -3418,6 +3419,28 @@
matcher = config.LocationMatcher(store, expected_url)
self.assertEquals(expected_location, matcher.location)
+ def test_branch_name_colo(self):
+ store = self.get_store(self)
+ store._load_from_string(dedent("""\
+ [/]
+ push_location=my{branchname}
+ """))
+ matcher = config.LocationMatcher(store, 'file:///,branch=example%3c')
+ self.assertEqual('example<', matcher.branch_name)
+ ((_, section),) = matcher.get_sections()
+ self.assertEqual('example<', section.locals['branchname'])
+
+ def test_branch_name_basename(self):
+ store = self.get_store(self)
+ store._load_from_string(dedent("""\
+ [/]
+ push_location=my{branchname}
+ """))
+ matcher = config.LocationMatcher(store, 'file:///parent/example%3c')
+ self.assertEqual('example<', matcher.branch_name)
+ ((_, section),) = matcher.get_sections()
+ self.assertEqual('example<', section.locals['branchname'])
+
class TestStartingPathMatcher(TestStore):
More information about the bazaar-commits
mailing list