Rev 5747: (jelmer) Support installing lazy hooks for all existing hook points, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Mar 31 16:28:30 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5747 [merge]
revision-id: pqm at pqm.ubuntu.com-20110331162811-w1uw1lgpr5fiawp5
parent: pqm at pqm.ubuntu.com-20110331143142-bna42j92s4mn6623
parent: jelmer at samba.org-20110331145827-39ydfy5jtalrz8ht
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-03-31 16:28:11 +0000
message:
  (jelmer) Support installing lazy hooks for all existing hook points,
   deprecate Hooks.create_hook. (Jelmer Vernooij)
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/hooks.py                hooks.py-20070325015548-ix4np2q0kd8452au-1
  bzrlib/info.py                 info.py-20050323235939-6bbfe7d9700b0b9b
  bzrlib/lock.py                 lock.py-20050527050856-ec090bb51bc03349
  bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
  bzrlib/merge_directive.py      merge_directive.py-20070228184838-ja62280spt1g7f4x-1
  bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
  bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
  bzrlib/plugins/changelog_merge/__init__.py __init__.py-20100920024628-tdrjysnxjm1q96oq-1
  bzrlib/plugins/launchpad/lp_propose.py lp_submit.py-20100120065117-penrmqruf596pui6-1
  bzrlib/plugins/news_merge/__init__.py __init__.py-20100113072530-qj0i1em8th5pqhat-3
  bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
  bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
  bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
  bzrlib/tests/test_hooks.py     test_hooks.py-20070628030849-89rtsbe5dmer5npz-1
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  bzrlib/tests/transport_util.py transportutil.py-20070525113600-5v2igk89s8fensom-1
  bzrlib/version_info_formats/format_rio.py format_rio.py-20060809202444-ike7i9ub03gb432p-2
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2011-03-26 01:37:08 +0000
+++ b/bzrlib/branch.py	2011-03-30 11:45:54 +0000
@@ -57,7 +57,7 @@
     needs_write_lock,
     only_raises,
     )
-from bzrlib.hooks import HookPoint, Hooks
+from bzrlib.hooks import Hooks
 from bzrlib.inter import InterObject
 from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
 from bzrlib import registry
