Rev 5138: * ``bzr commit`` will prompt before using a commit message that was in http://bazaar.launchpad.net/~lifeless/bzr/commit

Robert Collins robertc at robertcollins.net
Wed Apr 7 01:51:12 BST 2010


At http://bazaar.launchpad.net/~lifeless/bzr/commit

------------------------------------------------------------
revno: 5138
revision-id: robertc at robertcollins.net-20100407005056-wl0vsz9uietffpy8
parent: pqm at pqm.ubuntu.com-20100406214647-xikmc315d0w48fn7
fixes bug(s): https://launchpad.net/bugs/530265
committer: Robert Collins <robertc at robertcollins.net>
branch nick: commit
timestamp: Wed 2010-04-07 10:50:56 +1000
message:
  * ``bzr commit`` will prompt before using a commit message that was
    generated by a template and not edited by the user.
    (Robert Collins, #530265)
=== modified file 'NEWS'
--- a/NEWS	2010-04-06 11:29:06 +0000
+++ b/NEWS	2010-04-07 00:50:56 +0000
@@ -29,6 +29,10 @@
 Improvements
 ************
 
+* ``bzr commit`` will prompt before using a commit message that was
+  generated by a template and not edited by the user.
+  (Robert Collins, #530265)
+
 * Less code is loaded at startup.  (Cold-cache start time is about 10-20%
   less.)
   (Martin Pool, #553017)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-04-06 21:46:47 +0000
+++ b/bzrlib/builtins.py	2010-04-07 00:50:56 +0000
@@ -3150,31 +3150,37 @@
                     '(use --file "%(f)s" to take commit message from that file)'
                     % { 'f': message })
                 ui.ui_factory.show_warning(warning_msg)
+            if '\r' in message:
+                message = message.replace('\r\n', '\n')
+                message = message.replace('\r', '\n')
+            if file:
+                raise errors.BzrCommandError(
+                    "please specify either --message or --file")
 
         def get_message(commit_obj):
             """Callback to get commit message"""
-            my_message = message
-            if my_message is not None and '\r' in my_message:
-                my_message = my_message.replace('\r\n', '\n')
-                my_message = my_message.replace('\r', '\n')
-            if my_message is None and not file:
-                # t is the status of the tree
-                t = make_commit_message_template_encoded(tree,
+            if file:
+                my_message = codecs.open(
+                    file, 'rt', osutils.get_user_encoding()).read()
+            elif message is not None:
+                my_message = message
+            else:
+                # No message supplied: make one up.
+                # text is the status of the tree
+                text = make_commit_message_template_encoded(tree,
                         selected_list, diff=show_diff,
                         output_encoding=osutils.get_user_encoding())
                 # start_message is the template generated from hooks
+                # XXX: Warning - looks like hooks return unicode,
+                # 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(t,
+                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")
-            elif my_message and file:
-                raise errors.BzrCommandError(
-                    "please specify either --message or --file")
-            if file:
-                my_message = codecs.open(file, 'rt',
-                                         osutils.get_user_encoding()).read()
             if my_message == "":
                 raise errors.BzrCommandError("empty commit message specified")
             return my_message
@@ -3192,8 +3198,6 @@
                         timezone=offset,
                         exclude=safe_relpath_files(tree, exclude))
         except PointlessCommit:
-            # FIXME: This should really happen before the file is read in;
-            # perhaps prepare the commit; get the message; then actually commit
             raise errors.BzrCommandError("No changes to commit."
                               " Use --unchanged to commit anyhow.")
         except ConflictsInTree:

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/msgeditor.py	2010-04-07 00:50:56 +0000
@@ -27,6 +27,8 @@
     config,
     osutils,
     trace,
+    transport,
+    ui,
     )
 from bzrlib.errors import BzrError, BadCommitMessageEncoding
 from bzrlib.hooks import HookPoint, Hooks
@@ -139,10 +141,18 @@
     try:
         msgfilename, hasinfo = _create_temp_file_with_commit_template(
                                     infotext, ignoreline, start_message)
-
-        if not msgfilename or not _run_editor(msgfilename):
-            return None
-
+        if not msgfilename:
+            return None
+        basename = osutils.basename(msgfilename)
+        msg_transport = transport.get_transport(osutils.dirname(msgfilename))
+        reference_content = msg_transport.get_bytes(basename)
+        if not _run_editor(msgfilename):
+            return None
+        edited_content = msg_transport.get_bytes(basename)
+        if edited_content == reference_content:
+            if not ui.ui_factory.get_boolean(
+                "Commit message was not edited, use anyway"):
+                return ""
         started = False
         msg = []
         lastline, nlines = 0, 0

=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py	2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py	2010-04-07 00:50:56 +0000
@@ -693,6 +693,6 @@
         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")
+        out, err = self.run_bzr("commit tree/hello.txt", stdin="y\n")
         last_rev = tree.branch.repository.get_revision(tree.last_revision())
         self.assertEqual('save me some typing\n', last_rev.message)




More information about the bazaar-commits mailing list