Rev 3361: Add a hook for Branch.set_last_revision_info. (James Henstridge, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Apr 11 08:03:14 BST 2008


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

------------------------------------------------------------
revno: 3361
revision-id:pqm at pqm.ubuntu.com-20080411070305-2yg29trk4rzvgb1u
parent: pqm at pqm.ubuntu.com-20080411023221-tiv070pmkmf5q726
parent: andrew.bennetts at canonical.com-20080411045144-nu3ofu2nrfyszvma
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-04-11 08:03:05 +0100
message:
  Add a hook for Branch.set_last_revision_info. (James Henstridge,
  	Ian Clatworthy)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
  bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
  bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
    ------------------------------------------------------------
    revno: 3331.1.15
    revision-id:andrew.bennetts at canonical.com-20080411045144-nu3ofu2nrfyszvma
    parent: james at jamesh.id.au-20080409070934-8oouilavaxniz4vn
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: set_last_revision_info-hook
    timestamp: Fri 2008-04-11 14:51:44 +1000
    message:
      Use _write_last_revision_info rather than set_last_revision_info in Converter5to6, because we just want to write the last-revision file, not trigger hooks with half-converted branches.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 3331.1.14
    revision-id:james at jamesh.id.au-20080409070934-8oouilavaxniz4vn
    parent: james at jamesh.id.au-20080409065859-e5cpv7cj5smqqv5b
    parent: pqm at pqm.ubuntu.com-20080409055704-gkzxh5nkpxai1h6x
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 15:09:34 +0800
    message:
      merge from bzr.dev fixing conflicts
    added:
      bzrlib/tests/test_mutabletree.py test_mutabletree.py-20080405014429-2v0cdi3re320p8db-1
      doc/developers/integration.txt integration.txt-20080404022341-2lorxocp1in07zij-1
      doc/developers/plugin-api.txt  pluginapi.txt-20080229110225-q2j5y4agqhlkjn0s-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/tests/TestUtil.py       TestUtil.py-20050824080200-5f70140a2d938694
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_plugins.py   plugins.py-20050622075746-32002b55e5e943e9
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/en/user-guide/core_concepts.txt core_concepts.txt-20071114035000-q36a9h57ps06uvnl-2
    ------------------------------------------------------------
    revno: 3331.1.13
    revision-id:james at jamesh.id.au-20080409065859-e5cpv7cj5smqqv5b
    parent: james at jamesh.id.au-20080409064342-0xcvcq3vmvbwjhky
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 14:58:59 +0800
    message:
      Use last_revision_info() to retrieve the new revision number and ID.  
      This way we are sure that the params object is consistent with the 
      branch.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 3331.1.12
    revision-id:james at jamesh.id.au-20080409064342-0xcvcq3vmvbwjhky
    parent: james at jamesh.id.au-20080409064144-7iyvi9i3lvfv5265
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 14:43:42 +0800
    message:
      make sure that last_revision_info() matches data in params
    modified:
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
    ------------------------------------------------------------
    revno: 3331.1.11
    revision-id:james at jamesh.id.au-20080409064144-7iyvi9i3lvfv5265
    parent: james at jamesh.id.au-20080409064111-qjndmdy9500m0au5
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 14:41:44 +0800
    message:
      Note that the revision numbers are integers in the docs.
    modified:
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
    ------------------------------------------------------------
    revno: 3331.1.10
    revision-id:james at jamesh.id.au-20080409064111-qjndmdy9500m0au5
    parent: james at jamesh.id.au-20080409063358-6slk3yl0dgcalq2j
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 14:41:11 +0800
    message:
      Run the hook after the cached data is cleared for BzrBranch6, to match 
      behaviour of other formats.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 3331.1.9
    revision-id:james at jamesh.id.au-20080409063358-6slk3yl0dgcalq2j
    parent: james at jamesh.id.au-20080409034224-a5pm1290zhokn2uw
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 14:33:58 +0800
    message:
      Call _make_branch_tip_hook_params() after ensure_null()
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 3331.1.8
    revision-id:james at jamesh.id.au-20080409034224-a5pm1290zhokn2uw
    parent: james at jamesh.id.au-20080409033823-nxyw0jisw6qdh9jn
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 11:42:24 +0800
    message:
      Update help text to match change to params.
    modified:
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
    ------------------------------------------------------------
    revno: 3331.1.7
    revision-id:james at jamesh.id.au-20080409033823-nxyw0jisw6qdh9jn
    parent: james at jamesh.id.au-20080409031823-o9zzg0d9qi9vhtuf
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 11:38:23 +0800
    message:
      Make the branch a member of the ChangeBranchTipParams object.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
    ------------------------------------------------------------
    revno: 3331.1.6
    revision-id:james at jamesh.id.au-20080409031823-o9zzg0d9qi9vhtuf
    parent: james at jamesh.id.au-20080409031642-ru70fo7xcn38uin0
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 11:18:23 +0800
    message:
      Add my name to the NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3331.1.5
    revision-id:james at jamesh.id.au-20080409031642-ru70fo7xcn38uin0
    parent: james at jamesh.id.au-20080409030958-rzc9aplft44hpq35
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 11:16:42 +0800
    message:
      Put revno before revid in method arguments to match last_revision_info() 
      ordering: having them different is asking for bugs.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
    ------------------------------------------------------------
    revno: 3331.1.4
    revision-id:james at jamesh.id.au-20080409030958-rzc9aplft44hpq35
    parent: james at jamesh.id.au-20080409025318-1y8pi84bag2exhgk
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 11:09:58 +0800
    message:
      Adjust my tests to pass with Ian's API.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
    ------------------------------------------------------------
    revno: 3331.1.3
    revision-id:james at jamesh.id.au-20080409025318-1y8pi84bag2exhgk
    parent: james at jamesh.id.au-20080403083859-0wvldzj00arab75i
    parent: ian.clatworthy at canonical.com-20080401080826-85zjvdb6w6x8ah5d
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Wed 2008-04-09 10:53:18 +0800
    message:
      merge Ian's branch
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
        ------------------------------------------------------------
        revno: 3323.2.1
        revision-id:ian.clatworthy at canonical.com-20080401080826-85zjvdb6w6x8ah5d
        parent: pqm at pqm.ubuntu.com-20080401055945-3pmuiy0q0301axv6
        committer: Ian Clatworthy <ian.clatworthy at canonical.com>
        branch nick: bzr.new-tip-hook
        timestamp: Tue 2008-04-01 18:08:26 +1000
        message:
          first cut at post_change_branch_tip hook
        modified:
          NEWS                           NEWS-20050323055033-4e00b5db738777ff
          bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
          bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
    ------------------------------------------------------------
    revno: 3331.1.2
    revision-id:james at jamesh.id.au-20080403083859-0wvldzj00arab75i
    parent: james at jamesh.id.au-20080403080915-utjwj6xfwq55hnqh
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Thu 2008-04-03 16:38:59 +0800
    message:
      Add calls to set_last_revision_info hook to both BzrBranch and 
      BzrBranch6.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
    ------------------------------------------------------------
    revno: 3331.1.1
    revision-id:james at jamesh.id.au-20080403080915-utjwj6xfwq55hnqh
    parent: pqm at pqm.ubuntu.com-20080403080121-tbx3clqp8wqe776c
    committer: James Henstridge <james at jamesh.id.au>
    branch nick: bzr.last-revision-info-hook
    timestamp: Thu 2008-04-03 16:09:15 +0800
    message:
      Add set_last_revision_info hook.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'NEWS'
--- a/NEWS	2008-04-10 16:41:50 +0000
+++ b/NEWS	2008-04-11 07:03:05 +0000
@@ -17,6 +17,10 @@
    * On Linux bzr additionally looks for plugins in arch-independent site
      directory. (Toshio Kuratomi)
 
+   * The ``set_rh`` branch hook is now deprecated. Please migrate
+     any plugins using this hook to use an alternative, e.g.
+     ``post_change_branch_tip``. (Ian Clatworthy)
+
    * When a plugin cannot be loaded as the file path is not a valid
      python module name bzr will now strip a ``bzr_`` prefix from the
      front of the suggested name, as many plugins (e.g. bzr-svn)
@@ -41,6 +45,11 @@
       listing pending merges, which speeds up the command a lot on large
       histories.  (James Westby, #202830)
 
+    * New ``post_change_branch_tip`` hook that is called after the
+      branch tip is moved but while the branch is still write-locked.
+      See the User Reference for signature details.
+      (Ian Clatworthy, James Henstridge)
+
   IMPROVEMENTS:
 
     * The smart protocol now has support for setting branches' revision info

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-04-03 00:23:41 +0000
+++ b/bzrlib/branch.py	2008-04-11 04:51:44 +0000
@@ -1025,12 +1025,48 @@
         # local is the local branch or None, master is the target branch,
         # and an empty branch recieves new_revno of 0, new_revid of None.
         self['post_uncommit'] = []
+        # Introduced in 1.4
+        # Invoked after the tip of a branch changes.
+        # the api signature is
+        # (params) where params is a ChangeBranchTipParams with the members
+        # (branch, old_revno, new_revno, old_revid, new_revid)
+        self['post_change_branch_tip'] = []
 
 
 # install the default hooks into the Branch class.
 Branch.hooks = BranchHooks()
 
 
+class ChangeBranchTipParams(object):
+    """Object holding parameters passed to *_change_branch_tip hooks.
+
+    There are 5 fields that hooks may wish to access:
+
+    :ivar branch: the branch being changed
+    :ivar old_revno: revision number before the change
+    :ivar new_revno: revision number after the change
+    :ivar old_revid: revision id before the change
+    :ivar new_revid: revision id after the change
+
+    The revid fields are strings. The revno fields are integers.
+    """
+
+    def __init__(self, branch, old_revno, new_revno, old_revid, new_revid):
+        """Create a group of ChangeBranchTip parameters.
+
+        :param branch: The branch being changed.
+        :param old_revno: Revision number before the change.
+        :param new_revno: Revision number after the change.
+        :param old_revid: Tip revision id before the change.
+        :param new_revid: Tip revision id after the change.
+        """
+        self.branch = branch
+        self.old_revno = old_revno
+        self.new_revno = new_revno
+        self.old_revid = old_revid
+        self.new_revid = new_revid
+
+
 class BzrBranchFormat4(BranchFormat):
     """Bzr branch format 4.
 
@@ -1383,6 +1419,17 @@
         for hook in Branch.hooks['set_rh']:
             hook(self, rev_history)
 
+    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
+        """Run the post_change_branch_tip hooks."""
+        hooks = Branch.hooks['post_change_branch_tip']
+        if not hooks:
+            return
+        new_revno, new_revid = self.last_revision_info()
+        params = ChangeBranchTipParams(
+            self, old_revno, new_revno, old_revid, new_revid)
+        for hook in hooks:
+            hook(params)
+ 
     @needs_write_lock
     def set_last_revision_info(self, revno, revision_id):
         """Set the last revision of this branch.
@@ -1396,9 +1443,11 @@
         be permitted.
         """
         revision_id = _mod_revision.ensure_null(revision_id)
+        old_revno, old_revid = self.last_revision_info()
         history = self._lefthand_history(revision_id)
         assert len(history) == revno, '%d != %d' % (len(history), revno)
         self.set_revision_history(history)
+        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
 
     def _gen_revision_history(self):
         history = self.control_files.get('revision-history').read().split('\n')
@@ -1854,11 +1903,13 @@
     @needs_write_lock
     def set_last_revision_info(self, revno, revision_id):
         revision_id = _mod_revision.ensure_null(revision_id)
+        old_revno, old_revid = self.last_revision_info()
         if self._get_append_revisions_only():
             self._check_history_violation(revision_id)
         self._write_last_revision_info(revno, revision_id)
         self._clear_cached_state()
         self._last_revision_info_cache = revno, revision_id
+        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
 
     def _check_history_violation(self, revision_id):
         last_revision = _mod_revision.ensure_null(self.last_revision())
@@ -2149,7 +2200,7 @@
         new_branch = format.open(branch.bzrdir, _found=True)
 
         # Copy source data into target
-        new_branch.set_last_revision_info(*branch.last_revision_info())
+        new_branch._write_last_revision_info(*branch.last_revision_info())
         new_branch.set_parent(branch.get_parent())
         new_branch.set_bound_location(branch.get_bound_location())
         new_branch.set_push_location(branch.get_push_location())

=== modified file 'bzrlib/help_topics/en/hooks.txt'
--- a/bzrlib/help_topics/en/hooks.txt	2007-12-17 02:00:45 +0000
+++ b/bzrlib/help_topics/en/hooks.txt	2008-04-09 06:41:44 +0000
@@ -76,14 +76,38 @@
 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.
 
+post_change_branch_tip
+----------------------
+
+Run after a branch tip has been changed but while the branch is still
+write-locked. Note that push, pull, commit and uncommit all invoke this hook.
+
+The hook signature is (params), where params is an object containing
+the members
+
+  branch
+    The branch whose tip has been changed.
+
+  old_revno
+    The revision number (eg 10) of the branch before the change.
+
+  old_revid
+    The revision id (eg joe at foo.com-1234234-aoeua34) before the change.
+
+  new_revno
+    The revision number (eg 12) of the branch after the change.
+
+  new_revid
+    The revision id (eg joe at foo.com-5676566-boa234a) after the change.
+
+The old_revno and new_revno members are integers, as the head
+revision is never has a dotted revision number.
+
 set_rh
 ------
 
-Run after the branch's revision history has been modified (push, pull, commit
-and uncommit can all modify the revision history).
-
-The hook signature is (branch, revision_history), and the branch will be
-write-locked.
+Note: This hook is now deprecated and will be removed in the near future.
+Please use the ``post_change_branch_tip`` hook instead.
 
 See also `Using hooks`_ in the User Guide.
 

=== modified file 'bzrlib/tests/branch_implementations/test_hooks.py'
--- a/bzrlib/tests/branch_implementations/test_hooks.py	2007-08-14 11:42:58 +0000
+++ b/bzrlib/tests/branch_implementations/test_hooks.py	2008-04-09 06:43:42 +0000
@@ -17,6 +17,7 @@
 """Tests that branch classes implement hook callouts correctly."""
 
 from bzrlib.branch import Branch
+from bzrlib.revision import NULL_REVISION
 from bzrlib.tests import TestCaseWithMemoryTransport
 
 
@@ -72,3 +73,71 @@
             [('set_rh', branch, [], True),
              ('set_rh', branch, [], True),
             ])
+
+
+class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
+
+    def setUp(self):
+        self.hook_calls = []
+        TestCaseWithMemoryTransport.setUp(self)
+
+    def capture_post_change_branch_tip_hook(self, params):
+        """Capture post_change_branch_tip hook calls to self.hook_calls.
+
+        The call is logged, as is some state of the branch.
+        """
+        self.hook_calls.append((params, params.branch.is_locked()))
+        self.assertEquals(params.branch.last_revision_info(),
+                          (params.new_revno, params.new_revid))
+
+    def test_post_change_branch_tip_empty_history(self):
+        branch = self.make_branch('source')
+        Branch.hooks.install_hook('post_change_branch_tip',
+                                  self.capture_post_change_branch_tip_hook)
+        branch.set_last_revision_info(0, NULL_REVISION)
+        self.assertEqual(len(self.hook_calls), 1)
+        self.assertEqual(self.hook_calls[0][0].branch, branch)
+        self.assertEqual(self.hook_calls[0][0].old_revid, NULL_REVISION)
+        self.assertEqual(self.hook_calls[0][0].old_revno, 0)
+        self.assertEqual(self.hook_calls[0][0].new_revid, NULL_REVISION)
+        self.assertEqual(self.hook_calls[0][0].new_revno, 0)
+
+    def test_post_change_branch_tip_nonempty_history(self):
+        tree = self.make_branch_and_memory_tree('source')
+        tree.lock_write()
+        tree.add('')
+        tree.commit('another commit', rev_id='f\xc2\xb5')
+        tree.commit('empty commit', rev_id='foo')
+        tree.unlock()
+        branch = tree.branch
+        Branch.hooks.install_hook('post_change_branch_tip',
+                                  self.capture_post_change_branch_tip_hook)
+        # some branches require that their history be set to a revision in the
+        # repository
+        branch.set_last_revision_info(1, 'f\xc2\xb5')
+        self.assertEqual(len(self.hook_calls), 1)
+        self.assertEqual(self.hook_calls[0][0].branch, branch)
+        self.assertEqual(self.hook_calls[0][0].old_revid, 'foo')
+        self.assertEqual(self.hook_calls[0][0].old_revno, 2)
+        self.assertEqual(self.hook_calls[0][0].new_revid, 'f\xc2\xb5')
+        self.assertEqual(self.hook_calls[0][0].new_revno, 1)
+
+    def test_post_change_branch_tip_branch_is_locked(self):
+        branch = self.make_branch('source')
+        Branch.hooks.install_hook('post_change_branch_tip',
+                                  self.capture_post_change_branch_tip_hook)
+        branch.set_last_revision_info(0, NULL_REVISION)
+        self.assertEqual(len(self.hook_calls), 1)
+        self.assertEqual(self.hook_calls[0][0].branch, branch)
+        self.assertEqual(self.hook_calls[0][1], True)
+
+    def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
+        branch = self.make_branch('source')
+        Branch.hooks.install_hook('post_change_branch_tip',
+                                  self.capture_post_change_branch_tip_hook)
+        Branch.hooks.install_hook('post_change_branch_tip',
+                                  self.capture_post_change_branch_tip_hook)
+        branch.set_last_revision_info(0, NULL_REVISION)
+        self.assertEqual(len(self.hook_calls), 2)
+        self.assertEqual(self.hook_calls[0][0].branch, branch)
+        self.assertEqual(self.hook_calls[1][0].branch, branch)

=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py	2008-02-08 19:09:45 +0000
+++ b/bzrlib/tests/test_branch.py	2008-04-09 03:09:58 +0000
@@ -334,6 +334,8 @@
         self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
         self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
         self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
+        self.assertTrue("post_change_branch_tip" in hooks,
+                        "post_change_branch_tip not in %s" % hooks)
 
     def test_installed_hooks_are_BranchHooks(self):
         """The installed hooks object should be a BranchHooks."""




More information about the bazaar-commits mailing list