@@ -1808,25 +1808,25 @@
         These are all empty initially, because by default nothing should get
         notified.
         """
-        Hooks.__init__(self)
-        self.create_hook(HookPoint('set_rh',
+        Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
+        self.add_hook('set_rh',
             "Invoked whenever the revision history has been set via "
             "set_revision_history. The api signature is (branch, "
             "revision_history), and the branch will be write-locked. "
             "The set_rh hook can be expensive for bzr to trigger, a better "
-            "hook to use is Branch.post_change_branch_tip.", (0, 15), None))
-        self.create_hook(HookPoint('open',
+            "hook to use is Branch.post_change_branch_tip.", (0, 15))
+        self.add_hook('open',
             "Called with the Branch object that has been opened after a "
-            "branch is opened.", (1, 8), None))
-        self.create_hook(HookPoint('post_push',
+            "branch is opened.", (1, 8))
+        self.add_hook('post_push',
             "Called after a push operation completes. post_push is called "
             "with a bzrlib.branch.BranchPushResult object and only runs in the "
-            "bzr client.", (0, 15), None))
-        self.create_hook(HookPoint('post_pull',
+            "bzr client.", (0, 15))
+        self.add_hook('post_pull',
             "Called after a pull operation completes. post_pull is called "
             "with a bzrlib.branch.PullResult object and only runs in the "
-            "bzr client.", (0, 15), None))
-        self.create_hook(HookPoint('pre_commit',
+            "bzr client.", (0, 15))
+        self.add_hook('pre_commit',
             "Called after a commit is calculated but before it is "
             "completed. pre_commit is called with (local, master, old_revno, "
             "old_revid, future_revno, future_revid, tree_delta, future_tree"
@@ -1835,29 +1835,29 @@
             "basis revision. hooks MUST NOT modify this delta. "
             " future_tree is an in-memory tree obtained from "
             "CommitBuilder.revision_tree() and hooks MUST NOT modify this "
-            "tree.", (0,91), None))
-        self.create_hook(HookPoint('post_commit',
+            "tree.", (0,91))
+        self.add_hook('post_commit',
             "Called in the bzr client after a commit has completed. "
             "post_commit is called with (local, master, old_revno, old_revid, "
             "new_revno, new_revid). old_revid is NULL_REVISION for the first "
-            "commit to a branch.", (0, 15), None))
-        self.create_hook(HookPoint('post_uncommit',
+            "commit to a branch.", (0, 15))
+        self.add_hook('post_uncommit',
             "Called in the bzr client after an uncommit completes. "
             "post_uncommit is called with (local, master, old_revno, "
             "old_revid, new_revno, new_revid) where local is the local branch "
             "or None, master is the target branch, and an empty branch "
-            "receives new_revno of 0, new_revid of None.", (0, 15), None))
-        self.create_hook(HookPoint('pre_change_branch_tip',
+            "receives new_revno of 0, new_revid of None.", (0, 15))
+        self.add_hook('pre_change_branch_tip',
             "Called in bzr client and server before a change to the tip of a "
             "branch is made. pre_change_branch_tip is called with a "
             "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
-            "commit, uncommit will all trigger this hook.", (1, 6), None))
-        self.create_hook(HookPoint('post_change_branch_tip',
+            "commit, uncommit will all trigger this hook.", (1, 6))
+        self.add_hook('post_change_branch_tip',
             "Called in bzr client and server after a change to the tip of a "
             "branch is made. post_change_branch_tip is called with a "
             "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
-            "commit, uncommit will all trigger this hook.", (1, 4), None))
-        self.create_hook(HookPoint('transform_fallback_location',
+            "commit, uncommit will all trigger this hook.", (1, 4))
+        self.add_hook('transform_fallback_location',
             "Called when a stacked branch is activating its fallback "
             "locations. transform_fallback_location is called with (branch, "
             "url), and should return a new url. Returning the same url "
@@ -1868,23 +1868,23 @@
             "fallback locations have not been activated. When there are "
             "multiple hooks installed for transform_fallback_location, "
             "all are called with the url returned from the previous hook."
-            "The order is however undefined.", (1, 9), None))
-        self.create_hook(HookPoint('automatic_tag_name',
+            "The order is however undefined.", (1, 9))
+        self.add_hook('automatic_tag_name',
             "Called to determine an automatic tag name for a revision. "
             "automatic_tag_name is called with (branch, revision_id) and "
             "should return a tag name or None if no tag name could be "
             "determined. The first non-None tag name returned will be used.",
-            (2, 2), None))
-        self.create_hook(HookPoint('post_branch_init',
+            (2, 2))
+        self.add_hook('post_branch_init',
             "Called after new branch initialization completes. "
             "post_branch_init is called with a "
             "bzrlib.branch.BranchInitHookParams. "
             "Note that init, branch and checkout (both heavyweight and "
-            "lightweight) will all trigger this hook.", (2, 2), None))
-        self.create_hook(HookPoint('post_switch',
+            "lightweight) will all trigger this hook.", (2, 2))
+        self.add_hook('post_switch',
             "Called after a checkout switches branch. "
             "post_switch is called with a "
-            "bzrlib.branch.SwitchHookParams.", (2, 2), None))
+            "bzrlib.branch.SwitchHookParams.", (2, 2))
 
 
 

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-03-24 01:23:35 +0000
+++ b/bzrlib/bzrdir.py	2011-03-30 11:45:54 +0000
@@ -1082,15 +1082,15 @@
 
     def __init__(self):
         """Create the default hooks."""
-        hooks.Hooks.__init__(self)
-        self.create_hook(hooks.HookPoint('pre_open',
+        hooks.Hooks.__init__(self, "bzrlib.bzrdir", "BzrDir.hooks")
+        self.add_hook('pre_open',
             "Invoked before attempting to open a BzrDir with the transport "
-            "that the open will use.", (1, 14), None))
-        self.create_hook(hooks.HookPoint('post_repo_init',
+            "that the open will use.", (1, 14))
+        self.add_hook('post_repo_init',
             "Invoked after a repository has been initialized. "
             "post_repo_init is called with a "
             "bzrlib.bzrdir.RepoInitHookParams.",
-            (2, 2), None))
+            (2, 2))
 
 # install the default hooks
 BzrDir.hooks = BzrDirHooks()

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2011-02-04 22:25:59 +0000
+++ b/bzrlib/commands.py	2011-03-30 11:45:54 +0000
@@ -46,7 +46,7 @@
     )
 """)
 
