Rev 2766: (Daniel Watkins) fix for commit raising UnicodeError (traceback) if LANG is incorrect in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Aug 29 10:45:50 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2766
revision-id: pqm at pqm.ubuntu.com-20070829094547-qm9ntd7pd95r7w8c
parent: pqm at pqm.ubuntu.com-20070829061006-7zz2j5icnc8do0ru
parent: ian.clatworthy at internode.on.net-20070829085521-9oeu33oc30w0bjpi
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-08-29 10:45:47 +0100
message:
(Daniel Watkins) fix for commit raising UnicodeError (traceback) if LANG is incorrect
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
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
------------------------------------------------------------
revno: 2765.1.2
merged: ian.clatworthy at internode.on.net-20070829085521-9oeu33oc30w0bjpi
parent: ian.clatworthy at internode.on.net-20070829081822-yd131m9hl2m53lhk
committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
branch nick: ianc-integration
timestamp: Wed 2007-08-29 18:55:21 +1000
message:
fix try/except/finally nesting for Python 2.4
------------------------------------------------------------
revno: 2765.1.1
merged: ian.clatworthy at internode.on.net-20070829081822-yd131m9hl2m53lhk
parent: pqm at pqm.ubuntu.com-20070829061006-7zz2j5icnc8do0ru
parent: d.m.watkins at warwick.ac.uk-20070821125537-kmoystprykftt5th
committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
branch nick: ianc-integration
timestamp: Wed 2007-08-29 18:18:22 +1000
message:
(Daniel Watkins) fix for commit raising UnicodeError (traceback) if LANG is incorrect
------------------------------------------------------------
revno: 2625.9.11
merged: d.m.watkins at warwick.ac.uk-20070821125537-kmoystprykftt5th
parent: d.m.watkins at warwick.ac.uk-20070821123242-2z9w63aqc3p0s089
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Tue 2007-08-21 14:55:37 +0200
message:
Cleanup.
------------------------------------------------------------
revno: 2625.9.10
merged: d.m.watkins at warwick.ac.uk-20070821123242-2z9w63aqc3p0s089
parent: d.m.watkins at warwick.ac.uk-20070821122801-y8y7bf9n928hbjfb
parent: pqm at pqm.ubuntu.com-20070821044713-ttnupbvhlsbwh1he
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Tue 2007-08-21 14:32:42 +0200
message:
Merged bzr.dev, fixing NEWS.
------------------------------------------------------------
revno: 2625.9.9
merged: d.m.watkins at warwick.ac.uk-20070821122801-y8y7bf9n928hbjfb
parent: d.m.watkins at warwick.ac.uk-20070807113826-5b98xh1jcllm1frx
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Tue 2007-08-21 14:28:01 +0200
message:
Used format string as suggested by abentley.
------------------------------------------------------------
revno: 2625.9.8
merged: d.m.watkins at warwick.ac.uk-20070807113826-5b98xh1jcllm1frx
parent: d.m.watkins at warwick.ac.uk-20070730162917-6beay7tbjqdidn3m
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Tue 2007-08-07 12:38:26 +0100
message:
Updated as per poolie's !tweak.
------------------------------------------------------------
revno: 2625.9.7
merged: d.m.watkins at warwick.ac.uk-20070730162917-6beay7tbjqdidn3m
parent: d.m.watkins at warwick.ac.uk-20070730162841-ztnud0ga0sdhnl1h
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 17:29:17 +0100
message:
'bzr commit' now exits cleanly if a character unsupported by the current encoding is used in the commit message (fixing bug #116143).
------------------------------------------------------------
revno: 2625.9.6
merged: d.m.watkins at warwick.ac.uk-20070730162841-ztnud0ga0sdhnl1h
parent: d.m.watkins at warwick.ac.uk-20070730162702-57m2jj2lovqyw4gq
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 17:28:41 +0100
message:
Added test to ensure correct error message is thrown when an unencodable commit message is entered through the editor.
------------------------------------------------------------
revno: 2625.9.5
merged: d.m.watkins at warwick.ac.uk-20070730162702-57m2jj2lovqyw4gq
parent: d.m.watkins at warwick.ac.uk-20070730162626-l7a4gtltquh6nu1x
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 17:27:02 +0100
message:
Modified test_msgeditor.make_fake_editor to allow a custom message to be inserted.
------------------------------------------------------------
revno: 2625.9.4
merged: d.m.watkins at warwick.ac.uk-20070730162626-l7a4gtltquh6nu1x
parent: d.m.watkins at warwick.ac.uk-20070730162552-63klyh8lcv2pz8wm
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 17:26:26 +0100
message:
Fixed editor commit message to die cleanly if a UnicodeDecodeError is thrown.
------------------------------------------------------------
revno: 2625.9.3
merged: d.m.watkins at warwick.ac.uk-20070730162552-63klyh8lcv2pz8wm
parent: d.m.watkins at warwick.ac.uk-20070730044658-dibjohko37p176ex
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 17:25:52 +0100
message:
Added BadCommitMessageEncoding error.
------------------------------------------------------------
revno: 2625.9.2
merged: d.m.watkins at warwick.ac.uk-20070730044658-dibjohko37p176ex
parent: d.m.watkins at warwick.ac.uk-20070727225945-y8qywyj9hsqrlvjc
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Mon 2007-07-30 05:46:58 +0100
message:
Added test to ensure correct error message is given if an unencodable commit message is given at the command line.
------------------------------------------------------------
revno: 2625.9.1
merged: d.m.watkins at warwick.ac.uk-20070727225945-y8qywyj9hsqrlvjc
parent: pqm at pqm.ubuntu.com-20070717180333-5smmeduk2q3sbzvw
committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
branch nick: 116143
timestamp: Fri 2007-07-27 23:59:45 +0100
message:
Fixed command-line commit message to die cleanly if a UnicodeDecodeError is thrown.
=== modified file 'NEWS'
--- a/NEWS 2007-08-29 06:10:06 +0000
+++ b/NEWS 2007-08-29 08:18:22 +0000
@@ -66,6 +66,10 @@
* TreeTransform-based operations, like pull, merge, revert, and branch,
now roll back if they encounter an error. (Aaron Bentley, #67699)
+ * ``bzr commit`` now exits cleanly if a character unsupported by the
+ current encoding is used in the commit message. (Daniel Watkins,
+ #116143)
+
IMPROVEMENTS:
* ``pull`` and ``merge`` are much faster at installing bundle format 4.
@@ -82,6 +86,9 @@
* Help on debug flags is now included in ``help global-options``.
(Daniel Watkins, #124853)
+ * Parameters passed on the command line are checked to ensure they are
+ supported by the encoding in use. (Daniel Watkins)
+
API BREAKS:
* ``Branch.append_revision`` is removed altogether; please use
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2007-08-15 04:33:34 +0000
+++ b/bzrlib/commands.py 2007-08-21 12:32:42 +0000
@@ -770,7 +770,11 @@
import bzrlib.ui
from bzrlib.ui.text import TextUIFactory
bzrlib.ui.ui_factory = TextUIFactory()
- argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
+ try:
+ argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
+ except UnicodeDecodeError:
+ raise errors.BzrError(("Parameter '%r' is unsupported by the current "
+ "encoding." % a))
ret = run_bzr_catch_errors(argv)
trace.mutter("return code %d", ret)
return ret
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-08-29 05:22:21 +0000
+++ b/bzrlib/errors.py 2007-08-29 08:18:22 +0000
@@ -950,6 +950,12 @@
BzrError.__init__(self, files=files, files_str=files_str)
+class BadCommitMessageEncoding(BzrError):
+
+ _fmt = 'The specified commit message contains characters unsupported by '\
+ 'the current encoding.'
+
+
class UpgradeReadonly(BzrError):
_fmt = "Upgrade URL cannot work with readonly URLs."
=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py 2007-04-30 19:52:44 +0000
+++ b/bzrlib/msgeditor.py 2007-08-29 08:55:21 +0000
@@ -25,7 +25,7 @@
import bzrlib
import bzrlib.config as config
-from bzrlib.errors import BzrError
+from bzrlib.errors import BzrError, BadCommitMessageEncoding
from bzrlib.trace import warning, mutter
@@ -113,24 +113,29 @@
# codecs.open() ALWAYS opens file in binary mode but we need text mode
# 'rU' mode useful when bzr.exe used on Cygwin (bialix 20070430)
f = file(msgfilename, 'rU')
- for line in codecs.getreader(bzrlib.user_encoding)(f):
- stripped_line = line.strip()
- # strip empty line before the log message starts
- if not started:
- if stripped_line != "":
- started = True
- else:
- continue
- # check for the ignore line only if there
- # is additional information at the end
- if hasinfo and stripped_line == ignoreline:
- break
- nlines += 1
- # keep track of the last line that had some content
- if stripped_line != "":
- lastline = nlines
- msg.append(line)
- f.close()
+ try:
+ try:
+ for line in codecs.getreader(bzrlib.user_encoding)(f):
+ stripped_line = line.strip()
+ # strip empty line before the log message starts
+ if not started:
+ if stripped_line != "":
+ started = True
+ else:
+ continue
+ # check for the ignore line only if there
+ # is additional information at the end
+ if hasinfo and stripped_line == ignoreline:
+ break
+ nlines += 1
+ # keep track of the last line that had some content
+ if stripped_line != "":
+ lastline = nlines
+ msg.append(line)
+ except UnicodeDecodeError:
+ raise BadCommitMessageEncoding()
+ finally:
+ f.close()
if len(msg) == 0:
return ""
=== modified file 'bzrlib/tests/blackbox/test_commit.py'
--- a/bzrlib/tests/blackbox/test_commit.py 2007-08-07 14:57:35 +0000
+++ b/bzrlib/tests/blackbox/test_commit.py 2007-08-21 12:32:42 +0000
@@ -224,6 +224,15 @@
self.run_bzr('add foo.c')
self.run_bzr('commit -m ""', retcode=3)
+ def test_unsupported_encoding_commit_message(self):
+ tree = self.make_branch_and_tree('.')
+ self.build_tree_contents([('foo.c', 'int main() {}')])
+ tree.add('foo.c')
+ out,err = self.run_bzr_subprocess('commit -m "\xff"', retcode=1,
+ env_changes={'LANG': 'C'})
+ self.assertContainsRe(err, r'bzrlib.errors.BzrError: Parameter.*is '
+ 'unsupported by the current encoding.')
+
def test_other_branch_commit(self):
# this branch is to ensure consistent behaviour, whether we're run
# inside a branch, or not.
=== modified file 'bzrlib/tests/test_msgeditor.py'
--- a/bzrlib/tests/test_msgeditor.py 2007-05-01 09:09:18 +0000
+++ b/bzrlib/tests/test_msgeditor.py 2007-08-21 12:28:01 +0000
@@ -26,6 +26,11 @@
from bzrlib.tests import TestCaseWithTransport, TestSkipped
from bzrlib.trace import mutter
+from bzrlib import (
+ osutils,
+ errors
+ )
+
class MsgEditorTest(TestCaseWithTransport):
@@ -80,7 +85,7 @@
self.assertEqual(True, bzrlib.msgeditor._run_editor(''),
'Unable to run dummy fake editor')
- def make_fake_editor(self):
+ def make_fake_editor(self, message='test message from fed\\n'):
"""Set up environment so that an editor will be a known script.
Sets up BZR_EDITOR so that if an editor is spawned it will run a
@@ -89,6 +94,7 @@
f = file('fed.py', 'wb')
f.write('#!%s\n' % sys.executable)
f.write("""\
+# coding=utf-8
import sys
if len(sys.argv) == 2:
fn = sys.argv[1]
@@ -96,10 +102,10 @@
s = f.read()
f.close()
f = file(fn, 'wb')
- f.write('test message from fed\\n')
+ f.write('%s')
f.write(s)
f.close()
-""")
+""" % (message, ))
f.close()
if sys.platform == "win32":
# [win32] make batch file and set BZR_EDITOR
@@ -210,3 +216,14 @@
self.assertNotEqual(None, msgfilename)
self.assertFalse(hasinfo)
self.assertFileEqual('', msgfilename)
+
+ def test_unsupported_encoding_commit_message(self):
+ old_env = osutils.set_or_unset_env('LANG', 'C')
+ try:
+ self.make_fake_editor(message='\xff')
+
+ working_tree = self.make_uncommitted_tree()
+ self.assertRaises(errors.BadCommitMessageEncoding,
+ bzrlib.msgeditor.edit_commit_message, '')
+ finally:
+ osutils.set_or_unset_env('LANG', old_env)
More information about the bazaar-commits
mailing list