Merge lp:~jelmer/bzr/transform-hooks into lp:bzr/2.5

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6444
Proposed branch: lp:~jelmer/bzr/transform-hooks
Merge into: lp:bzr/2.5
Diff against target: 128 lines (+56/-2)
4 files modified
bzrlib/mutabletree.py (+9/-1)
bzrlib/tests/test_transform.py (+38/-0)
bzrlib/transform.py (+5/-1)
doc/en/release-notes/bzr-2.5.txt (+4/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/transform-hooks
Reviewer Review Type Date Requested Status
Vincent Ladeuil Pending
Review via email: mp+89007@code.launchpad.net

This proposal supersedes a proposal from 2012-01-06.

Commit message

Add pre_transform and post_transform hooks.

Description of the change

Add pre_transform and post_transform hooks to MutableTree.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote : Posted in a previous version of this proposal

Fine to land in trunk (aka s/2.5/2.6 and move... news entry :-p)

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/mutabletree.py'
--- bzrlib/mutabletree.py 2012-01-06 14:09:04 +0000
+++ bzrlib/mutabletree.py 2012-01-18 10:57:25 +0000
@@ -520,10 +520,18 @@
520 "called with a bzrlib.mutabletree.PostCommitHookParams object. "520 "called with a bzrlib.mutabletree.PostCommitHookParams object. "
521 "The mutable tree the commit was performed on is available via "521 "The mutable tree the commit was performed on is available via "
522 "the mutable_tree attribute of that object.", (2, 0))522 "the mutable_tree attribute of that object.", (2, 0))
523 self.add_hook('pre_transform',
524 "Called before a tree transform on this tree. The hook is called "
525 "with the tree that is being transformed and the transform.",
526 (2, 5))
523 self.add_hook('post_build_tree',527 self.add_hook('post_build_tree',
524 "Called after a completely new tree is built. The hook is "528 "Called after a completely new tree is built. The hook is "
525 "called with the tree as its only argument.", (2, 5))529 "called with the tree as its only argument.", (2, 5))
526530 self.add_hook('post_transform',
531 "Called after a tree transform has been performed on a tree. "
532 "The hook is called with the tree that is being transformed and "
533 "the transform.",
534 (2, 5))
527535
528# install the default hooks into the MutableTree class.536# install the default hooks into the MutableTree class.
529MutableTree.hooks = MutableTreeHooks()537MutableTree.hooks = MutableTreeHooks()
530538
=== modified file 'bzrlib/tests/test_transform.py'
--- bzrlib/tests/test_transform.py 2011-11-17 13:45:49 +0000
+++ bzrlib/tests/test_transform.py 2012-01-18 10:57:25 +0000
@@ -60,6 +60,7 @@
60 pathjoin,60 pathjoin,
61)61)
62from bzrlib.merge import Merge3Merger, Merger62from bzrlib.merge import Merge3Merger, Merger
63from bzrlib.mutabletree import MutableTree
63from bzrlib.tests import (64from bzrlib.tests import (
64 features,65 features,
65 TestCaseInTempDir,66 TestCaseInTempDir,
@@ -3717,3 +3718,40 @@
3717 remaining_conflicts.pop())3718 remaining_conflicts.pop())
3718 self.assertLength(1, warnings)3719 self.assertLength(1, warnings)
3719 self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')3720 self.assertStartsWith(warnings[0], 'donttouchmypreciouuus')
3721
3722
3723class TestTransformHooks(tests.TestCaseWithTransport):
3724
3725 def setUp(self):
3726 super(TestTransformHooks, self).setUp()
3727 self.wt = self.make_branch_and_tree('.')
3728 os.chdir('..')
3729
3730 def get_transform(self):
3731 transform = TreeTransform(self.wt)
3732 self.addCleanup(transform.finalize)
3733 return transform, transform.root
3734
3735 def test_pre_commit_hooks(self):
3736 calls = []
3737 def record_pre_transform(tree, tt):
3738 calls.append((tree, tt))
3739 MutableTree.hooks.install_named_hook('pre_transform',
3740 record_pre_transform, "Pre transform")
3741 transform, root = self.get_transform()
3742 old_root_id = transform.tree_file_id(root)
3743 transform.apply()
3744 self.assertEqual(old_root_id, self.wt.get_root_id())
3745 self.assertEquals([(self.wt, transform)], calls)
3746
3747 def test_post_commit_hooks(self):
3748 calls = []
3749 def record_post_transform(tree, tt):
3750 calls.append((tree, tt))
3751 MutableTree.hooks.install_named_hook('post_transform',
3752 record_post_transform, "Post transform")
3753 transform, root = self.get_transform()
3754 old_root_id = transform.tree_file_id(root)
3755 transform.apply()
3756 self.assertEqual(old_root_id, self.wt.get_root_id())
3757 self.assertEquals([(self.wt, transform)], calls)
37203758
=== modified file 'bzrlib/transform.py'
--- bzrlib/transform.py 2012-01-17 14:45:27 +0000
+++ bzrlib/transform.py 2012-01-18 10:57:25 +0000
@@ -50,6 +50,7 @@
50 ExistingLimbo, ImmortalLimbo, NoFinalPath,50 ExistingLimbo, ImmortalLimbo, NoFinalPath,
51 UnableCreateSymlink)51 UnableCreateSymlink)
52from bzrlib.filters import filtered_output_bytes, ContentFilterContext52from bzrlib.filters import filtered_output_bytes, ContentFilterContext
53from bzrlib.mutabletree import MutableTree
53from bzrlib.osutils import (54from bzrlib.osutils import (
54 delete_any,55 delete_any,
55 file_kind,56 file_kind,
@@ -57,7 +58,6 @@
57 pathjoin,58 pathjoin,
58 sha_file,59 sha_file,
59 splitpath,60 splitpath,
60 supports_executable,
61 )61 )
62from bzrlib.progress import ProgressPhase62from bzrlib.progress import ProgressPhase
63from bzrlib.symbol_versioning import (63from bzrlib.symbol_versioning import (
@@ -156,6 +156,8 @@
156 """156 """
157 if self._tree is None:157 if self._tree is None:
158 return158 return
159 for hook in MutableTree.hooks['post_transform']:
160 hook(self._tree, self)
159 self._tree.unlock()161 self._tree.unlock()
160 self._tree = None162 self._tree = None
161163
@@ -1722,6 +1724,8 @@
1722 calculating one.1724 calculating one.
1723 :param _mover: Supply an alternate FileMover, for testing1725 :param _mover: Supply an alternate FileMover, for testing
1724 """1726 """
1727 for hook in MutableTree.hooks['pre_transform']:
1728 hook(self._tree, self)
1725 if not no_conflicts:1729 if not no_conflicts:
1726 self._check_malformed()1730 self._check_malformed()
1727 child_pb = ui.ui_factory.nested_progress_bar()1731 child_pb = ui.ui_factory.nested_progress_bar()
17281732
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- doc/en/release-notes/bzr-2.5.txt 2012-01-17 16:02:03 +0000
+++ doc/en/release-notes/bzr-2.5.txt 2012-01-18 10:57:25 +0000
@@ -52,6 +52,10 @@
52.. Major internal changes, unlikely to be visible to users or plugin 52.. Major internal changes, unlikely to be visible to users or plugin
53 developers, but interesting for bzr developers.53 developers, but interesting for bzr developers.
5454
55* ``MutableTree`` has two new hooks ``pre_transform`` and
56 ``post_transform`` that are called for tree transform operations.
57 (Jelmer Vernooij, #912084)
58
55Testing59Testing
56*******60*******
5761

Subscribers

People subscribed via source and target branches