[PATCH 2 of 2] Add 'My Documents\Mercurial\Mercurial.ini' to user rcpath
Steve Borho
steve at borho.org
Mon Mar 9 21:14:39 CDT 2009
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1236471259 21600
# Node ID a7640c3627441ba33c3e8147fecf76ab7db3130e
# Parent 57fa116520f56e5ea21e65489586388787f7b335
Add 'My Documents\Mercurial\Mercurial.ini' to user rcpath
This directory has a higher chance of being writable by a non-
administrative user account. This leaves the previous two search
locations intact: %USERPROFILE%\ and %HOME%\, though the search
order is now consistent across all Windows revisions.
diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt
--- a/doc/hgrc.5.txt
+++ b/doc/hgrc.5.txt
@@ -52,12 +52,13 @@
will be read.
(Unix) $HOME/.hgrc::
+(Windows) %USERPROFILE%\My Documents\Mercurial\Mercurial.ini::
+(Windows) %USERPROFILE%\My Documents\Mercurial\.hgrc::
+(Windows) %USERPROFILE%\Mercurial.ini::
+(Windows) %USERPROFILE%\.hgrc::
(Windows) %HOME%\Mercurial.ini::
(Windows) %HOME%\.hgrc::
-(Windows) %USERPROFILE%\Mercurial.ini::
-(Windows) %USERPROFILE%\.hgrc::
Per-user configuration file(s), for the user running Mercurial.
- On Windows 9x, %HOME% is replaced by %APPDATA%.
Options in these files apply to all Mercurial commands executed
by this user in any directory. Options in thes files override
per-installation and per-system options.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1178,16 +1178,21 @@
def user_rcpath():
'''return os-specific hgrc search path to the user dir'''
+ # %USERPROFILE%\My Documents\Mercurial
try:
path = user_rcpath_win32()
except:
- home = os.path.expanduser('~')
- path = [os.path.join(home, 'mercurial.ini'),
- os.path.join(home, '.hgrc')]
+ path = []
+ # %USERPROFILE%
userprofile = os.environ.get('USERPROFILE')
if userprofile:
- path.append(os.path.join(userprofile, 'mercurial.ini'))
+ path.append(os.path.join(userprofile, 'Mercurial.ini'))
path.append(os.path.join(userprofile, '.hgrc'))
+ # ~/.hgrc (except under cygwin, same as %USERPROFILE%)
+ home = os.path.expanduser('~')
+ if home not in ('~', userprofile):
+ path.append(os.path.join(home, 'Mercurial.ini'))
+ path.append(os.path.join(home, '.hgrc'))
return path
def parse_patch_output(output_line):
diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py
--- a/mercurial/util_win32.py
+++ b/mercurial/util_win32.py
@@ -246,15 +246,13 @@
def user_rcpath_win32():
'''return os-specific hgrc search path to the user dir'''
- userdir = os.path.expanduser('~')
- if sys.getwindowsversion()[3] != 2 and userdir == '~':
- # We are on win < nt: fetch the APPDATA directory location and use
- # the parent directory as the user home dir.
- appdir = shell.SHGetPathFromIDList(
- shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA))
- userdir = os.path.dirname(appdir)
- return [os.path.join(userdir, 'mercurial.ini'),
- os.path.join(userdir, '.hgrc')]
+ # %USERPROFILE%\My Documents\Mercurial\Mercurial.ini
+ docdir = shell.SHGetSpecialFolderPath(None, shellcon.CSIDL_PERSONAL, False)
+ rcpath = []
+ if docdir:
+ rcpath.append(os.path.join(docdir, 'Mercurial', 'Mercurial.ini'))
+ rcpath.append(os.path.join(docdir, 'Mercurial', '.hgrc'))
+ return rcpath
class posixfile_nt(object):
'''file object with posix-like semantics. on windows, normal
More information about the Mercurial-devel
mailing list