mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 14:58:03 +03:00
dynamicconfig: read file as bytes
Summary: Somehow reading the file with `open("r")` will try to decode it as ascii, but that file may contain utf-8 characters, so open it as bytes, and then decode it. Reviewed By: DurhamG Differential Revision: D22105188 fbshipit-source-id: 0cfbd8c5417b637dd76391f86226e24ee663baf7
This commit is contained in:
parent
6700fa7d08
commit
67db664778
@ -558,16 +558,16 @@ def loaddynamicconfig(ui, path):
|
|||||||
if ui.configbool("configs", "loaddynamicconfig"):
|
if ui.configbool("configs", "loaddynamicconfig"):
|
||||||
sharedpathfile = os.path.join(path, "sharedpath")
|
sharedpathfile = os.path.join(path, "sharedpath")
|
||||||
if os.path.exists(sharedpathfile):
|
if os.path.exists(sharedpathfile):
|
||||||
with open(sharedpathfile, "r") as f:
|
with open(sharedpathfile, "rb") as f:
|
||||||
path = f.read()
|
path = pycompat.decodeutf8(f.read())
|
||||||
|
|
||||||
hgrcdyn = os.path.join(path, "hgrc.dynamic")
|
hgrcdyn = os.path.join(path, "hgrc.dynamic")
|
||||||
|
|
||||||
# Check the version of the existing generated config. If it doesn't
|
# Check the version of the existing generated config. If it doesn't
|
||||||
# match the current version, regenerate it immediately.
|
# match the current version, regenerate it immediately.
|
||||||
try:
|
try:
|
||||||
with open(hgrcdyn, "r") as f:
|
with open(hgrcdyn, "rb") as f:
|
||||||
content = f.read()
|
content = pycompat.decodeutf8(f.read())
|
||||||
matches = re.search("^# version=(.*)$", content, re.MULTILINE)
|
matches = re.search("^# version=(.*)$", content, re.MULTILINE)
|
||||||
version = matches.group(1) if matches else None
|
version = matches.group(1) if matches else None
|
||||||
except IOError:
|
except IOError:
|
||||||
|
25
eden/scm/tests/test-dynamicconfig-unicode.t
Normal file
25
eden/scm/tests/test-dynamicconfig-unicode.t
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#chg-compatible
|
||||||
|
|
||||||
|
$ configure modern
|
||||||
|
|
||||||
|
$ setconfig configs.loaddynamicconfig=True
|
||||||
|
$ export HG_TEST_DYNAMICCONFIG="$TESTTMP/test_hgrc"
|
||||||
|
$ cat > test_hgrc <<EOF
|
||||||
|
> [section]
|
||||||
|
> key=✓
|
||||||
|
> EOF
|
||||||
|
|
||||||
|
$ hg init client
|
||||||
|
$ cd client
|
||||||
|
|
||||||
|
Verify it can be manually generated
|
||||||
|
|
||||||
|
$ hg debugdynamicconfig
|
||||||
|
$ cat .hg/hgrc.dynamic
|
||||||
|
# version=4.4.2* (glob)
|
||||||
|
# Generated by `hg debugdynamicconfig` - DO NOT MODIFY
|
||||||
|
[section]
|
||||||
|
key=✓
|
||||||
|
|
||||||
|
$ hg config section.key
|
||||||
|
✓
|
Loading…
Reference in New Issue
Block a user