3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
4 # |
4 # |
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 import osutil, encoding |
8 import encoding |
9 import ctypes, errno, os, struct, subprocess |
9 import ctypes, errno, os, struct, subprocess |
10 |
10 |
11 _kernel32 = ctypes.windll.kernel32 |
11 _kernel32 = ctypes.windll.kernel32 |
12 |
12 |
13 _BOOL = ctypes.c_long |
13 _BOOL = ctypes.c_long |
220 raise ctypes.WinError() |
220 raise ctypes.WinError() |
221 elif len == size: |
221 elif len == size: |
222 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) |
222 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) |
223 return buf.value |
223 return buf.value |
224 |
224 |
225 def system_rcpath_win32(): |
|
226 '''return default os-specific hgrc search path''' |
|
227 rcpath = [] |
|
228 filename = executable_path() |
|
229 # Use mercurial.ini found in directory with hg.exe |
|
230 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
231 if os.path.isfile(progrc): |
|
232 rcpath.append(progrc) |
|
233 return rcpath |
|
234 # Use hgrc.d found in directory with hg.exe |
|
235 progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') |
|
236 if os.path.isdir(progrcd): |
|
237 for f, kind in osutil.listdir(progrcd): |
|
238 if f.endswith('.rc'): |
|
239 rcpath.append(os.path.join(progrcd, f)) |
|
240 return rcpath |
|
241 # else look for a system rcpath in the registry |
|
242 value = lookup_reg('SOFTWARE\\Mercurial', None, _HKEY_LOCAL_MACHINE) |
|
243 if not isinstance(value, str) or not value: |
|
244 return rcpath |
|
245 value = value.replace('/', os.sep) |
|
246 for p in value.split(os.pathsep): |
|
247 if p.lower().endswith('mercurial.ini'): |
|
248 rcpath.append(p) |
|
249 elif os.path.isdir(p): |
|
250 for f, kind in osutil.listdir(p): |
|
251 if f.endswith('.rc'): |
|
252 rcpath.append(os.path.join(p, f)) |
|
253 return rcpath |
|
254 |
|
255 def user_rcpath_win32(): |
225 def user_rcpath_win32(): |
256 '''return os-specific hgrc search path to the user dir''' |
226 '''return os-specific hgrc search path to the user dir''' |
257 userdir = os.path.expanduser('~') |
227 userdir = os.path.expanduser('~') |
258 return [os.path.join(userdir, 'mercurial.ini'), |
228 return [os.path.join(userdir, 'mercurial.ini'), |
259 os.path.join(userdir, '.hgrc')] |
229 os.path.join(userdir, '.hgrc')] |