Rev 6325: (jelmer) Allow registering new location aliases. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Nov 29 12:57:57 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6325 [merge]
revision-id: pqm at pqm.ubuntu.com-20111129125756-zmz58wibn2o1c6kb
parent: pqm at pqm.ubuntu.com-20111129123253-b25h3ypytx64jp01
parent: jelmer at samba.org-20111129114802-vtm3rm4e5brvt87f
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2011-11-29 12:57:56 +0000
message:
(jelmer) Allow registering new location aliases. (Jelmer Vernooij)
removed:
bzrlib/help_topics/en/location-alias.txt locationalias.txt-20100211071747-8cyf9n9xw0j3ypaz-1
modified:
bzrlib/directory_service.py directory_service.py-20080305221044-vr2mkvlsk8jypa2y-1
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/tests/test_directory_service.py test_directory_servi-20080305221044-vr2mkvlsk8jypa2y-2
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/directory_service.py'
--- a/bzrlib/directory_service.py 2011-04-07 10:36:24 +0000
+++ b/bzrlib/directory_service.py 2011-11-29 11:48:02 +0000
@@ -64,7 +64,6 @@
directories = DirectoryServiceRegistry()
-
class AliasDirectory(object):
"""Directory lookup for locations associated with a branch.
@@ -72,16 +71,22 @@
supported. On error, a subclass of DirectoryLookupFailure will be raised.
"""
+ branch_aliases = registry.Registry()
+ branch_aliases.register('parent', lambda b: b.get_parent(),
+ help="The parent of this branch.")
+ branch_aliases.register('submit', lambda b: b.get_submit_branch(),
+ help="The submit branch for this branch.")
+ branch_aliases.register('public', lambda b: b.get_public_branch(),
+ help="The public location of this branch.")
+ branch_aliases.register('bound', lambda b: b.get_bound_location(),
+ help="The branch this branch is bound to, for bound branches.")
+ branch_aliases.register('push', lambda b: b.get_push_location(),
+ help="The saved location used for `bzr push` with no arguments.")
+ branch_aliases.register('this', lambda b: b.base,
+ help="This branch.")
+
def look_up(self, name, url):
branch = _mod_branch.Branch.open_containing('.')[0]
- lookups = {
- 'parent': branch.get_parent,
- 'submit': branch.get_submit_branch,
- 'public': branch.get_public_branch,
- 'bound': branch.get_bound_location,
- 'push': branch.get_push_location,
- 'this': lambda: branch.base
- }
parts = url.split('/', 1)
if len(parts) == 2:
name, extra = parts
@@ -89,16 +94,38 @@
(name,) = parts
extra = None
try:
- method = lookups[name[1:]]
+ method = self.branch_aliases.get(name[1:])
except KeyError:
raise errors.InvalidLocationAlias(url)
else:
- result = method()
+ result = method(branch)
if result is None:
raise errors.UnsetLocationAlias(url)
if extra is not None:
result = urlutils.join(result, extra)
return result
+ @classmethod
+ def help_text(cls, topic):
+ alias_lines = []
+ for key in cls.branch_aliases.keys():
+ help = cls.branch_aliases.get_help(key)
+ alias_lines.append(" :%-10s%s\n" % (key, help))
+ return """\
+Location aliases
+================
+
+Bazaar defines several aliases for locations associated with a branch. These
+can be used with most commands that expect a location, such as `bzr push`.
+
+The aliases are::
+
+%s
+For example, to push to the parent location::
+
+ bzr push :parent
+""" % "".join(alias_lines)
+
+
directories.register(':', AliasDirectory,
'Easy access to remembered branch locations')
=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py 2011-10-10 20:15:02 +0000
+++ b/bzrlib/help_topics/__init__.py 2011-11-29 01:35:03 +0000
@@ -33,8 +33,6 @@
rendering on the screen naturally.
"""
-import sys
-
import bzrlib
from bzrlib import (
config,
@@ -769,6 +767,9 @@
'Information on configuration and log files')
topic_registry.register_lazy('hooks', 'bzrlib.hooks', 'hooks_help_text',
'Points at which custom processing can be added')
+topic_registry.register_lazy('location-alias', 'bzrlib.directory_service',
+ 'AliasDirectory.help_text',
+ 'Aliases for remembered locations')
# Load some of the help topics from files. Note that topics which reproduce API
# details will tend to skew (quickly usually!) so please seek other solutions
@@ -781,8 +782,6 @@
'Types of conflicts and what to do about them')
topic_registry.register('debug-flags', _load_from_file,
'Options to show or record debug information')
-topic_registry.register('location-alias', _load_from_file,
- 'Aliases for remembered locations')
topic_registry.register('log-formats', _load_from_file,
'Details on the logging formats available')
topic_registry.register('url-special-chars', _load_from_file,
=== removed file 'bzrlib/help_topics/en/location-alias.txt'
--- a/bzrlib/help_topics/en/location-alias.txt 2010-02-11 07:18:20 +0000
+++ b/bzrlib/help_topics/en/location-alias.txt 1970-01-01 00:00:00 +0000
@@ -1,19 +0,0 @@
-Location aliases
-================
-
-Bazaar defines several aliases for locations associated with a branch. These
-can be used with most commands that expect a location, such as `bzr push`.
-
-The aliases are::
-
- :parent the parent of this branch
- :submit the submit branch for this branch
- :public the public location of this branch
- :bound the branch this branch is bound to, for bound branches
- :push the saved location used for `bzr push` with no arguments
- :this this branch
-
-For example, to push to the parent location::
-
- bzr push :parent
-
=== modified file 'bzrlib/tests/test_directory_service.py'
--- a/bzrlib/tests/test_directory_service.py 2010-06-20 11:18:38 +0000
+++ b/bzrlib/tests/test_directory_service.py 2011-11-29 01:35:03 +0000
@@ -21,7 +21,11 @@
transport,
urlutils,
)
-from bzrlib.directory_service import DirectoryServiceRegistry, directories
+from bzrlib.directory_service import (
+ AliasDirectory,
+ DirectoryServiceRegistry,
+ directories,
+ )
from bzrlib.tests import TestCase, TestCaseWithTransport
@@ -107,3 +111,10 @@
e = self.assertRaises(errors.UnsetLocationAlias,
directories.dereference, ':parent')
self.assertEqual('No parent location assigned.', str(e))
+
+ def test_register_location_alias(self):
+ branch = self.make_branch('.')
+ self.addCleanup(AliasDirectory.branch_aliases.remove, "booga")
+ AliasDirectory.branch_aliases.register("booga",
+ lambda b: "UHH?", help="Nobody knows")
+ self.assertEquals("UHH?", directories.dereference(":booga"))
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-11-29 12:06:33 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-11-29 12:57:56 +0000
@@ -43,6 +43,9 @@
* ``bzr branch --stacked`` now only makes a single connection to the remote
server rather than three. (Jelmer Vernooij, #444293)
+* Plugins can now register additional "location aliases".
+ (Jelmer Vernooij)
+
Bug Fixes
*********
More information about the bazaar-commits
mailing list