Rev 2800: bugfix #131100: bzr --version should care about encoding of stdout in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Sep 5 09:48:27 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2800
revision-id: pqm at pqm.ubuntu.com-20070905084824-xdwd8f4fioovdi9v
parent: pqm at pqm.ubuntu.com-20070905060644-7559hac0lrdw0xjb
parent: bialix at ukr.net-20070905081857-me1osc2lpuzq6ur1
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-09-05 09:48:24 +0100
message:
bugfix #131100: bzr --version should care about encoding of stdout
(bialix,r=ianc)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_version.py test_version.py-20070312060045-ol7th9z035r3im3d-1
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/version.py version.py-20060816024207-ves6ult9a11taj9t-1
------------------------------------------------------------
revno: 2785.1.7
merged: bialix at ukr.net-20070905081857-me1osc2lpuzq6ur1
parent: bialix at ukr.net-20070904112050-muj2o81u0xuaheoz
parent: pqm at pqm.ubuntu.com-20070905060644-7559hac0lrdw0xjb
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: show-version
timestamp: Wed 2007-09-05 11:18:57 +0300
message:
merge bzr.dev
------------------------------------------------------------
revno: 2785.1.6
merged: bialix at ukr.net-20070904112050-muj2o81u0xuaheoz
parent: bialix at ukr.net-20070904110030-pma21wbsylstkdnv
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: show-version
timestamp: Tue 2007-09-04 14:20:50 +0300
message:
show path to python dll instead of bzr.exe for standalone application
------------------------------------------------------------
revno: 2785.1.5
merged: bialix at ukr.net-20070904110030-pma21wbsylstkdnv
parent: bialix at ukr.net-20070904105639-7v4f759v470td0gh
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: show-version
timestamp: Tue 2007-09-04 14:00:30 +0300
message:
support for non-ascii BZR_HOME in show_version()
------------------------------------------------------------
revno: 2785.1.4
merged: bialix at ukr.net-20070904105639-7v4f759v470td0gh
parent: bialix at ukr.net-20070903125826-32dwn9mjziqvi7e0
committer: Alexander Belchenko <bialix at ukr.net>
branch nick: show-version
timestamp: Tue 2007-09-04 13:56:39 +0300
message:
tweak identation (review from Ian C.)
------------------------------------------------------------
revno: 2785.1.3
merged: bialix at ukr.net-20070903125826-32dwn9mjziqvi7e0
parent: bialix at ukr.net-20070903125357-hy1wzy0wv1exq5uv
committer: bialix at ukr.net
branch nick: show-version
timestamp: Mon 2007-09-03 15:58:26 +0300
message:
NEWS
------------------------------------------------------------
revno: 2785.1.2
merged: bialix at ukr.net-20070903125357-hy1wzy0wv1exq5uv
parent: bialix at ukr.net-20070903123635-yirtvrekkbzw7swl
committer: bialix at ukr.net
branch nick: show-version
timestamp: Mon 2007-09-03 15:53:57 +0300
message:
bugfix for #131100
------------------------------------------------------------
revno: 2785.1.1
merged: bialix at ukr.net-20070903123635-yirtvrekkbzw7swl
parent: pqm at pqm.ubuntu.com-20070903083917-b6n7swxr3yolv0ak
committer: bialix at ukr.net
branch nick: show-version
timestamp: Mon 2007-09-03 15:36:35 +0300
message:
test cases for #131100
=== modified file 'NEWS'
--- a/NEWS 2007-09-05 05:31:31 +0000
+++ b/NEWS 2007-09-05 08:18:57 +0000
@@ -120,6 +120,9 @@
* When committing to a branch, the location being committed to is
displayed. (Daniel Watkins, #52479)
+ * ``bzr --version`` takes care about encoding of stdout, especially
+ when output is redirected. (Alexander Belchenko, #131100)
+
IMPROVEMENTS:
* Add the option "--show-diff" to the commit command in order to display
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-09-05 03:20:26 +0000
+++ b/bzrlib/builtins.py 2007-09-05 08:18:57 +0000
@@ -2561,7 +2561,6 @@
from bzrlib.tests import selftest
import bzrlib.benchmarks as benchmarks
from bzrlib.benchmarks import tree_creator
- from bzrlib.version import show_version
if cache_dir is not None:
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
@@ -2615,10 +2614,12 @@
class cmd_version(Command):
"""Show version of bzr."""
+ encoding_type = 'replace'
+
@display_command
def run(self):
from bzrlib.version import show_version
- show_version()
+ show_version(to_file=self.outf)
class cmd_rocks(Command):
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2007-09-03 09:46:21 +0000
+++ b/bzrlib/commands.py 2007-09-05 08:18:57 +0000
@@ -449,9 +449,8 @@
output_encoding = osutils.get_terminal_encoding()
- # use 'replace' so that we don't abort if trying to write out
- # in e.g. the default C locale.
- self.outf = codecs.getwriter(output_encoding)(sys.stdout, errors=self.encoding_type)
+ self.outf = codecs.getwriter(output_encoding)(sys.stdout,
+ errors=self.encoding_type)
# For whatever reason codecs.getwriter() does not advertise its encoding
# it just returns the encoding of the wrapped file, which is completely
# bogus. So set the attribute, so we can find the correct encoding later.
@@ -722,8 +721,8 @@
return 0
if argv[0] == '--version':
- from bzrlib.version import show_version
- show_version()
+ from bzrlib.builtins import cmd_version
+ cmd_version().run_argv_aliases([])
return 0
if not opt_no_plugins:
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-09-04 04:12:07 +0000
+++ b/bzrlib/tests/__init__.py 2007-09-05 08:18:57 +0000
@@ -2652,3 +2652,21 @@
new_id = "%s(%s)" % (new_test.id(), scenario[0])
new_test.id = lambda: new_id
return new_test
+
+
+def probe_unicode_in_user_encoding():
+ """Try to encode several unicode strings to use in unicode-aware tests.
+ Return first successfull match.
+
+ :return: (unicode value, encoded plain string value) or (None, None)
+ """
+ possible_vals = [u'm\xb5', u'\xe1', u'\u0410']
+ for uni_val in possible_vals:
+ try:
+ str_val = uni_val.encode(bzrlib.user_encoding)
+ except UnicodeEncodeError:
+ # Try a different character
+ pass
+ else:
+ return uni_val, str_val
+ return None, None
=== modified file 'bzrlib/tests/blackbox/test_version.py'
--- a/bzrlib/tests/blackbox/test_version.py 2007-07-13 03:16:31 +0000
+++ b/bzrlib/tests/blackbox/test_version.py 2007-09-04 11:00:30 +0000
@@ -17,10 +17,16 @@
"""Black-box tests for bzr version."""
import bzrlib
-from bzrlib.tests.blackbox import ExternalBase
-
-
-class TestVersion(ExternalBase):
+from bzrlib import osutils, trace
+from bzrlib.tests import (
+ probe_unicode_in_user_encoding,
+ TestCase,
+ TestCaseInTempDir,
+ TestSkipped,
+ )
+
+
+class TestVersion(TestCase):
def test_version(self):
out = self.run_bzr("version")[0]
@@ -31,3 +37,40 @@
self.assertContainsRe(out, r"(?m)^ bzrlib:")
self.assertContainsRe(out, r"(?m)^ Bazaar configuration:")
self.assertContainsRe(out, r'(?m)^ Bazaar log file:.*bzr\.log')
+
+
+class TestVersionUnicodeOutput(TestCaseInTempDir):
+
+ def _check(self, args):
+ # Even though trace._bzr_log_filename variable
+ # is used only to keep actual log filename
+ # and changing this variable in selftest
+ # don't change main .bzr.log location,
+ # and therefore pretty safe,
+ # but we run these tests in separate temp dir
+ # with relative unicoded path
+ old_trace_file = trace._bzr_log_filename
+ trace._bzr_log_filename = u'\u1234/.bzr.log'
+ try:
+ out = self.run_bzr(args)[0]
+ finally:
+ trace._bzr_log_filename = old_trace_file
+ self.assertTrue(len(out) > 0)
+ self.assertContainsRe(out, r'(?m)^ Bazaar log file:.*bzr\.log')
+
+ def test_command(self):
+ self._check("version")
+
+ def test_flag(self):
+ self._check("--version")
+
+ def test_unicode_bzr_home(self):
+ uni_val, str_val = probe_unicode_in_user_encoding()
+ if uni_val is None:
+ raise TestSkipped('Cannot find a unicode character that works in'
+ ' encoding %s' % (bzrlib.user_encoding,))
+
+ osutils.set_or_unset_env('BZR_HOME', str_val)
+ out = self.run_bzr("version")[0]
+ self.assertTrue(len(out) > 0)
+ self.assertContainsRe(out, r"(?m)^ Bazaar configuration: " + str_val)
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2007-08-21 05:08:31 +0000
+++ b/bzrlib/tests/test_osutils.py 2007-09-04 11:00:30 +0000
@@ -35,6 +35,7 @@
pathjoin,
)
from bzrlib.tests import (
+ probe_unicode_in_user_encoding,
StringIOWrapper,
TestCase,
TestCaseInTempDir,
@@ -1001,18 +1002,8 @@
So Unicode strings must be encoded.
"""
- # Try a few different characters, to see if we can get
- # one that will be valid in the user_encoding
- possible_vals = [u'm\xb5', u'\xe1', u'\u0410']
- for uni_val in possible_vals:
- try:
- env_val = uni_val.encode(bzrlib.user_encoding)
- except UnicodeEncodeError:
- # Try a different character
- pass
- else:
- break
- else:
+ uni_val, env_val = probe_unicode_in_user_encoding()
+ if uni_val is None:
raise TestSkipped('Cannot find a unicode character that works in'
' encoding %s' % (bzrlib.user_encoding,))
=== modified file 'bzrlib/version.py'
--- a/bzrlib/version.py 2007-07-13 01:37:19 +0000
+++ b/bzrlib/version.py 2007-09-04 11:20:50 +0000
@@ -30,38 +30,58 @@
from bzrlib.branch import Branch
-def show_version(show_config=True, show_copyright=True):
- print "Bazaar (bzr) %s" % bzrlib.__version__
+def show_version(show_config=True, show_copyright=True, to_file=None):
+ if to_file is None:
+ to_file = sys.stdout
+ print >>to_file, "Bazaar (bzr) %s" % bzrlib.__version__
# is bzrlib itself in a branch?
src_tree = _get_bzr_source_tree()
if src_tree:
src_revision_id = src_tree.last_revision()
revno = src_tree.branch.revision_id_to_revno(src_revision_id)
- print " from bzr checkout", src_tree.basedir
- print " revision:", revno
- print " revid:", src_revision_id
- print " branch nick:", src_tree.branch.nick
- print " Python interpreter:", sys.executable, '.'.join(map(str, sys.version_info))
- print " Python standard library:", os.path.dirname(os.__file__)
- print " bzrlib:",
+ print >>to_file, " from bzr checkout", src_tree.basedir
+ print >>to_file, " revision:", revno
+ print >>to_file, " revid:", src_revision_id
+ print >>to_file, " branch nick:", src_tree.branch.nick
+
+ print >>to_file, " Python interpreter:",
+ # show path to python interpreter
+ # (bzr.exe use python interpreter from pythonXY.dll
+ # but sys.executable point to bzr.exe itself)
+ if not hasattr(sys, 'frozen'): # check for bzr.exe
+ # python executable
+ print >>to_file, sys.executable,
+ else:
+ # pythonXY.dll
+ basedir = os.path.dirname(sys.executable)
+ python_dll = "python%d%d.dll" % sys.version_info[:2]
+ print >>to_file, os.path.join(basedir, python_dll),
+ # and now version of python interpreter
+ print >>to_file, '.'.join(map(str, sys.version_info))
+
+ print >>to_file, " Python standard library:", os.path.dirname(os.__file__)
+ print >>to_file, " bzrlib:",
if len(bzrlib.__path__) > 1:
# print repr, which is a good enough way of making it clear it's
# more than one element (eg ['/foo/bar', '/foo/bzr'])
- print repr(bzrlib.__path__)
+ print >>to_file, repr(bzrlib.__path__)
else:
- print bzrlib.__path__[0]
+ print >>to_file, bzrlib.__path__[0]
if show_config:
- print " Bazaar configuration:", config.config_dir()
- print " Bazaar log file:", trace._bzr_log_filename
+ config_dir = os.path.normpath(config.config_dir()) # use native slashes
+ if not isinstance(config_dir, unicode):
+ config_dir = config_dir.decode(bzrlib.user_encoding)
+ print >>to_file, " Bazaar configuration:", config_dir
+ print >>to_file, " Bazaar log file:", trace._bzr_log_filename
if show_copyright:
- print
- print bzrlib.__copyright__
- print "http://bazaar-vcs.org/"
- print
- print "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
- print "you may use, modify and redistribute it under the terms of the GNU"
- print "General Public License version 2 or later."
- print
+ print >>to_file
+ print >>to_file, bzrlib.__copyright__
+ print >>to_file, "http://bazaar-vcs.org/"
+ print >>to_file
+ print >>to_file, "bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and"
+ print >>to_file, "you may use, modify and redistribute it under the terms of the GNU"
+ print >>to_file, "General Public License version 2 or later."
+ print >>to_file
def _get_bzr_source_tree():
More information about the bazaar-commits
mailing list