[PATCH] win32: fix unicode error caused by GetModuleFileNameEx (issue2480)

Yuya Nishihara yuya at tcha.org
Tue Nov 9 10:46:58 CST 2010


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1289320880 -32400
# Node ID 08d6ea6440e222ee6530fef95aafd0b9b6d45e8f
# Parent  9f2ac318b92e3bde06108bf8493b7d71219ad13e
win32: fix unicode error caused by GetModuleFileNameEx (issue2480)

system_rcpath_win32() happened to return unicode paths due to
win32process.GetModuleFileNameEx().

This patch tries to encode the result of GetModuleFileNameEx to locale
encoding. If encoding failed, falls back to GetModuleFileName, which returns
string.

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -106,6 +106,7 @@ def system_rcpath_win32():
     try:
         # This will fail on windows < NT
         filename = win32process.GetModuleFileNameEx(proc, 0)
+        filename = filename.encode(encoding.encoding)
     except:
         filename = win32api.GetModuleFileName(0)
     # Use mercurial.ini found in directory with hg.exe


More information about the Mercurial-devel mailing list