Rev 5965: (jr) New hook set_commit_message in bzrlib.msgeditor to set a commit message in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jun 9 13:24:13 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5965 [merge]
revision-id: pqm at pqm.ubuntu.com-20110609132411-xxr3scf3mb9o585c
parent: pqm at pqm.ubuntu.com-20110609082500-vn5pctkfv1utnp0x
parent: jriddell at canonical.com-20110609115908-s2wphwxdlv9m4fjs
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-06-09 13:24:11 +0000
message:
  (jr) New hook set_commit_message in bzrlib.msgeditor to set a commit message
   and revision properties. (Jonathan Riddell, #274578) (Jonathan Riddell)
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/msgeditor.py            msgeditor.py-20050901111708-ef6d8de98f5d8f2f
  bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
  bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
  doc/en/release-notes/bzr-2.4.txt bzr2.4.txt-20110114053217-k7ym9jfz243fddjm-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-05-31 18:30:32 +0000
+++ b/bzrlib/builtins.py	2011-06-01 16:50:59 +0000
@@ -3193,7 +3193,8 @@
         from bzrlib.msgeditor import (
             edit_commit_message_encoded,
             generate_commit_message_template,
-            make_commit_message_template_encoded
+            make_commit_message_template_encoded,
+            set_commit_message,
         )
 
         commit_stamp = offset = None
@@ -3265,9 +3266,11 @@
                 # make_commit_message_template_encoded returns user encoding.
                 # We probably want to be using edit_commit_message instead to
                 # avoid this.
-                start_message = generate_commit_message_template(commit_obj)
-                my_message = edit_commit_message_encoded(text,
-                    start_message=start_message)
+                my_message = set_commit_message(commit_obj)
+                if my_message is None:
+                    start_message = generate_commit_message_template(commit_obj)
+                    my_message = edit_commit_message_encoded(text,
+                        start_message=start_message)
                 if my_message is None:
                     raise errors.BzrCommandError("please specify a commit"
                         " message with either --message or --file")

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2011-05-31 21:08:52 +0000
+++ b/bzrlib/msgeditor.py	2011-06-09 11:52:35 +0000
@@ -303,6 +303,13 @@
         These are all empty initially.
         """
         Hooks.__init__(self, "bzrlib.msgeditor", "hooks")
+        self.add_hook('set_commit_message',
+            "Set a fixed commit message. "
+            "set_commit_message is called with the "
+            "bzrlib.commit.Commit object (so you can also change e.g. revision "
+            "properties by editing commit.builder._revprops) and the message "
+            "so far. set_commit_message must return the message to use or None"
+            " if it should use the message editor as normal.", (2, 4))
         self.add_hook('commit_message_template',
             "Called when a commit message is being generated. "
             "commit_message_template is called with the bzrlib.commit.Commit "
@@ -317,6 +324,17 @@
 hooks = MessageEditorHooks()
 
 
+def set_commit_message(commit, start_message=None):
+    """Sets the commit message.
+    :param commit: Commit object for the active commit.
+    :return: The commit message or None to continue using the message editor
+    """
+    start_message = None
+    for hook in hooks['set_commit_message']:
+        start_message = hook(commit, start_message)
+    return start_message
+
+
 def generate_commit_message_template(commit, start_message=None):
     """Generate a commit message template.
 

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2011-05-17 14:27:30 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2011-06-09 11:48:03 +0000
@@ -754,6 +754,16 @@
             "commit tree/hello.txt", stdin="n\n")
         self.assertEqual(expected, tree.last_revision())
 
+    def test_set_commit_message(self):
+        msgeditor.hooks.install_named_hook("set_commit_message",
+                lambda commit_obj, msg: "save me some typing\n", None)
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/hello.txt'])
+        tree.add('hello.txt')
+        out, err = self.run_bzr("commit tree/hello.txt")
+        last_rev = tree.branch.repository.get_revision(tree.last_revision())
+        self.assertEqual('save me some typing\n', last_rev.message)
+
     def test_commit_without_username(self):
         """Ensure commit error if username is not set.
         """
@@ -782,4 +792,3 @@
         self.assertEqual(out, '')
         self.assertContainsRe(err,
             'Branch.*test_checkout.*appears to be bound to itself')
-

=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py	2011-05-11 11:35:28 +0000
+++ b/bzrlib/tests/test_msgeditor.py	2011-06-09 11:48:03 +0000
@@ -344,6 +344,18 @@
         self.assertRaises(errors.BadCommitMessageEncoding,
                           msgeditor.edit_commit_message, '')
 
+    def test_set_commit_message_no_hooks(self):
+        commit_obj = commit.Commit()
+        self.assertIs(None,
+            msgeditor.set_commit_message(commit_obj))
+
+    def test_set_commit_message_hook(self):
+        msgeditor.hooks.install_named_hook("set_commit_message",
+                lambda commit_obj, existing_message: "save me some typing\n", None)
+        commit_obj = commit.Commit()
+        self.assertEquals("save me some typing\n",
+            msgeditor.set_commit_message(commit_obj))
+
     def test_generate_commit_message_template_no_hooks(self):
         commit_obj = commit.Commit()
         self.assertIs(None,

=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt	2011-06-08 13:51:30 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt	2011-06-09 11:59:08 +0000
@@ -24,6 +24,10 @@
   exception caused while running bzr serve.  (Jonathan Riddell,
   #274578)
 
+* New hook set_commit_message in bzrlib.msgeditor to set
+  a commit message and revision properties.  (Jonathan Riddell,
+  #274578)
+
 * Support ``-S`` as an alias for ``--short`` for the ``log`` and
   ``missing`` commands. (Martin von Gagern, #38655)
 




More information about the bazaar-commits mailing list