-from bzrlib.hooks import HookPoint, Hooks
+from bzrlib.hooks import Hooks
 # Compatibility - Option used to be in commands.
 from bzrlib.option import Option
 from bzrlib.plugin import disable_plugins, load_plugins
@@ -775,30 +775,30 @@
         These are all empty initially, because by default nothing should get
         notified.
         """
-        Hooks.__init__(self)
-        self.create_hook(HookPoint('extend_command',
+        Hooks.__init__(self, "bzrlib.commands", "Command.hooks")
+        self.add_hook('extend_command',
             "Called after creating a command object to allow modifications "
             "such as adding or removing options, docs etc. Called with the "
-            "new bzrlib.commands.Command object.", (1, 13), None))
-        self.create_hook(HookPoint('get_command',
+            "new bzrlib.commands.Command object.", (1, 13))
+        self.add_hook('get_command',
             "Called when creating a single command. Called with "
             "(cmd_or_None, command_name). get_command should either return "
             "the cmd_or_None parameter, or a replacement Command object that "
             "should be used for the command. Note that the Command.hooks "
             "hooks are core infrastructure. Many users will prefer to use "
             "bzrlib.commands.register_command or plugin_cmds.register_lazy.",
-            (1, 17), None))
-        self.create_hook(HookPoint('get_missing_command',
+            (1, 17))
+        self.add_hook('get_missing_command',
             "Called when creating a single command if no command could be "
             "found. Called with (command_name). get_missing_command should "
             "either return None, or a Command object to be used for the "
-            "command.", (1, 17), None))
-        self.create_hook(HookPoint('list_commands',
+            "command.", (1, 17))
+        self.add_hook('list_commands',
             "Called when enumerating commands. Called with a set of "
             "cmd_name strings for all the commands found so far. This set "
             " is safe to mutate - e.g. to remove a command. "
             "list_commands should return the updated set of command names.",
-            (1, 17), None))
+            (1, 17))
 
 Command.hooks = CommandHooks()
 

=== modified file 'bzrlib/hooks.py'
--- a/bzrlib/hooks.py	2011-02-18 17:44:53 +0000
+++ b/bzrlib/hooks.py	2011-03-30 13:03:08 +0000
@@ -145,10 +145,10 @@
         else:
             callbacks = None
         hookpoint = HookPoint(name=name, doc=doc, introduced=introduced,
-                              deprecated=deprecated,
-                              callbacks=callbacks)
+                              deprecated=deprecated, callbacks=callbacks)
         self[name] = hookpoint
 
+    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4)))
     def create_hook(self, hook):
         """Create a hook which can have callbacks registered for it.
 
@@ -392,6 +392,8 @@
     return '\n'.join(segments)
 
 
+# Lazily registered hooks. Maps (module, name, hook_name) tuples
+# to lists of tuples with objectgetters and names
 _lazy_hooks = {}
 
 

=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py	2010-04-30 11:35:43 +0000
+++ b/bzrlib/info.py	2011-03-30 11:45:54 +0000
@@ -481,12 +481,11 @@
     """Hooks for the info command."""
 
     def __init__(self):
-        super(InfoHooks, self).__init__()
-        self.create_hook(_mod_hooks.HookPoint('repository',
+        super(InfoHooks, self).__init__("bzrlib.info", "hooks")
+        self.add_hook('repository',
             "Invoked when displaying the statistics for a repository. "
             "repository is called with a statistics dictionary as returned "
-            "by the repository and a file-like object to write to.", (1, 15), 
-            None))
+            "by the repository and a file-like object to write to.", (1, 15))
 
 
 hooks = InfoHooks()

