##// END OF EJS Templates
windows: continue looking at `%HOME%` for user config files with py3.8+...
Matt Harbison -
r46709:224af780 default
parent child Browse files
Show More
@@ -68,7 +68,7 b' def systemrcpath():'
68 68
69 69 def userrcpath():
70 70 '''return os-specific hgrc search path to the user dir'''
71 home = os.path.expanduser(b'~')
71 home = _legacy_expanduser(b'~')
72 72 path = [os.path.join(home, b'mercurial.ini'), os.path.join(home, b'.hgrc')]
73 73 userprofile = encoding.environ.get(b'USERPROFILE')
74 74 if userprofile and userprofile != home:
@@ -77,5 +77,37 b' def userrcpath():'
77 77 return path
78 78
79 79
80 def _legacy_expanduser(path):
81 """Expand ~ and ~user constructs in the pre 3.8 style"""
82
83 # Python 3.8+ changed the expansion of '~' from HOME to USERPROFILE. See
84 # https://bugs.python.org/issue36264. It also seems to capitalize the drive
85 # letter, as though it was processed through os.path.realpath().
86 if not path.startswith(b'~'):
87 return path
88
89 i, n = 1, len(path)
90 while i < n and path[i] not in b'\\/':
91 i += 1
92
93 if b'HOME' in encoding.environ:
94 userhome = encoding.environ[b'HOME']
95 elif b'USERPROFILE' in encoding.environ:
96 userhome = encoding.environ[b'USERPROFILE']
97 elif b'HOMEPATH' not in encoding.environ:
98 return path
99 else:
100 try:
101 drive = encoding.environ[b'HOMEDRIVE']
102 except KeyError:
103 drive = b''
104 userhome = os.path.join(drive, encoding.environ[b'HOMEPATH'])
105
106 if i != 1: # ~user
107 userhome = os.path.join(os.path.dirname(userhome), path[1:i])
108
109 return userhome + path[i:]
110
111
80 112 def termsize(ui):
81 113 return win32.termsize()
General Comments 0
You need to be logged in to leave comments. Login now