Merge lp:~jelmer/bzr/post-tree-build-hook into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Martin Packman
Approved revision: no longer in the source branch.
Merged at revision: 6436
Proposed branch: lp:~jelmer/bzr/post-tree-build-hook
Merge into: lp:bzr
Diff against target: 130 lines (+36/-1)
6 files modified
bzrlib/mutabletree.py (+3/-0)
bzrlib/plugins/weave_fmt/workingtree.py (+3/-0)
bzrlib/tests/per_workingtree/test_workingtree.py (+18/-0)
bzrlib/workingtree_3.py (+3/-0)
bzrlib/workingtree_4.py (+6/-1)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/post-tree-build-hook
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+87756@code.launchpad.net

Commit message

Add post_build_tree hook to MutableTree.

Description of the change

Add a post_tree_build hook, useful for bzr-builddeb.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Three callsites and one test worried me, but now I see it's a per_workingtree one, so ideal.

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

sent to pqm by email

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
1=== modified file 'bzrlib/mutabletree.py'
2--- bzrlib/mutabletree.py 2011-12-19 13:23:58 +0000
3+++ bzrlib/mutabletree.py 2012-01-06 19:50:29 +0000
4@@ -520,6 +520,9 @@
5 "called with a bzrlib.mutabletree.PostCommitHookParams object. "
6 "The mutable tree the commit was performed on is available via "
7 "the mutable_tree attribute of that object.", (2, 0))
8+ self.add_hook('post_build_tree',
9+ "Called after a completely new tree is built. The hook is "
10+ "called with the tree as its only argument.", (2, 5))
11
12
13 # install the default hooks into the MutableTree class.
14
15=== modified file 'bzrlib/plugins/weave_fmt/workingtree.py'
16--- bzrlib/plugins/weave_fmt/workingtree.py 2011-12-19 13:23:58 +0000
17+++ bzrlib/plugins/weave_fmt/workingtree.py 2012-01-06 19:50:29 +0000
18@@ -30,6 +30,7 @@
19 xml5,
20 )
21 from bzrlib.decorators import needs_read_lock
22+from bzrlib.mutabletree import MutableTree
23 from bzrlib.transport.local import LocalTransport
24 from bzrlib.workingtree import (
25 WorkingTreeFormat,
26@@ -113,6 +114,8 @@
27 parent_trees = [(revision_id, basis_tree)]
28 wt.set_parent_trees(parent_trees)
29 transform.build_tree(basis_tree, wt)
30+ for hook in MutableTree.hooks['post_build_tree']:
31+ hook(wt)
32 return wt
33
34 def __init__(self):
35
36=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
37--- bzrlib/tests/per_workingtree/test_workingtree.py 2011-12-16 17:34:46 +0000
38+++ bzrlib/tests/per_workingtree/test_workingtree.py 2012-01-06 19:50:29 +0000
39@@ -37,6 +37,7 @@
40 PathsNotVersionedError,
41 )
42 from bzrlib.inventory import Inventory
43+from bzrlib.mutabletree import MutableTree
44 from bzrlib.osutils import pathjoin, getcwd, has_symlinks
45 from bzrlib.tests import (
46 features,
47@@ -451,6 +452,23 @@
48 revision_id='a')
49 self.assertEqual(['a'], made_tree.get_parent_ids())
50
51+ def test_post_build_tree_hook(self):
52+ calls = []
53+ def track_post_build_tree(tree):
54+ calls.append(tree.last_revision())
55+ source = self.make_branch_and_tree('source')
56+ source.commit('a', rev_id='a', allow_pointless=True)
57+ source.commit('b', rev_id='b', allow_pointless=True)
58+ self.build_tree(['new/'])
59+ made_control = self.bzrdir_format.initialize('new')
60+ source.branch.repository.clone(made_control)
61+ source.branch.clone(made_control)
62+ MutableTree.hooks.install_named_hook("post_build_tree",
63+ track_post_build_tree, "Test")
64+ made_tree = self.workingtree_format.initialize(made_control,
65+ revision_id='a')
66+ self.assertEqual(['a'], calls)
67+
68 def test_update_sets_last_revision(self):
69 # working tree formats from the meta-dir format and newer support
70 # setting the last revision on a tree independently of that on the
71
72=== modified file 'bzrlib/workingtree_3.py'
73--- bzrlib/workingtree_3.py 2011-12-19 19:15:58 +0000
74+++ bzrlib/workingtree_3.py 2012-01-06 19:50:29 +0000
75@@ -36,6 +36,7 @@
76 )
77 from bzrlib.lockable_files import LockableFiles
78 from bzrlib.lockdir import LockDir
79+from bzrlib.mutabletree import MutableTree
80 from bzrlib.transport.local import LocalTransport
81 from bzrlib.workingtree import (
82 InventoryWorkingTree,
83@@ -227,6 +228,8 @@
84 else:
85 wt.set_parent_trees([(revision_id, basis_tree)])
86 transform.build_tree(basis_tree, wt)
87+ for hook in MutableTree.hooks['post_build_tree']:
88+ hook(wt)
89 finally:
90 # Unlock in this order so that the unlock-triggers-flush in
91 # WorkingTree is given a chance to fire.
92
93=== modified file 'bzrlib/workingtree_4.py'
94--- bzrlib/workingtree_4.py 2011-12-19 19:15:58 +0000
95+++ bzrlib/workingtree_4.py 2012-01-06 19:50:29 +0000
96@@ -57,7 +57,10 @@
97 from bzrlib.lock import LogicalLockResult
98 from bzrlib.lockable_files import LockableFiles
99 from bzrlib.lockdir import LockDir
100-from bzrlib.mutabletree import needs_tree_write_lock
101+from bzrlib.mutabletree import (
102+ MutableTree,
103+ needs_tree_write_lock,
104+ )
105 from bzrlib.osutils import (
106 file_kind,
107 isdir,
108@@ -1544,6 +1547,8 @@
109 transform.build_tree(basis, wt, accelerator_tree,
110 hardlink=hardlink,
111 delta_from_tree=delta_from_tree)
112+ for hook in MutableTree.hooks['post_build_tree']:
113+ hook(wt)
114 finally:
115 basis.unlock()
116 finally:
117
118=== modified file 'doc/en/release-notes/bzr-2.5.txt'
119--- doc/en/release-notes/bzr-2.5.txt 2012-01-05 16:03:11 +0000
120+++ doc/en/release-notes/bzr-2.5.txt 2012-01-06 19:50:29 +0000
121@@ -178,6 +178,9 @@
122 which contains the branch from which the ``other_tree``
123 was obtained, if any. (Jelmer Vernooij)
124
125+* MutableTree now has a hook ``post_build_tree`` which is called after
126+ a new mutable tree has been created. (Jelmer Vernooij, #912765)
127+
128 * New HPSS call ``BzrDir.checkout_metadir``. (Jelmer Vernooij, #894459)
129
130 * New HPSS call ``VersionedFileRepository.get_inventories``,