=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py	2010-05-11 08:36:16 +0000
+++ b/bzrlib/lock.py	2011-03-30 11:45:54 +0000
@@ -45,22 +45,22 @@
     osutils,
     trace,
     )
-from bzrlib.hooks import HookPoint, Hooks
+from bzrlib.hooks import Hooks
 
 
 class LockHooks(Hooks):
 
     def __init__(self):
-        Hooks.__init__(self)
-        self.create_hook(HookPoint('lock_acquired',
-            "Called with a bzrlib.lock.LockResult when a physical lock is "
-            "acquired.", (1, 8), None))
-        self.create_hook(HookPoint('lock_released',
-            "Called with a bzrlib.lock.LockResult when a physical lock is "
-            "released.", (1, 8), None))
-        self.create_hook(HookPoint('lock_broken',
-            "Called with a bzrlib.lock.LockResult when a physical lock is "
-            "broken.", (1, 15), None))
+        Hooks.__init__(self, "bzrlib.lock", "Lock.hooks")
+        self.add_hook('lock_acquired',
+            "Called with a bzrlib.lock.LockResult when a physical lock is "
+            "acquired.", (1, 8))
+        self.add_hook('lock_released',
+            "Called with a bzrlib.lock.LockResult when a physical lock is "
+            "released.", (1, 8))
+        self.add_hook('lock_broken',
+            "Called with a bzrlib.lock.LockResult when a physical lock is "
+            "broken.", (1, 15))
 
 
 class Lock(object):

=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py	2011-02-07 04:14:29 +0000
+++ b/bzrlib/merge.py	2011-03-30 11:45:54 +0000
@@ -62,8 +62,8 @@
 class MergeHooks(hooks.Hooks):
 
     def __init__(self):
-        hooks.Hooks.__init__(self)
-        self.create_hook(hooks.HookPoint('merge_file_content',
+        hooks.Hooks.__init__(self, "bzrlib.merge", "Merger.hooks")
+        self.add_hook('merge_file_content',
             "Called with a bzrlib.merge.Merger object to create a per file "
             "merge object when starting a merge. "
             "Should return either None or a subclass of "
@@ -73,7 +73,7 @@
             "side has deleted the file and the other has changed it). "
             "See the AbstractPerFileMerger API docs for details on how it is "
             "used by merge.",
-            (2, 1), None))
+            (2, 1))
 
 
 class AbstractPerFileMerger(object):

=== modified file 'bzrlib/merge_directive.py'
--- a/bzrlib/merge_directive.py	2011-02-19 21:00:05 +0000
+++ b/bzrlib/merge_directive.py	2011-03-30 11:45:54 +0000
@@ -59,12 +59,12 @@
     """Hooks for MergeDirective classes."""
 
     def __init__(self):
-        hooks.Hooks.__init__(self)
-        self.create_hook(hooks.HookPoint('merge_request_body',
+        hooks.Hooks.__init__(self, "bzrlib.merge_directive", "BaseMergeDirective.hooks")
+        self.add_hook('merge_request_body',
             "Called with a MergeRequestBodyParams when a body is needed for"
             " a merge request.  Callbacks must return a body.  If more"
             " than one callback is registered, the output of one callback is"
-            " provided to the next.", (1, 15, 0), False))
+            " provided to the next.", (1, 15, 0))
 
 
 class BaseMergeDirective(object):

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2011-02-07 01:30:38 +0000
+++ b/bzrlib/msgeditor.py	2011-03-30 11:45:54 +0000
@@ -31,7 +31,7 @@
     ui,
     )
 from bzrlib.errors import BzrError, BadCommitMessageEncoding
-from bzrlib.hooks import HookPoint, Hooks
+from bzrlib.hooks import Hooks
 
 
 def _get_editor():
