Rev 6363: Use simpler config stacks and use strings as inputs to better respect the API. in file:///home/vila/src/bzr/reviews/commit-uses-config-stacks/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Dec 14 10:28:24 UTC 2011
At file:///home/vila/src/bzr/reviews/commit-uses-config-stacks/
------------------------------------------------------------
revno: 6363
revision-id: v.ladeuil+lp at free.fr-20111214102824-xykkunwwm7uqo8au
parent: v.ladeuil+lp at free.fr-20111214100413-xptcryznfmrlrxq2
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: commit-uses-config-stacks
timestamp: Wed 2011-12-14 11:28:24 +0100
message:
Use simpler config stacks and use strings as inputs to better respect the API.
-------------- next part --------------
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2011-12-09 12:05:47 +0000
+++ b/bzrlib/commit.py 2011-12-14 10:28:24 +0000
@@ -604,9 +604,10 @@
# Process the post commit hooks, if any
self._set_progress_stage("Running post_commit hooks")
# old style commit hooks - should be deprecated ? (obsoleted in
- # 0.15)
- if self.config_stack.get('post_commit') is not None:
- hooks = self.config_stack.get('post_commit').split(' ')
+ # 0.15^H^H^H^H 2.5.0)
+ post_commit = self.config_stack.get('post_commit')
+ if post_commit is not None:
+ hooks = post_commit.split(' ')
# this would be nicer with twisted.python.reflect.namedAny
for hook in hooks:
result = eval(hook + '(branch, rev_id)',
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-12-09 14:24:21 +0000
+++ b/bzrlib/config.py 2011-12-14 10:28:24 +0000
@@ -2659,11 +2659,10 @@
' (terminal encoding if not specified).'))
option_registry.register(
Option('post_commit', default=None,
- from_unicode=list_from_store,
help='''\
Post commit functions.
-An ordered list of python functions to call.
+An ordered list of python functions to call separated by spaces.
Each function takes branch, rev_id as parameters.
'''))
=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py 2011-12-09 14:24:21 +0000
+++ b/bzrlib/tests/test_commit.py 2011-12-14 10:28:24 +0000
@@ -20,15 +20,12 @@
import bzrlib
from bzrlib import (
bzrdir,
+ config,
errors,
)
from bzrlib.branch import Branch
from bzrlib.bzrdir import BzrDirMetaFormat1
from bzrlib.commit import Commit, NullCommitReporter
-from bzrlib.config import (
- SIGN_ALWAYS,
- BranchStack,
- )
from bzrlib.errors import (
PointlessCommit,
BzrError,
@@ -47,22 +44,27 @@
# TODO: Test commit with some added, and added-but-missing files
-class MustSignConfig(BranchStack):
-
- def get(self, name):
- if name == "gpg_signing_command":
- return u"cat -"
- elif name == "create_signatures":
- return SIGN_ALWAYS
- return super(MustSignConfig, self).get(name)
-
-
-class BranchWithHooks(BranchStack):
-
- def get(self, name):
- if name == "post_commit":
- return "bzrlib.ahook bzrlib.ahook"
- return super(BranchWithHooks, self).get(name)
+class MustSignConfig(config.Stack):
+
+ def __init__(self, branch):
+ store = config.IniFileStore()
+ store._load_from_string('''
+gpg_signing_command=cat -
+create_signatures=always
+''')
+ super(MustSignConfig, self).__init__([store.get_sections])
+ # FIXME: Strictly speaking we should fallback to the no-name section in
+ # branch.conf but no tests need that so far -- vila 2011-12-14
+
+
+class BranchWithHooks(config.Stack):
+
+ def __init__(self, branch):
+ store = config.IniFileStore()
+ store._load_from_string('post_commit=bzrlib.ahook bzrlib.ahook')
+ super(BranchWithHooks, self).__init__([store.get_sections])
+ # FIXME: Strictly speaking we should fallback to the no-name section in
+ # branch.conf but no tests need that so far -- vila 2011-12-14
class CapturingReporter(NullCommitReporter):
@@ -437,14 +439,13 @@
from bzrlib.testament import Testament
# monkey patch gpg signing mechanism
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
- commit.Commit(config_stack=MustSignConfig(branch)).commit(message="base",
- allow_pointless=True,
- rev_id='B',
- working_tree=wt)
+ commit.Commit(config_stack=MustSignConfig(branch)
+ ).commit(message="base", allow_pointless=True,
+ rev_id='B', working_tree=wt)
def sign(text):
return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text)
self.assertEqual(sign(Testament.from_revision(branch.repository,
- 'B').as_short_text()),
+ 'B').as_short_text()),
branch.repository.get_signature_text('B'))
finally:
bzrlib.gpg.GPGStrategy = oldstrategy
More information about the bazaar-commits
mailing list