Merge lp:~jr/bzr/707274-commit-message-hook into lp:bzr

Proposed by Jonathan Riddell
Status: Merged
Approved by: Jonathan Riddell
Approved revision: no longer in the source branch.
Merged at revision: 5965
Proposed branch: lp:~jr/bzr/707274-commit-message-hook
Merge into: lp:bzr
Diff against target: 127 lines (+51/-5)
5 files modified
bzrlib/builtins.py (+7/-4)
bzrlib/msgeditor.py (+18/-0)
bzrlib/tests/blackbox/test_commit.py (+10/-1)
bzrlib/tests/test_msgeditor.py (+12/-0)
doc/en/release-notes/bzr-2.4.txt (+4/-0)
To merge this branch: bzr merge lp:~jr/bzr/707274-commit-message-hook
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) code Approve
John A Meinel Needs Fixing
Vincent Ladeuil Needs Information
Andrew Bennetts Pending
Review via email: mp+62334@code.launchpad.net

Commit message

New hook set_commit_message in bzrlib.msgeditor to set a commit message and revision properties. (Jonathan Riddell, #274578)

Description of the change

Proposed new hook set_commit_message() to set a commit message

For bug 707274

called as part of the get_message() callback which is too late to set properties directory on the Commit object, although it can be done through editing commit.builder._revprops

No option to confirm commit message yet
Needs bzr-builddeb updated to use it
Needs qbzr updated to use it

To post a comment you must log in.
Revision history for this message
Jonathan Riddell (jr) wrote :

Submitted bug https://bugs.launchpad.net/qbzr/+bug/788216 on qbzr to use the commit message hooks

Revision history for this message
Jonathan Riddell (jr) wrote :

It needs to be called as part of get_message(), any earlier and there is no Commit object to get interesting data out of (such as the changes to debian/changelog that bzr-buiddeb needs)

Revision history for this message
Vincent Ladeuil (vila) wrote :

@spiv: I seem to remember you had a deep discussion in this area but I didn't participate nor remember the details. I have a vague feeling that this proposal is not doing the Right Thing but I can't put my finger on it. Care to review it ?

@Jonathan: I really hate spreading FUD on proposals, so wait for spiv input before worrying about me ;)

review: Needs Information
Revision history for this message
Martin Packman (gz) wrote :

You're probably thinking of these two threads from Gary and Alexander trying to rationalise the way qcommit works:

<https://lists.ubuntu.com/archives/bazaar/2009q3/062169.html>
<https://lists.ubuntu.com/archives/bazaar/2010q2/068315.html>

Revision history for this message
John A Meinel (jameinel) wrote :

There is a small issue if 2 plugins both provide "set_commit_message". Since neither one can see that another plugin has set it, and the ordering of hooks is intentionally undefined.

So I think we at least want the hook to take 2 parameters. The Commit object, and the current commit message.

We might want to future proof this by having the took take a Params object. But ATM I feel that it YAGNI.

Otherwise this looks fine, so "tweak".

review: Needs Fixing
Revision history for this message
Jonathan Riddell (jr) wrote :

updated

Revision history for this message
Martin Packman (gz) wrote :

Would it be helpful to get Alexander or Gary to look at this and see if it helps the qbzr use case?

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

If the intend of this is to allow e.g. plugins to modify the revision properties, I think the _revprops attribute on CommitBuilder should explicitly be made part of the interface.

E.g. bzr-svn, bzr-git and bzr-hg which have custom CommitBuilders currently get the revprops passed in from Repository.get_commit_builder() and do not necessarily set them as a private CommitBuilder._revprops variable and/or assume nobody else touches them.

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

I'm surprised by how small this is, well done.

A minor nitpick: You need an extra empty line after set_commit_message.

Approving, though it would indeed be useful if one of the qbzr folks could also have a look.

review: Approve (code)
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/4/2011 4:34 PM, Jelmer Vernooij wrote:
> Review: Approve code
> I'm surprised by how small this is, well done.
>
> A minor nitpick: You need an extra empty line after set_commit_message.
>
> Approving, though it would indeed be useful if one of the qbzr folks could also have a look.

In talking with Jonathan about this (voice-chat no less), it doesn't fit
the qbzr use case, but they really need something custom anyway.
Specifically, they already select files before committing (so they run
'status' and then let the user use radio boxes, etc.)