@@ -302,8 +302,8 @@
 
         These are all empty initially.
         """
-        Hooks.__init__(self)
-        self.create_hook(HookPoint('commit_message_template',
+        Hooks.__init__(self, "bzrlib.msgeditor", "hooks")
+        self.add_hook('commit_message_template',
             "Called when a commit message is being generated. "
             "commit_message_template is called with the bzrlib.commit.Commit "
             "object and the message that is known so far. "
@@ -311,7 +311,7 @@
             "could be the same as it was given. When there are multiple "
             "hooks registered for commit_message_template, they are chained "
             "with the result from the first passed into the second, and so "
-            "on.", (1, 10), None))
+            "on.", (1, 10))
 
 
 hooks = MessageEditorHooks()

=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py	2011-03-06 18:10:47 +0000
+++ b/bzrlib/mutabletree.py	2011-03-30 11:45:54 +0000
@@ -652,17 +652,17 @@
         """Create the default hooks.
 
         """
-        hooks.Hooks.__init__(self)
-        self.create_hook(hooks.HookPoint('start_commit',
+        hooks.Hooks.__init__(self, "bzrlib.mutabletree", "MutableTree.hooks")
+        self.add_hook('start_commit',
             "Called before a commit is performed on a tree. The start commit "
             "hook is able to change the tree before the commit takes place. "
             "start_commit is called with the bzrlib.mutabletree.MutableTree "
-            "that the commit is being performed on.", (1, 4), None))
-        self.create_hook(hooks.HookPoint('post_commit',
+            "that the commit is being performed on.", (1, 4))
+        self.add_hook('post_commit',
             "Called after a commit is performed on a tree. The hook is "
             "called with a bzrlib.mutabletree.PostCommitHookParams object. "
             "The mutable tree the commit was performed on is available via "
-            "the mutable_tree attribute of that object.", (2, 0), None))
+            "the mutable_tree attribute of that object.", (2, 0))
 
 
 # install the default hooks into the MutableTree class.

=== modified file 'bzrlib/plugins/changelog_merge/__init__.py'
--- a/bzrlib/plugins/changelog_merge/__init__.py	2011-03-15 07:56:42 +0000
+++ b/bzrlib/plugins/changelog_merge/__init__.py	2011-03-30 14:23:59 +0000
@@ -55,27 +55,17 @@
 
 # Since we are a built-in plugin we share the bzrlib version
 from bzrlib import version_info
+from bzrlib.hooks import install_lazy_named_hook
 
 # Put most of the code in a separate module that we lazy-import to keep the
 # overhead of this plugin as minimal as possible.
-from bzrlib.lazy_import import lazy_import
-lazy_import(globals(), """
-from bzrlib.plugins.changelog_merge import changelog_merge as _mod_changelog_merge
-""")
-
-from bzrlib.merge import Merger
-
-
 def changelog_merge_hook(merger):
     """Merger.merge_file_content hook for GNU-format ChangeLog files."""
-    return _mod_changelog_merge.ChangeLogMerger(merger)
-
-
-def install_hook():
-    Merger.hooks.install_named_hook(
-        'merge_file_content', changelog_merge_hook, 'GNU ChangeLog file merge')
-install_hook()
-
+    from brlib.plugins.changelog_merge.changelog_merge import ChangeLogMerger
+    return ChangeLogMerger(merger)
+
+install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
+    changelog_merge_hook, 'GNU ChangeLog file merge')
 
 def load_tests(basic_tests, module, loader):
     testmod_names = [
@@ -84,4 +74,3 @@
     basic_tests.addTest(loader.loadTestsFromModuleNames(
             ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
     return basic_tests
-

=== modified file 'bzrlib/plugins/launchpad/lp_propose.py'
--- a/bzrlib/plugins/launchpad/lp_propose.py	2011-01-19 16:57:38 +0000
+++ b/bzrlib/plugins/launchpad/lp_propose.py	2011-03-30 11:45:54 +0000
@@ -36,19 +36,12 @@
     """Hooks for proposing a merge on Launchpad."""
 
     def __init__(self):
-        hooks.Hooks.__init__(self)
-        self.create_hook(
-            hooks.HookPoint(
-                'get_prerequisite',
-                "Return the prerequisite branch for proposing as merge.",
-                (2, 1), None),
-        )
-        self.create_hook(
-            hooks.HookPoint(
-                'merge_proposal_body',
-                "Return an initial body for the merge proposal message.",
-                (2, 1), None),
-        )
+        hooks.Hooks.__init__(self, "bzrlib.plugins.launchpad.lp_propose",
+            "Proposer.hooks")
+        self.add_hook('get_prerequisite',
+            "Return the prerequisite branch for proposing as merge.", (2, 1))
+        self.add_hook('merge_proposal_body',
+            "Return an initial body for the merge proposal message.", (2, 1))
 
 
 class Proposer(object):

=== modified file 'bzrlib/plugins/news_merge/__init__.py'
--- a/bzrlib/plugins/news_merge/__init__.py	2010-05-03 04:08:50 +0000
+++ b/bzrlib/plugins/news_merge/__init__.py	2011-03-30 14:23:59 +0000
@@ -33,26 +33,17 @@
 
 # Since we are a built-in plugin we share the bzrlib version
 from bzrlib import version_info
-
-# Put most of the code in a separate module that we lazy-import to keep the
-# overhead of this plugin as minimal as possible.
-from bzrlib.lazy_import import lazy_import
-lazy_import(globals(), """
-from bzrlib.plugins.news_merge import news_merge as _mod_news_merge
-""")
-
-from bzrlib.merge import Merger
+from bzrlib.hooks import install_lazy_named_hook
 
 
 def news_merge_hook(merger):
     """Merger.merge_file_content hook for bzr-format NEWS files."""
-    return _mod_news_merge.NewsMerger(merger)
-
-
-def install_hook():
-    Merger.hooks.install_named_hook(
-        'merge_file_content', news_merge_hook, 'NEWS file merge')
-install_hook()
+    from bzrlib.plugins.news_merge.news_merge import NewsMerger
+    return NewsMerger(merger)
+
+
+install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
+    news_merge_hook, "NEWS file merge")
 
 
 def load_tests(basic_tests, module, loader):

=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/smart/client.py	2011-03-30 11:45:54 +0000
@@ -194,12 +194,12 @@
 class SmartClientHooks(hooks.Hooks):
 
     def __init__(self):
-        hooks.Hooks.__init__(self)
-        self.create_hook(hooks.HookPoint('call',
+        hooks.Hooks.__init__(self, "bzrlib.smart.client", "_SmartClient.hooks")
+        self.add_hook('call',
             "Called when the smart client is submitting a request to the "
             "smart server. Called with a bzrlib.smart.client.CallHookParams "
             "object. Streaming request bodies, and responses, are not "
-            "accessible.", None, None))
+            "accessible.", None)
 
 
 _SmartClient.hooks = SmartClientHooks()

=== modified file 'bzrlib/smart/server.py'
--- a/bzrlib/smart/server.py	2011-03-05 02:26:26 +0000
+++ b/bzrlib/smart/server.py	2011-03-30 11:45:54 +0000
@@ -22,7 +22,7 @@
 import sys
 import threading
 
-from bzrlib.hooks import HookPoint, Hooks
+from bzrlib.hooks import Hooks
 from bzrlib import (
     errors,
     trace,
@@ -239,21 +239,21 @@
         These are all empty initially, because by default nothing should get
         notified.
         """
