Rev 3336: (Jelmer) Add MutableTree start_commit hook. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Apr 5 17:46:43 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3336
revision-id:pqm at pqm.ubuntu.com-20080405164635-lpul8ep0famwf5u5
parent: pqm at pqm.ubuntu.com-20080404122038-852408u460mitk5y
parent: jelmer at samba.org-20080405134537-br55msytmlapxjvf
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2008-04-05 17:46:35 +0100
message:
(Jelmer) Add MutableTree start_commit hook.
added:
bzrlib/tests/test_mutabletree.py test_mutabletree.py-20080405014429-2v0cdi3re320p8db-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
------------------------------------------------------------
revno: 3335.1.4
revision-id:jelmer at samba.org-20080405134537-br55msytmlapxjvf
parent: jelmer at samba.org-20080405022911-d6tfmx6y30e3f6cx
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: start-commit-hook
timestamp: Sat 2008-04-05 15:45:37 +0200
message:
Fix indentation, add version number.
modified:
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
------------------------------------------------------------
revno: 3335.1.3
revision-id:jelmer at samba.org-20080405022911-d6tfmx6y30e3f6cx
parent: jelmer at samba.org-20080405014818-0nene03mynptkxae
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: start-commit-hook
timestamp: Sat 2008-04-05 04:29:11 +0200
message:
Add tests for start_commit hook.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
------------------------------------------------------------
revno: 3335.1.2
revision-id:jelmer at samba.org-20080405014818-0nene03mynptkxae
parent: jelmer at samba.org-20080405014646-0vav5xn9xud7eaoe
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: start-commit-hook
timestamp: Sat 2008-04-05 03:48:18 +0200
message:
Add mutabletree hooks class and start_commit hook.
modified:
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
------------------------------------------------------------
revno: 3335.1.1
revision-id:jelmer at samba.org-20080405014646-0vav5xn9xud7eaoe
parent: pqm at pqm.ubuntu.com-20080404122038-852408u460mitk5y
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: start-commit-hook
timestamp: Sat 2008-04-05 03:46:46 +0200
message:
Add tests for mutabletree hooks.
added:
bzrlib/tests/test_mutabletree.py test_mutabletree.py-20080405014429-2v0cdi3re320p8db-1
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
=== added file 'bzrlib/tests/test_mutabletree.py'
--- a/bzrlib/tests/test_mutabletree.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_mutabletree.py 2008-04-05 01:46:46 +0000
@@ -0,0 +1,40 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for MutableTree.
+
+Most functionality of MutableTree is tested as part of WorkingTree.
+"""
+
+from bzrlib.tests import TestCase
+from bzrlib.mutabletree import MutableTree, MutableTreeHooks
+
+class TestHooks(TestCase):
+
+ def test_constructor(self):
+ """Check that creating a MutableTreeHooks instance has the right
+ defaults."""
+ hooks = MutableTreeHooks()
+ self.assertTrue("start_commit" in hooks,
+ "start_commit not in %s" % hooks)
+
+ def test_installed_hooks_are_MutableTreeHooks(self):
+ """The installed hooks object should be a MutableTreeHooks."""
+ # the installed hooks are saved in self._preserved_hooks.
+ self.assertIsInstance(self._preserved_hooks[MutableTree],
+ MutableTreeHooks)
+
+
=== modified file 'NEWS'
--- a/NEWS 2008-04-04 10:44:23 +0000
+++ b/NEWS 2008-04-05 02:29:11 +0000
@@ -32,6 +32,8 @@
* Added mail-mode GNU Emacs mail package as a mail_client.
(Xavier Maillard, Bojan Nikolic)
+ * Added start_commit hook for mutable trees. (Jelmer Vernooij, #186422)
+
IMPROVEMENTS:
* ``bzr commit --fixes`` now recognises "gnome" as a tag by default.
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2007-10-23 22:14:32 +0000
+++ b/bzrlib/mutabletree.py 2008-04-05 13:45:37 +0000
@@ -27,6 +27,7 @@
from bzrlib import (
add,
bzrdir,
+ hooks,
)
from bzrlib.osutils import dirname
from bzrlib.revisiontree import RevisionTree
@@ -183,6 +184,8 @@
revprops['author'] = author
# args for wt.commit start at message from the Commit.commit method,
args = (message, ) + args
+ for hook in MutableTree.hooks['start_commit']:
+ hook(self)
committed_id = commit.Commit().commit(working_tree=self,
revprops=revprops, *args, **kwargs)
return committed_id
@@ -466,6 +469,24 @@
self.set_parent_trees([(new_revid, rev_tree)])
+class MutableTreeHooks(hooks.Hooks):
+ """A dictionary mapping a hook name to a list of callables for mutabletree
+ hooks.
+ """
+
+ def __init__(self):
+ """Create the default hooks.
+
+ """
+ hooks.Hooks.__init__(self)
+ # Invoked before a commit is done in a tree. New in 1.4
+ self['start_commit'] = []
+
+
+# install the default hooks into the MutableTree class.
+MutableTree.hooks = MutableTreeHooks()
+
+
class _FastPath(object):
"""A path object with fast accessors for things like basename."""
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-04-04 10:44:23 +0000
+++ b/bzrlib/tests/__init__.py 2008-04-05 01:46:46 +0000
@@ -810,6 +810,7 @@
import bzrlib.smart.server
self._preserved_hooks = {
bzrlib.branch.Branch: bzrlib.branch.Branch.hooks,
+ bzrlib.mutabletree.MutableTree: bzrlib.mutabletree.MutableTree.hooks,
bzrlib.smart.server.SmartTCPServer: bzrlib.smart.server.SmartTCPServer.hooks,
}
self.addCleanup(self._restoreHooks)
@@ -2726,6 +2727,7 @@
'bzrlib.tests.test_missing',
'bzrlib.tests.test_msgeditor',
'bzrlib.tests.test_multiparent',
+ 'bzrlib.tests.test_mutabletree',
'bzrlib.tests.test_nonascii',
'bzrlib.tests.test_options',
'bzrlib.tests.test_osutils',
=== modified file 'bzrlib/tests/workingtree_implementations/test_commit.py'
--- a/bzrlib/tests/workingtree_implementations/test_commit.py 2007-11-13 17:48:49 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_commit.py 2008-04-05 02:29:11 +0000
@@ -23,6 +23,7 @@
bzrdir,
conflicts,
errors,
+ mutabletree,
osutils,
revision as _mod_revision,
ui,
@@ -536,3 +537,19 @@
],
factory._calls
)
+
+ def test_start_commit_hook(self):
+ """Make sure a start commit hook can modify the tree that is
+ committed."""
+ def start_commit_hook_adds_file(tree):
+ open(tree.abspath("newfile"), 'w').write("data")
+ tree.add(["newfile"])
+ def restoreDefaults():
+ mutabletree.MutableTree.hooks['start_commit'] = []
+ self.addCleanup(restoreDefaults)
+ tree = self.make_branch_and_tree('.')
+ mutabletree.MutableTree.hooks.install_hook('start_commit',
+ start_commit_hook_adds_file)
+ revid = tree.commit('first post')
+ committed_tree = tree.basis_tree()
+ self.assertTrue(committed_tree.has_filename("newfile"))
More information about the bazaar-commits
mailing list