They want to get the templated commit message before actually running
commit (which the current api, nor the new api support). And then they
can set the commit message with just the equivalent of '-m' or '-F'. So
they don't need a hook like this (bzr-builddeb does). What they need is
a hook that lets template messages be generated without actually having
processed a commit at all.

Note that there are lots of fuzzy bits to that. Because if you haven't
actually processed a commit, what if the code actually wants to insert
the names of the new files, or a per-file comment, or ... We can evolve
to that. Eg as a first pass, having a templated commit message that does
*not* take the list of files, or having it take the list, but qbzr needs
to re-query whenever a user changes the selection list.

All that to say, this handles what bzr-builddeb needs, and qbzr needs to
design something that is going to work for them, because it is very
different from the existing stuff. So we shouldn't block on this.

My only concern is if we would rather just have a flag on the existing
hook, that says "if the user uses this template message without changing
it, just commit the text, don't prompt them if they really want it.".
(Extend the existing hook, rather than creating a new one.)

However, I don't think the current hook is easy to extend, so I'm good
with this.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3s4wUACgkQJdeBCYSNAANd7QCg1Zjob46KFud1AJRxKDqmparL
ONUAniPGsNswxVwtUsAt0l6xAPCnk+jt
=Rx7Z
-----END PGP SIGNATURE-----

Revision history for this message
John A Meinel (jameinel) wrote :

Looking at it with fresh eyes, the only thing I see missing is a test that "bzr commit" will use the set_commit_message hook. You test that msgeditor.... works, but not that the Commit code uses it.

So small tweak and I think it is ready to land.

Revision history for this message
Jonathan Riddell (jr) wrote :

sent to pqm by email