-        Hooks.__init__(self)
-        self.create_hook(HookPoint('server_started',
+        Hooks.__init__(self, "bzrlib.smart.server", "SmartTCPServer.hooks")
+        self.add_hook('server_started',
             "Called by the bzr server when it starts serving a directory. "
             "server_started is called with (backing urls, public url), "
             "where backing_url is a list of URLs giving the "
             "server-specific directory locations, and public_url is the "
-            "public URL for the directory being served.", (0, 16), None))
-        self.create_hook(HookPoint('server_started_ex',
+            "public URL for the directory being served.", (0, 16))
+        self.add_hook('server_started_ex',
             "Called by the bzr server when it starts serving a directory. "
             "server_started is called with (backing_urls, server_obj).",
-            (1, 17), None))
-        self.create_hook(HookPoint('server_stopped',
+            (1, 17))
+        self.add_hook('server_stopped',
             "Called by the bzr server when it stops serving a directory. "
             "server_stopped is called with the same parameters as the "
-            "server_started hook: (backing_urls, public_url).", (0, 16), None))
+            "server_started hook: (backing_urls, public_url).", (0, 16))
 
 SmartTCPServer.hooks = SmartServerHooks()
 

=== modified file 'bzrlib/status.py'
--- a/bzrlib/status.py	2011-01-31 22:09:46 +0000
+++ b/bzrlib/status.py	2011-03-30 11:50:40 +0000
@@ -379,23 +379,23 @@
         These are all empty initially, because by default nothing should get
         notified.
         """
-        _mod_hooks.Hooks.__init__(self)
-        self.create_hook(_mod_hooks.HookPoint('post_status',
+        _mod_hooks.Hooks.__init__(self, "bzrlib.status", "hooks")
+        self.add_hook('post_status',
             "Called with argument StatusHookParams after Bazaar has "
             "displayed the status. StatusHookParams has the attributes "
             "(old_tree, new_tree, to_file, versioned, show_ids, short, "
             "verbose). The last four arguments correspond to the command "
             "line options specified by the user for the status command. "
             "to_file is the output stream for writing.",
-            (2, 3), None))
-        self.create_hook(_mod_hooks.HookPoint('pre_status',
+            (2, 3))
+        self.add_hook('pre_status',
             "Called with argument StatusHookParams before Bazaar "
             "displays the status. StatusHookParams has the attributes "
             "(old_tree, new_tree, to_file, versioned, show_ids, short, "
             "verbose). The last four arguments correspond to the command "
             "line options specified by the user for the status command. "
             "to_file is the output stream for writing.",
-            (2, 3), None))
+            (2, 3))
 
 
 class StatusHookParams(object):

=== modified file 'bzrlib/tests/test_hooks.py'
--- a/bzrlib/tests/test_hooks.py	2011-03-30 12:24:06 +0000
+++ b/bzrlib/tests/test_hooks.py	2011-03-30 13:03:08 +0000
@@ -39,39 +39,38 @@
 class TestHooks(tests.TestCase):
 
     def test_create_hook_first(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
         doc = ("Invoked after changing the tip of a branch object. Called with"
             "a bzrlib.branch.PostChangeBranchTipParams object")
         hook = HookPoint("post_tip_change", doc, (0, 15), None)
-        hooks.create_hook(hook)
+        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
         self.assertEqual(hook, hooks['post_tip_change'])
 
     def test_create_hook_name_collision_errors(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
         doc = ("Invoked after changing the tip of a branch object. Called with"
             "a bzrlib.branch.PostChangeBranchTipParams object")
         hook = HookPoint("post_tip_change", doc, (0, 15), None)
         hook2 = HookPoint("post_tip_change", None, None, None)
-        hooks.create_hook(hook)
-        self.assertRaises(errors.DuplicateKey, hooks.create_hook, hook2)
+        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
+        self.assertRaises(errors.DuplicateKey, self.applyDeprecated,
+            deprecated_in((2, 4, 0)), hooks.create_hook, hook2)
         self.assertEqual(hook, hooks['post_tip_change'])
 
     def test_docs(self):
         """docs() should return something reasonable about the Hooks."""
         class MyHooks(Hooks):
             pass
-        hooks = MyHooks()
+        hooks = MyHooks("bzrlib.tests.test_hooks", "some_hooks")
         hooks['legacy'] = []
-        hook1 = HookPoint('post_tip_change',
+        hooks.add_hook('post_tip_change',
             "Invoked after the tip of a branch changes. Called with "
-            "a ChangeBranchTipParams object.", (1, 4), None)
-        hook2 = HookPoint('pre_tip_change',
+            "a ChangeBranchTipParams object.", (1, 4))
+        hooks.add_hook('pre_tip_change',
             "Invoked before the tip of a branch changes. Called with "
             "a ChangeBranchTipParams object. Hooks should raise "
             "TipChangeRejected to signal that a tip change is not permitted.",
             (1, 6), None)
-        hooks.create_hook(hook1)
-        hooks.create_hook(hook2)
         self.assertEqualDiff(
             "MyHooks\n"
             "-------\n"
@@ -99,18 +98,18 @@
             "signal that a tip change is not permitted.\n", hooks.docs())
 
     def test_install_named_hook_raises_unknown_hook(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
         self.assertRaises(errors.UnknownHook, hooks.install_named_hook, 'silly',
                           None, "")
 
     def test_install_named_hook_appends_known_hook(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
         hooks['set_rh'] = []
         hooks.install_named_hook('set_rh', None, "demo")
         self.assertEqual(hooks['set_rh'], [None])
 
     def test_install_named_hook_and_retrieve_name(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.test_hooks", "somehooks")
         hooks['set_rh'] = []
         hooks.install_named_hook('set_rh', None, "demo")
         self.assertEqual("demo", hooks.get_hook_name(None))
@@ -134,7 +133,7 @@
     set_rh = lambda: None
 
     def test_install_named_hook_lazy(self):
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
         hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
         hooks.install_named_hook_lazy('set_rh', 'bzrlib.tests.test_hooks',
             'TestHooks.set_rh', "demo")
@@ -143,7 +142,7 @@
     def test_install_named_hook_lazy_old(self):
         # An exception is raised if a lazy hook is raised for
         # an old style hook point.
-        hooks = Hooks()
+        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
         hooks['set_rh'] = []
         self.assertRaises(errors.UnsupportedOperation,
             hooks.install_named_hook_lazy,

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-03-29 04:30:03 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-03-31 16:28:11 +0000
@@ -1437,12 +1437,12 @@
         # Note this test won't fail with hooks that the core library doesn't
         # use - but it trigger with a plugin that adds hooks, so its still a
         # useful warning in that case.
-        self.assertEqual(bzrlib.branch.BranchHooks(),
-            bzrlib.branch.Branch.hooks)
-        self.assertEqual(bzrlib.smart.server.SmartServerHooks(),
+        self.assertEqual(bzrlib.branch.BranchHooks(), bzrlib.branch.Branch.hooks)
+        self.assertEqual(
+            bzrlib.smart.server.SmartServerHooks(),
             bzrlib.smart.server.SmartTCPServer.hooks)
-        self.assertEqual(bzrlib.commands.CommandHooks(),
-            bzrlib.commands.Command.hooks)
+        self.assertEqual(
+            bzrlib.commands.CommandHooks(), bzrlib.commands.Command.hooks)
 
     def test__gather_lsprof_in_benchmarks(self):
         """When _gather_lsprof_in_benchmarks is on, accumulate profile data.

