Rev 3686: (Mark Hammond) Fix bug #256550 by using a Unicode api on Windows for in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Sep 3 21:58:48 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3686
revision-id: pqm at pqm.ubuntu.com-20080903205840-mteswj8dfvld7vo3
parent: pqm at pqm.ubuntu.com-20080903202836-qhw58bwsm1sixtfe
parent: john at arbash-meinel.com-20080903200303-qbrlirpfx908inue
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-09-03 21:58:40 +0100
message:
(Mark Hammond) Fix bug #256550 by using a Unicode api on Windows for
the host name.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/atomicfile.py atomicfile.py-20050509044450-dbd24e6c564f7c66
bzrlib/lockdir.py lockdir.py-20060220222025-98258adf27fbdda3
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 3626.1.6
revision-id: john at arbash-meinel.com-20080903200303-qbrlirpfx908inue
parent: john at arbash-meinel.com-20080903200051-ygqm3rh5qtmmx4f9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: unicode_hostname
timestamp: Wed 2008-09-03 15:03:03 -0500
message:
NEWS entry for fixing bug #256550
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 3626.1.5
revision-id: john at arbash-meinel.com-20080903200051-ygqm3rh5qtmmx4f9
parent: john at arbash-meinel.com-20080903195948-24iha6kjan1b0pc9
parent: pqm at pqm.ubuntu.com-20080903094659-lkj3i4hd83d35fov
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: unicode_hostname
timestamp: Wed 2008-09-03 15:00:51 -0500
message:
Merge bzr.dev 3684
removed:
tools/win32/survey.txt survey.txt-20070809075950-sf265mgu9oog8jjb-1
added:
bzrlib/_btree_serializer_c.pyx _parse_btree_c.pyx-20080703034413-3q25bklkenti3p8p-2
bzrlib/_btree_serializer_py.py _parse_btree_py.py-20080703034413-3q25bklkenti3p8p-3
bzrlib/_readdir_py.py readdir.py-20060609152855-rm6v321vuaqyh9tu-3
bzrlib/_readdir_pyx.pyx readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
bzrlib/btree_index.py index.py-20080624222253-p0x5f92uyh5hw734-7
bzrlib/chunk_writer.py chunk_writer.py-20080630234519-6ggn4id17nipovny-1
bzrlib/readdir.h readdir.h-20060609152855-rm6v321vuaqyh9tu-2
bzrlib/tests/test_btree_index.py test_index.py-20080624222253-p0x5f92uyh5hw734-13
bzrlib/tests/test_chunk_writer.py test_chunk_writer.py-20080630234519-6ggn4id17nipovny-2
bzrlib/tests/test_transport_log.py test_transport_log.p-20080902041816-vh8x5yt5nvdzvew3-3
bzrlib/transport/ftp/ ftp-20080611185801-3vm145h8dmnfgh25-1
bzrlib/transport/ftp/_gssapi.py _gssapi.py-20080611190840-7ejrtp884bk5eu72-2
bzrlib/transport/log.py log.py-20080902041816-vh8x5yt5nvdzvew3-5
tools/packaging/ packaging-20080825202834-3j433iaawnt72wqa-1
tools/packaging/build-packages.sh buildpackages.sh-20080821102059-fzlodktas65qmo1k-1
tools/packaging/update-changelogs.sh updatechangelogs.sh-20080821102059-fzlodktas65qmo1k-2
tools/packaging/update-packaging-branches.sh updatepackagingbranc-20080825210254-6is8ciit1yzyd3a2-1
renamed:
bzrlib/transport/ftp.py => bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
doc/en/developer-guide/testing.txt => doc/developers/testing.txt testing.txt-20080812140359-i70zzh6v2z7grqex-1
modified:
.bzrignore bzrignore-20050311232317-81f7b71efa2db11a
Makefile Makefile-20050805140406-d96e3498bb61c5bb
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/__init__.py __init__.py-20050309040759-33e65acf91bbcd5d
bzrlib/_dirstate_helpers_c.pyx dirstate_helpers.pyx-20070503201057-u425eni465q4idwn-3
bzrlib/_dirstate_helpers_py.py _dirstate_helpers_py-20070710145033-90nz6cqglsk150jy-1
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
bzrlib/benchmarks/bench_osutils.py bench_osutils.py-20060608153714-apso8cyz1bu2z1ig-1
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/commands.py bzr.py-20050309040720-d10f4714595cf8c3
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/fetch.py fetch.py-20050818234941-26fea6105696365d
bzrlib/help_topics/en/rules.txt rules.txt-20080516063844-ghr5l6pvvrhiycun-1
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/log.py log.py-20050505065812-c40ce11702fe5fb1
bzrlib/mail_client.py mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
bzrlib/merge.py merge.py-20050513021216-953b65a438527106
bzrlib/option.py option.py-20051014052914-661fb36e76e7362f
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
bzrlib/push.py push.py-20080606021927-5fe39050e8xne9un-1
bzrlib/reconcile.py reweave_inventory.py-20051108164726-1e5e0934febac06e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repofmt/pack_repo.py pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
bzrlib/smart/protocol.py protocol.py-20061108035435-ot0lstk2590yqhzr-1
bzrlib/smart/repository.py repository.py-20061128022038-vr5wy5bubyb8xttk-1
bzrlib/status.py status.py-20050505062338-431bfa63ec9b19e6
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
bzrlib/tests/blackbox/test_cat_revision.py test_cat_revision.py-20070410204634-fq8mnld5l5aza9e2-1
bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
bzrlib/tests/blackbox/test_init.py test_init.py-20060309032856-a292116204d86eb7
bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
bzrlib/tests/blackbox/test_missing.py test_missing.py-20051211212735-a2cf4c1840bb84c4
bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
bzrlib/tests/blackbox/test_outside_wt.py test_outside_wt.py-20060116200058-98edd33e7db8bdde
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/blackbox/test_remove.py test_remove.py-20060530011439-fika5rm84lon0goe-1
bzrlib/tests/blackbox/test_selftest.py test_selftest.py-20060123024542-01c5f1bbcb596d78
bzrlib/tests/blackbox/test_send.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
bzrlib/tests/blackbox/test_shared_repository.py test_shared_repository.py-20060317053531-ed30c0d79325e483
bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
bzrlib/tests/blackbox/test_uncommit.py test_uncommit.py-20051027212835-84944b63adae51be
bzrlib/tests/branch_implementations/test_permissions.py test_permissions.py-20060210110243-245c01403bf0fde6
bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
bzrlib/tests/commands/test_init.py test_init.py-20070514074921-audbcdd8o56dpame-1
bzrlib/tests/commands/test_init_repository.py test_init_repository-20070525163812-87xw0678ky573l27-1
bzrlib/tests/http_utils.py HTTPTestUtil.py-20050914180604-247d3aafb7a43343
bzrlib/tests/intertree_implementations/test_compare.py test_compare.py-20060724101752-09ysswo1a92uqyoz-2
bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
bzrlib/tests/test__dirstate_helpers.py test_dirstate_helper-20070504035751-jsbn00xodv0y1eve-2
bzrlib/tests/test_bundle.py test.py-20050630184834-092aa401ab9f039c
bzrlib/tests/test_bzrdir.py test_bzrdir.py-20060131065654-deba40eef51cf220
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
bzrlib/tests/test_fetch.py testfetch.py-20050825090644-f73e07e7dfb1765a
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/tests/test_index.py test_index.py-20070712131115-lolkarso50vjr64s-2
bzrlib/tests/test_info.py test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
bzrlib/tests/test_log.py testlog.py-20050728115707-1a514809d7d49309
bzrlib/tests/test_merge.py testmerge.py-20050905070950-c1b5aa49ff911024
bzrlib/tests/test_options.py testoptions.py-20051014093702-96457cfc86319a8f
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/tests/test_pack_repository.py test_pack_repository-20080801043947-eaw0e6h2gu75kwmy-1
bzrlib/tests/test_permissions.py test_permissions.py-20051215004520-ccf475789c80e80c
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
bzrlib/tests/test_setup.py test_setup.py-20051208073730-4a59a6368c4efa04
bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
bzrlib/tests/test_status.py test_status.py-20060516190614-fbf6432e4a6e8aa5
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
bzrlib/tests/test_upgrade_stacked.py test_upgrade_stacked-20080804072225-jd13yami19nskns5-1
bzrlib/tests/test_whitebox.py whitebox.py-20050530064534-a063aafb4a0a3a04
bzrlib/tests/tree_implementations/__init__.py __init__.py-20060717075546-420s7b0bj9hzeowi-2
bzrlib/tests/tree_implementations/test_iter_search_rules.py test_iter_search_rul-20080528065532-1ml1ttb12az20cxf-1
bzrlib/tests/tree_implementations/test_walkdirs.py test_walkdirs.py-20060729160421-gmjnkotqgxdh98ce-1
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
bzrlib/transport/remote.py ssh.py-20060608202016-c25gvf1ob7ypbus6-1
bzrlib/transport/trace.py trace.py-20070828055009-7kt0bbc4t4b92apz-1
bzrlib/tree.py tree.py-20050309040759-9d5f2496be663e77
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
doc/developers/development-repo.txt developmentrepo.txt-20080102200205-raj42k61dch8pjmj-1
doc/developers/index.txt index.txt-20070508041241-qznziunkg0nffhiw-1
doc/developers/ppa.txt ppa.txt-20080722055539-606u7t2z32t3ae4w-1
doc/en/mini-tutorial/index.txt index.txt-20070813141352-2u64ooqzo0or4hss-2
doc/en/user-guide/configuring_bazaar.txt configuring_bazaar.t-20071128000722-ncxiua259xwbdbg7-1
doc/es/mini-tutorial/index.txt index.txt-20080504182136-wmoc35u2t6kom8ca-1
setup.py setup.py-20050314065409-02f8a0a6e3f9bc70
tools/win32/bzr.iss.cog bzr.iss.cog-20060622100836-b3yup582rt3y0nvm-5
------------------------------------------------------------
revno: 3626.1.4
revision-id: john at arbash-meinel.com-20080903195948-24iha6kjan1b0pc9
parent: john at arbash-meinel.com-20080819194410-f1cxgbwx541r8vaq
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: unicode_hostname
timestamp: Wed 2008-09-03 14:59:48 -0500
message:
Document the difference in get_host_name, per Robert's request.
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
------------------------------------------------------------
revno: 3626.1.3
revision-id: john at arbash-meinel.com-20080819194410-f1cxgbwx541r8vaq
parent: skip at vistadev--20080817032414-rzsqf40vu6c641ha
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: unicode_hostname
timestamp: Tue 2008-08-19 14:44:10 -0500
message:
Use GetComputerNameEx from ctypes when available.
modified:
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 3626.1.2
revision-id: skip at vistadev--20080817032414-rzsqf40vu6c641ha
parent: mhammond at skippinet.com.au-20080816040054-7ptlmd3zbmxf9yig
committer: skip <skip at vistadev-©har>
branch nick: bzr.work.hostname
timestamp: Sun 2008-08-17 13:24:14 +1000
message:
win32utils.get_host_name() uses 'mbcs' encoding when decoding env vars
and prefer GetComputerNameExW(ComputerNameDnsFullyQualified) if available
modified:
bzrlib/win32utils.py win32console.py-20051021033308-123c6c929d04973d
------------------------------------------------------------
revno: 3626.1.1
revision-id: mhammond at skippinet.com.au-20080816040054-7ptlmd3zbmxf9yig
parent: pqm at pqm.ubuntu.com-20080814032324-mhfk4rggo7hgxeuf
committer: Mark Hammond <mhammond at skippinet.com.au>
branch nick: bzr.work.hostname
timestamp: Sat 2008-08-16 14:00:54 +1000
message:
Add osutils.get_host_name() to return a unicode hostname to prevent
non-ascii host names from causing Unicode error. Fixes bzr/+bug/256550
modified:
bzrlib/atomicfile.py atomicfile.py-20050509044450-dbd24e6c564f7c66
bzrlib/lockdir.py lockdir.py-20060220222025-98258adf27fbdda3
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
=== modified file 'NEWS'
--- a/NEWS 2008-09-03 19:54:34 +0000
+++ b/NEWS 2008-09-03 20:58:40 +0000
@@ -90,6 +90,10 @@
check and test for parsing a dirstate with invalid trailing data.
(John Arbash Meinel, #186014)
+ * Use a Windows api function to get a Unicode host name, rather than
+ assuming the host name is ascii.
+ (Mark Hammond, John Arbash Meinel, #256550)
+
* ``WorkingTree4`` trees will now correctly report missing-and-new
paths in the output of ``iter_changes``. (Robert Collins)
=== modified file 'bzrlib/atomicfile.py'
--- a/bzrlib/atomicfile.py 2008-04-24 07:22:53 +0000
+++ b/bzrlib/atomicfile.py 2008-08-16 04:00:54 +0000
@@ -53,7 +53,7 @@
self._fd = None
if _hostname is None:
- _hostname = socket.gethostname()
+ _hostname = osutils.get_host_name()
self.tmpfilename = '%s.%d.%s.tmp' % (filename, _pid, _hostname)
=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py 2008-05-21 01:38:52 +0000
+++ b/bzrlib/lockdir.py 2008-08-16 04:00:54 +0000
@@ -128,7 +128,7 @@
)
from bzrlib.trace import mutter, note
from bzrlib.transport import Transport
-from bzrlib.osutils import rand_chars, format_delta
+from bzrlib.osutils import rand_chars, format_delta, get_host_name
from bzrlib.rio import read_stanza, Stanza
import bzrlib.ui
@@ -422,14 +422,13 @@
def _prepare_info(self):
"""Write information about a pending lock to a temporary file.
"""
- import socket
# XXX: is creating this here inefficient?
config = bzrlib.config.GlobalConfig()
try:
user = config.user_email()
except errors.NoEmailInUsername:
user = config.username()
- s = Stanza(hostname=socket.gethostname(),
+ s = Stanza(hostname=get_host_name(),
pid=str(os.getpid()),
start_time=str(int(time.time())),
nonce=self.nonce,
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2008-09-03 06:31:11 +0000
+++ b/bzrlib/osutils.py 2008-09-03 20:00:51 +0000
@@ -1470,6 +1470,20 @@
return user_encoding
+def get_host_name():
+ """Return the current unicode host name.
+
+ This is meant to be used in place of socket.gethostname() because that
+ behaves inconsistently on different platforms.
+ """
+ if sys.platform == "win32":
+ import win32utils
+ return win32utils.get_host_name()
+ else:
+ import socket
+ return socket.gethostname().decode(get_user_encoding())
+
+
def recv_all(socket, bytes):
"""Receive an exact number of bytes.
=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py 2007-11-26 08:54:41 +0000
+++ b/bzrlib/win32utils.py 2008-08-19 19:44:10 +0000
@@ -69,6 +69,11 @@
has_win32file = True
except ImportError:
has_win32file = False
+try:
+ import win32api
+ has_win32api = True
+except ImportError:
+ has_win32api = False
# Special Win32 API constants
@@ -202,27 +207,58 @@
return os.environ.get('USERNAME', None)
+# 1 == ComputerNameDnsHostname, which returns "The DNS host name of the local
+# computer or the cluster associated with the local computer."
+_WIN32_ComputerNameDnsHostname = 1
+
def get_host_name():
"""Return host machine name.
If name cannot be obtained return None.
- Returned value can be unicode or plain sring.
- To convert plain string to unicode use
- s.decode(bzrlib.user_encoding)
+ :return: A unicode string representing the host name. On win98, this may be
+ a plain string as win32 api doesn't support unicode.
"""
+ if has_win32api:
+ try:
+ return win32api.GetComputerNameEx(_WIN32_ComputerNameDnsHostname)
+ except (NotImplementedError, win32api.error):
+ # NotImplemented will happen on win9x...
+ pass
if has_ctypes:
try:
kernel32 = ctypes.windll.kernel32
- GetComputerName = getattr(kernel32, 'GetComputerName'+suffix)
except AttributeError:
- pass
+ pass # Missing the module we need
else:
buf = create_buffer(MAX_COMPUTERNAME_LENGTH+1)
n = ctypes.c_int(MAX_COMPUTERNAME_LENGTH+1)
- if GetComputerName(buf, ctypes.byref(n)):
- return buf.value
- # otherwise try env variables
- return os.environ.get('COMPUTERNAME', None)
+
+ # Try GetComputerNameEx which gives a proper Unicode hostname
+ GetComputerNameEx = getattr(kernel32, 'GetComputerNameEx'+suffix,
+ None)
+ if (GetComputerNameEx is not None
+ and GetComputerNameEx(_WIN32_ComputerNameDnsHostname,
+ buf, ctypes.byref(n))):
+ return buf.value
+
+ # Try GetComputerName in case GetComputerNameEx wasn't found
+ # It returns the NETBIOS name, which isn't as good, but still ok.
+ # The first GetComputerNameEx might have changed 'n', so reset it
+ n = ctypes.c_int(MAX_COMPUTERNAME_LENGTH+1)
+ GetComputerName = getattr(kernel32, 'GetComputerName'+suffix,
+ None)
+ if (GetComputerName is not None
+ and GetComputerName(buf, ctypes.byref(n))):
+ return buf.value
+ # otherwise try env variables, which will be 'mbcs' encoded
+ # on Windows (Python doesn't expose the native win32 unicode environment)
+ # According to this:
+ # http://msdn.microsoft.com/en-us/library/aa246807.aspx
+ # environment variables should always be encoded in 'mbcs'.
+ try:
+ return os.environ['COMPUTERNAME'].decode("mbcs")
+ except KeyError:
+ return None
def _ensure_unicode(s):
@@ -230,7 +266,7 @@
import bzrlib
s = s.decode(bzrlib.user_encoding)
return s
-
+
def get_appdata_location_unicode():
return _ensure_unicode(get_appdata_location())
More information about the bazaar-commits
mailing list