Revision history for this message
Jonathan Riddell (jr) 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/builtins.py'
--- bzrlib/builtins.py 2011-05-31 18:30:32 +0000
+++ bzrlib/builtins.py 2011-06-09 12:02:30 +0000
@@ -3193,7 +3193,8 @@
3193 from bzrlib.msgeditor import (3193 from bzrlib.msgeditor import (
3194 edit_commit_message_encoded,3194 edit_commit_message_encoded,
3195 generate_commit_message_template,3195 generate_commit_message_template,
3196 make_commit_message_template_encoded3196 make_commit_message_template_encoded,
3197 set_commit_message,
3197 )3198 )
31983199
3199 commit_stamp = offset = None3200 commit_stamp = offset = None
@@ -3265,9 +3266,11 @@
3265 # make_commit_message_template_encoded returns user encoding.3266 # make_commit_message_template_encoded returns user encoding.
3266 # We probably want to be using edit_commit_message instead to3267 # We probably want to be using edit_commit_message instead to
3267 # avoid this.3268 # avoid this.
3268 start_message = generate_commit_message_template(commit_obj)3269 my_message = set_commit_message(commit_obj)
3269 my_message = edit_commit_message_encoded(text,3270 if my_message is None:
3270 start_message=start_message)3271 start_message = generate_commit_message_template(commit_obj)
3272 my_message = edit_commit_message_encoded(text,
3273 start_message=start_message)
3271 if my_message is None:3274 if my_message is None:
3272 raise errors.BzrCommandError("please specify a commit"3275 raise errors.BzrCommandError("please specify a commit"
3273 " message with either --message or --file")3276 " message with either --message or --file")
32743277
=== modified file 'bzrlib/msgeditor.py'
--- bzrlib/msgeditor.py 2011-05-31 21:08:52 +0000
+++ bzrlib/msgeditor.py 2011-06-09 12:02:30 +0000
@@ -303,6 +303,13 @@
303 These are all empty initially.303 These are all empty initially.
304 """304 """
305 Hooks.__init__(self, "bzrlib.msgeditor", "hooks")305 Hooks.__init__(self, "bzrlib.msgeditor", "hooks")
306 self.add_hook('set_commit_message',
307 "Set a fixed commit message. "
308 "set_commit_message is called with the "
309 "bzrlib.commit.Commit object (so you can also change e.g. revision "
310 "properties by editing commit.builder._revprops) and the message "
311 "so far. set_commit_message must return the message to use or None"
312 " if it should use the message editor as normal.", (2, 4))
306 self.add_hook('commit_message_template',313 self.add_hook('commit_message_template',
307 "Called when a commit message is being generated. "314 "Called when a commit message is being generated. "
308 "commit_message_template is called with the bzrlib.commit.Commit "315 "commit_message_template is called with the bzrlib.commit.Commit "
@@ -317,6 +324,17 @@
317hooks = MessageEditorHooks()324hooks = MessageEditorHooks()
318325
319326
327def set_commit_message(commit, start_message=None):
328 """Sets the commit message.
329 :param commit: Commit object for the active commit.
330 :return: The commit message or None to continue using the message editor
331 """
332 start_message = None
333 for hook in hooks['set_commit_message']:
334 start_message = hook(commit, start_message)
335 return start_message
336
337
320def generate_commit_message_template(commit, start_message=None):338def generate_commit_message_template(commit, start_message=None):
321 """Generate a commit message template.339 """Generate a commit message template.
322340
323341
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- bzrlib/tests/blackbox/test_commit.py 2011-05-17 14:27:30 +0000
+++ bzrlib/tests/blackbox/test_commit.py 2011-06-09 12:02:30 +0000
@@ -754,6 +754,16 @@
754 "commit tree/hello.txt", stdin="n\n")754 "commit tree/hello.txt", stdin="n\n")
755 self.assertEqual(expected, tree.last_revision())755 self.assertEqual(expected, tree.last_revision())
756756
757 def test_set_commit_message(self):
758 msgeditor.hooks.install_named_hook("set_commit_message",
759 lambda commit_obj, msg: "save me some typing\n", None)
760 tree = self.make_branch_and_tree('tree')
761 self.build_tree(['tree/hello.txt'])
762 tree.add('hello.txt')
763 out, err = self.run_bzr("commit tree/hello.txt")
764 last_rev = tree.branch.repository.get_revision(tree.last_revision())
765 self.assertEqual('save me some typing\n', last_rev.message)
766
757 def test_commit_without_username(self):767 def test_commit_without_username(self):
758 """Ensure commit error if username is not set.768 """Ensure commit error if username is not set.
759 """769 """
@@ -782,4 +792,3 @@
782 self.assertEqual(out, '')792 self.assertEqual(out, '')
783 self.assertContainsRe(err,793 self.assertContainsRe(err,
784 'Branch.*test_checkout.*appears to be bound to itself')794 'Branch.*test_checkout.*appears to be bound to itself')
785
786795
=== modified file 'bzrlib/tests/test_msgeditor.py'
--- bzrlib/tests/test_msgeditor.py 2011-05-11 11:35:28 +0000
+++ bzrlib/tests/test_msgeditor.py 2011-06-09 12:02:30 +0000
@@ -344,6 +344,18 @@
344 self.assertRaises(errors.BadCommitMessageEncoding,344 self.assertRaises(errors.BadCommitMessageEncoding,
345 msgeditor.edit_commit_message, '')345 msgeditor.edit_commit_message, '')
346346
347 def test_set_commit_message_no_hooks(self):
348 commit_obj = commit.Commit()
349 self.assertIs(None,
350 msgeditor.set_commit_message(commit_obj))
351
352 def test_set_commit_message_hook(self):
353 msgeditor.hooks.install_named_hook("set_commit_message",
354 lambda commit_obj, existing_message: "save me some typing\n", None)
355 commit_obj = commit.Commit()
356 self.assertEquals("save me some typing\n",
357 msgeditor.set_commit_message(commit_obj))
358
347 def test_generate_commit_message_template_no_hooks(self):359 def test_generate_commit_message_template_no_hooks(self):
348 commit_obj = commit.Commit()360 commit_obj = commit.Commit()
349 self.assertIs(None,361 self.assertIs(None,
350362
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- doc/en/release-notes/bzr-2.4.txt 2011-06-08 13:51:30 +0000
+++ doc/en/release-notes/bzr-2.4.txt 2011-06-09 12:02:30 +0000
@@ -24,6 +24,10 @@
24 exception caused while running bzr serve. (Jonathan Riddell,24 exception caused while running bzr serve. (Jonathan Riddell,
25 #274578)25 #274578)
2626
27* New hook set_commit_message in bzrlib.msgeditor to set
28 a commit message and revision properties. (Jonathan Riddell,
29 #274578)
30
27* Support ``-S`` as an alias for ``--short`` for the ``log`` and31* Support ``-S`` as an alias for ``--short`` for the ``log`` and
28 ``missing`` commands. (Martin von Gagern, #38655)32 ``missing`` commands. (Martin von Gagern, #38655)
2933