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
=== modified file 'NEWS'
--- NEWS 2009-09-06 22:12:06 +0000
+++ NEWS 2009-09-07 23:14:05 +0000
@@ -9,6 +9,13 @@
9bzr 2.0rc2 (not released yet)9bzr 2.0rc2 (not released yet)
10#############################10#############################
1111
12New Features
13************
14
15* Added post_commit hook for mutable trees. This allows the keywords
16 plugin to expand keywords on files changed by the commit.
17 (Ian Clatworthy, #408841)
18
12Bug Fixes19Bug Fixes
13*********20*********
1421
1522
=== modified file 'bzrlib/mutabletree.py'
--- bzrlib/mutabletree.py 2009-07-10 08:33:11 +0000
+++ bzrlib/mutabletree.py 2009-09-07 23:14:05 +0000
@@ -226,6 +226,9 @@
226 revprops=revprops,226 revprops=revprops,
227 possible_master_transports=possible_master_transports,227 possible_master_transports=possible_master_transports,
228 *args, **kwargs)228 *args, **kwargs)
229 post_hook_params = PostCommitHookParams(self)
230 for hook in MutableTree.hooks['post_commit']:
231 hook(post_hook_params)
229 return committed_id232 return committed_id
230233
231 def _gather_kinds(self, files, kinds):234 def _gather_kinds(self, files, kinds):
@@ -581,14 +584,32 @@
581 self.create_hook(hooks.HookPoint('start_commit',584 self.create_hook(hooks.HookPoint('start_commit',
582 "Called before a commit is performed on a tree. The start commit "585 "Called before a commit is performed on a tree. The start commit "
583 "hook is able to change the tree before the commit takes place. "586 "hook is able to change the tree before the commit takes place. "
584 "start_commit is called with the bzrlib.tree.MutableTree that the "587 "start_commit is called with the bzrlib.mutabletree.MutableTree "
585 "commit is being performed on.", (1, 4), None))588 "that the commit is being performed on.", (1, 4), None))
589 self.create_hook(hooks.HookPoint('post_commit',
590 "Called after a commit is performed on a tree. The hook is "
591 "called with a bzrlib.mutabletree.PostCommitHookParams object. "
592 "The mutable tree the commit was performed on is available via "
593 "the mutable_tree attribute of that object.", (2, 0), None))
586594
587595
588# install the default hooks into the MutableTree class.596# install the default hooks into the MutableTree class.
589MutableTree.hooks = MutableTreeHooks()597MutableTree.hooks = MutableTreeHooks()
590598
591599
600class PostCommitHookParams(object):
601 """Parameters for the post_commit hook.
602
603 To access the parameters, use the following attributes:
604
605 * mutable_tree - the MutableTree object
606 """
607
608 def __init__(self, mutable_tree):
609 """Create the parameters for the post_commit hook."""
610 self.mutable_tree = mutable_tree
611
612
592class _FastPath(object):613class _FastPath(object):
593 """A path object with fast accessors for things like basename."""614 """A path object with fast accessors for things like basename."""
594615
595616
=== modified file 'bzrlib/tests/per_workingtree/test_commit.py'
--- bzrlib/tests/per_workingtree/test_commit.py 2009-08-04 11:40:59 +0000
+++ bzrlib/tests/per_workingtree/test_commit.py 2009-09-07 23:14:05 +0000
@@ -611,3 +611,26 @@
611 revid = tree.commit('first post')611 revid = tree.commit('first post')
612 committed_tree = tree.basis_tree()612 committed_tree = tree.basis_tree()
613 self.assertTrue(committed_tree.has_filename("newfile"))613 self.assertTrue(committed_tree.has_filename("newfile"))
614
615 def test_post_commit_hook(self):
616 """Make sure a post_commit hook is called after a commit."""
617 def post_commit_hook_test_params(params):
618 self.assertTrue(isinstance(params,
619 mutabletree.PostCommitHookParams))
620 self.assertTrue(isinstance(params.mutable_tree,
621 mutabletree.MutableTree))
622 open(tree.abspath("newfile"), 'w').write("data")
623 params.mutable_tree.add(["newfile"])
624 def restoreDefaults():
625 mutabletree.MutableTree.hooks['post_commit'] = []
626 self.addCleanup(restoreDefaults)
627 tree = self.make_branch_and_tree('.')
628 mutabletree.MutableTree.hooks.install_named_hook(
629 'post_commit',
630 post_commit_hook_test_params,
631 None)
632 self.assertFalse(tree.has_filename("newfile"))
633 revid = tree.commit('first post')
634 self.assertTrue(tree.has_filename("newfile"))
635 committed_tree = tree.basis_tree()
636 self.assertFalse(committed_tree.has_filename("newfile"))
614637
=== modified file 'bzrlib/tests/test_mutabletree.py'
--- bzrlib/tests/test_mutabletree.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/test_mutabletree.py 2009-09-07 23:14:05 +0000
@@ -30,6 +30,8 @@
30 hooks = MutableTreeHooks()30 hooks = MutableTreeHooks()
31 self.assertTrue("start_commit" in hooks,31 self.assertTrue("start_commit" in hooks,
32 "start_commit not in %s" % hooks)32 "start_commit not in %s" % hooks)
33 self.assertTrue("post_commit" in hooks,
34 "post_commit not in %s" % hooks)
3335
34 def test_installed_hooks_are_MutableTreeHooks(self):36 def test_installed_hooks_are_MutableTreeHooks(self):
35 """The installed hooks object should be a MutableTreeHooks."""37 """The installed hooks object should be a MutableTreeHooks."""

Subscribers

People subscribed via source and target branches