[PATCH 1 of 1 stable] win32: remove try-catch block of GetModuleFileNameEx (issue2480)

Yuya Nishihara yuya at tcha.org
Wed Nov 10 10:22:19 CST 2010


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1289405571 -32400
# Node ID 0da1cea28f221d0ad67ae03a51a69eead949bcf2
# Parent  e80128e40c044ea6619c3dc160df69ad36a8e5ff
win32: remove try-catch block of GetModuleFileNameEx (issue2480)

According to the API document, GetModuleFileName is the preferred way to
retrieve the filename of the current process. So we shouldn't try
GetModuleFileName'Ex' first.

Previously system_rcpath_win32() happened to return unicode paths due to
GetModuleFileNameEx (issue2480). This problem is fixed as GetModuleFileName
never return unicode.

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -102,12 +102,7 @@ def lookup_reg(key, valname=None, scope=
 
 def system_rcpath_win32():
     '''return default os-specific hgrc search path'''
-    proc = win32api.GetCurrentProcess()
-    try:
-        # This will fail on windows < NT
-        filename = win32process.GetModuleFileNameEx(proc, 0)
-    except:
-        filename = win32api.GetModuleFileName(0)
+    filename = win32api.GetModuleFileName(0)
     # Use mercurial.ini found in directory with hg.exe
     progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
     if os.path.isfile(progrc):


More information about the Mercurial-devel mailing list