=== modified file 'bzrlib/tests/transport_util.py'
--- a/bzrlib/tests/transport_util.py	2011-01-26 19:34:58 +0000
+++ b/bzrlib/tests/transport_util.py	2011-03-30 11:45:54 +0000
@@ -47,7 +47,8 @@
     """Dict-mapping hook name to a list of callables for transport hooks"""
 
     def __init__(self):
-        super(TransportHooks, self).__init__()
+        super(TransportHooks, self).__init__("bzrlib.tests.transport_util",
+            "InstrumentedTransport.hooks")
         # Invoked when the transport has just created a new connection.
         # The api signature is (transport, connection, credentials)
         self['_set_connection'] = []

=== modified file 'bzrlib/version_info_formats/format_rio.py'
--- a/bzrlib/version_info_formats/format_rio.py	2011-02-18 19:01:43 +0000
+++ b/bzrlib/version_info_formats/format_rio.py	2011-03-30 11:45:54 +0000
@@ -89,7 +89,7 @@
         self.add_hook('revision',
             "Invoked when adding information about a revision to the"
             " RIO stanza that is printed. revision is called with a"
-            " revision object and a RIO stanza.", (1, 15), None)
+            " revision object and a RIO stanza.", (1, 15))
 
 
 RioVersionInfoBuilder.hooks = RioVersionInfoBuilderHooks()

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-03-30 10:54:24 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-03-30 11:50:40 +0000
@@ -56,6 +56,9 @@
 .. Changes that may require updates in plugins or other code that uses
    bzrlib.
 
+* ``Hooks.create_hook`` is now deprecated in favour of ``Hooks.add_hook``.
+  (Jelmer Vernooij)
+
 Internals
 *********
 




More information about the bazaar-commits mailing list