Rev 3682: Create a new hook Branch.open. (Robert Collins) in http://people.ubuntu.com/~robertc/baz2.0/branch
Robert Collins
robertc at robertcollins.net
Thu Sep 4 06:23:45 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/branch
------------------------------------------------------------
revno: 3682
revision-id: robertc at robertcollins.net-20080904052339-tyyojuqlonks504v
parent: pqm at pqm.ubuntu.com-20080902220856-plj0mk673ygzwc1k
committer: Robert Collins <robertc at robertcollins.net>
branch nick: branch
timestamp: Thu 2008-09-04 15:23:39 +1000
message:
Create a new hook Branch.open. (Robert Collins)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
=== modified file 'NEWS'
--- a/NEWS 2008-09-02 19:46:10 +0000
+++ b/NEWS 2008-09-04 05:23:39 +0000
@@ -123,6 +123,9 @@
INTERNALS:
+ * A new hook, ``Branch.open``, has been added, which is called when
+ branch objects are opened. (Robert Collins)
+
* A new plugin interface, ``bzrlib.log.log_adapters``, has been added.
This allows dynamic log output filtering by plugins.
(Robert Collins)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-08-28 18:57:59 +0000
+++ b/bzrlib/branch.py 2008-09-04 05:23:39 +0000
@@ -91,6 +91,9 @@
self._revision_id_to_revno_cache = None
self._last_revision_info_cache = None
self._open_hook()
+ hooks = Branch.hooks['open']
+ for hook in hooks:
+ hook(self)
def _open_hook(self):
"""Called by init to allow simpler extension of the base class."""
@@ -1068,6 +1071,8 @@
# (branch, revision_history), and the branch will
# be write-locked.
self['set_rh'] = []
+ # Invoked after a branch is opened. The api signature is (branch).
+ self['open'] = []
# invoked after a push operation completes.
# the api signature is
# (push_result)
=== modified file 'bzrlib/help_topics/en/hooks.txt'
--- a/bzrlib/help_topics/en/hooks.txt 2008-07-04 03:19:47 +0000
+++ b/bzrlib/help_topics/en/hooks.txt 2008-09-04 05:23:39 +0000
@@ -15,6 +15,12 @@
The class of each hook is given immediately after each hook type below.
+open (Branch)
+-------------
+
+Called after a Branch object is opened, with the Branch object.
+
+
post_push (Branch)
------------------
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2008-09-01 06:19:29 +0000
+++ b/bzrlib/remote.py 2008-09-04 05:23:39 +0000
@@ -1277,6 +1277,10 @@
self._repo_lock_token = None
self._lock_count = 0
self._leave_lock = False
+ # The base class init is not called.
+ hooks = branch.Branch.hooks['open']
+ for hook in hooks:
+ hook(self)
def _get_real_transport(self):
# if we try vfs access, return the real branch's vfs transport
=== modified file 'bzrlib/tests/branch_implementations/test_hooks.py'
--- a/bzrlib/tests/branch_implementations/test_hooks.py 2008-07-25 06:42:08 +0000
+++ b/bzrlib/tests/branch_implementations/test_hooks.py 2008-09-04 05:23:39 +0000
@@ -107,6 +107,27 @@
return branch
+class TestOpen(TestCaseWithMemoryTransport):
+
+ def capture_hook(self, branch):
+ self.hook_calls.append(branch)
+
+ def install_hook(self):
+ self.hook_calls = []
+ Branch.hooks.install_named_hook('open', self.capture_hook, None)
+
+ def test_create(self):
+ self.install_hook()
+ b = self.make_branch('.')
+ self.assertEqual([b], self.hook_calls)
+
+ def test_open(self):
+ branch_url = self.make_branch('.').bzrdir.root_transport.base
+ self.install_hook()
+ b = Branch.open(branch_url)
+ self.assertEqual([b], self.hook_calls)
+
+
class TestPreChangeBranchTip(ChangeBranchTipTestCase):
"""Tests for pre_change_branch_tip hook.
More information about the bazaar-commits
mailing list