Merge lp:~ian-clatworthy/bzr/finish_commit_hook_2 into lp:bzr/2.0

Proposed by Ian Clatworthy
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~ian-clatworthy/bzr/finish_commit_hook_2
Merge into: lp:bzr/2.0
Diff against target: None lines
To merge this branch: bzr merge lp:~ian-clatworthy/bzr/finish_commit_hook_2
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+11332@code.launchpad.net

This proposal supersedes a proposal from 2009-09-07.

To post a comment you must log in.
Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote : Posted in a previous version of this proposal

This patch is required for content filtering to Do The Right Thing. In particular, it provides a hook so that bzr-keywords can update the working tree and expand keywords in files just committed. See bug 385879.

This patch supersedes https://code.edge.launchpad.net/~ian-clatworthy/bzr/finish-commit-hook/+merge/10973 and introduces a FinishCommitHookParams class as discussed with jam during the review of that earlier branch.

Revision history for this message
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal

This looks fine modulo the name.

The hook isn't actually finishing the commit; its happening strictly
after the commit.

So please call it post_commit.

Cheers,
Rob

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote : Posted in a previous version of this proposal

> So please call it post_commit.

Done. I'll resubmit for a quick check of my changes.

Revision history for this message
Robert Collins (lifeless) wrote :

 merge approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-09-06 22:12:06 +0000
3+++ NEWS 2009-09-07 23:14:05 +0000
4@@ -9,6 +9,13 @@
5 bzr 2.0rc2 (not released yet)
6 #############################
7
8+New Features
9+************
10+
11+* Added post_commit hook for mutable trees. This allows the keywords
12+ plugin to expand keywords on files changed by the commit.
13+ (Ian Clatworthy, #408841)
14+
15 Bug Fixes
16 *********
17
18
19=== modified file 'bzrlib/mutabletree.py'
20--- bzrlib/mutabletree.py 2009-07-10 08:33:11 +0000
21+++ bzrlib/mutabletree.py 2009-09-07 23:14:05 +0000
22@@ -226,6 +226,9 @@
23 revprops=revprops,
24 possible_master_transports=possible_master_transports,
25 *args, **kwargs)
26+ post_hook_params = PostCommitHookParams(self)
27+ for hook in MutableTree.hooks['post_commit']:
28+ hook(post_hook_params)
29 return committed_id
30
31 def _gather_kinds(self, files, kinds):
32@@ -581,14 +584,32 @@
33 self.create_hook(hooks.HookPoint('start_commit',
34 "Called before a commit is performed on a tree. The start commit "
35 "hook is able to change the tree before the commit takes place. "
36- "start_commit is called with the bzrlib.tree.MutableTree that the "
37- "commit is being performed on.", (1, 4), None))
38+ "start_commit is called with the bzrlib.mutabletree.MutableTree "
39+ "that the commit is being performed on.", (1, 4), None))
40+ self.create_hook(hooks.HookPoint('post_commit',
41+ "Called after a commit is performed on a tree. The hook is "
42+ "called with a bzrlib.mutabletree.PostCommitHookParams object. "
43+ "The mutable tree the commit was performed on is available via "
44+ "the mutable_tree attribute of that object.", (2, 0), None))
45
46
47 # install the default hooks into the MutableTree class.
48 MutableTree.hooks = MutableTreeHooks()
49
50
51+class PostCommitHookParams(object):
52+ """Parameters for the post_commit hook.
53+
54+ To access the parameters, use the following attributes:
55+
56+ * mutable_tree - the MutableTree object
57+ """
58+
59+ def __init__(self, mutable_tree):
60+ """Create the parameters for the post_commit hook."""
61+ self.mutable_tree = mutable_tree
62+
63+
64 class _FastPath(object):
65 """A path object with fast accessors for things like basename."""
66
67
68=== modified file 'bzrlib/tests/per_workingtree/test_commit.py'
69--- bzrlib/tests/per_workingtree/test_commit.py 2009-08-04 11:40:59 +0000
70+++ bzrlib/tests/per_workingtree/test_commit.py 2009-09-07 23:14:05 +0000
71@@ -611,3 +611,26 @@
72 revid = tree.commit('first post')
73 committed_tree = tree.basis_tree()
74 self.assertTrue(committed_tree.has_filename("newfile"))
75+
76+ def test_post_commit_hook(self):
77+ """Make sure a post_commit hook is called after a commit."""
78+ def post_commit_hook_test_params(params):
79+ self.assertTrue(isinstance(params,
80+ mutabletree.PostCommitHookParams))
81+ self.assertTrue(isinstance(params.mutable_tree,
82+ mutabletree.MutableTree))
83+ open(tree.abspath("newfile"), 'w').write("data")
84+ params.mutable_tree.add(["newfile"])
85+ def restoreDefaults():
86+ mutabletree.MutableTree.hooks['post_commit'] = []
87+ self.addCleanup(restoreDefaults)
88+ tree = self.make_branch_and_tree('.')
89+ mutabletree.MutableTree.hooks.install_named_hook(
90+ 'post_commit',
91+ post_commit_hook_test_params,
92+ None)
93+ self.assertFalse(tree.has_filename("newfile"))
94+ revid = tree.commit('first post')
95+ self.assertTrue(tree.has_filename("newfile"))
96+ committed_tree = tree.basis_tree()
97+ self.assertFalse(committed_tree.has_filename("newfile"))
98
99=== modified file 'bzrlib/tests/test_mutabletree.py'
100--- bzrlib/tests/test_mutabletree.py 2009-03-23 14:59:43 +0000
101+++ bzrlib/tests/test_mutabletree.py 2009-09-07 23:14:05 +0000
102@@ -30,6 +30,8 @@
103 hooks = MutableTreeHooks()
104 self.assertTrue("start_commit" in hooks,
105 "start_commit not in %s" % hooks)
106+ self.assertTrue("post_commit" in hooks,
107+ "post_commit not in %s" % hooks)
108
109 def test_installed_hooks_are_MutableTreeHooks(self):
110 """The installed hooks object should be a MutableTreeHooks."""

Subscribers

People subscribed via source and target branches