~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: Jonathan Riddell
  • Date: 2011-05-25 15:18:31 UTC
  • mto: This revision was merged to the branch mainline in revision 5965.
  • Revision ID: jriddell@canonical.com-20110525151831-8tnxop1epk3iug2t
Add commit message hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
303
303
        These are all empty initially.
304
304
        """
305
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 bzrlib.commit.Commit "
 
309
            "object so you can also change e.g. revision properties by "
 
310
            "editing commit.builder._revprops. set_commit_message must return "
 
311
            "the message to use or None if it should use the message editor "
 
312
            "as normal.", (2, 4))
306
313
        self.add_hook('commit_message_template',
307
314
            "Called when a commit message is being generated. "
308
315
            "commit_message_template is called with the bzrlib.commit.Commit "
316
323
 
317
324
hooks = MessageEditorHooks()
318
325
 
 
326
from bzrlib.trace import note
 
327
 
 
328
def set_commit_message(commit):
 
329
    """Sets the commit message.
 
330
    :param commit: Commit object for the active commit.
 
331
    :return: The commit message or None to continue using the message editor, properties.
 
332
    """
 
333
    message = None
 
334
    for hook in hooks['set_commit_message']:
 
335
        message = hook(commit)
 
336
    note("set_commit_message: " + str(message))
 
337
    return message
319
338
 
320
339
def generate_commit_message_template(commit, start_message=None):
321
340
    """Generate a commit message template.
324
343
    :param start_message: Message to start with.
325
344
    :return: A start commit message or None for an empty start commit message.
326
345
    """
 
346
    note("generate_commit_message_template " + str(commit))
327
347
    start_message = None
328
348
    for hook in hooks['commit_message_template']:
329
349
        start_message = hook(commit, start_message)