py3: fix test-hint.py

Summary:
I can't say that I understand `mdiff.splitnewlines`. In my test it does not
behave the way it reads and I don't know why. The stripping that it's supposed
to do doesn't happen for some reason. It behaves like splitlines.
I believe that rcutil used '\n' for line termination because it was relying on
Python to do the conversion to system line end. I updated to use os.linesep
now that we encode the contents.

Reviewed By: quark-zju

Differential Revision: D20935377

fbshipit-source-id: 0958fdff03950ab0a4b2da02e4333b5438ac5c70
This commit is contained in:
Stefan Filip 2020-04-08 21:58:11 -07:00 committed by Facebook GitHub Bot
parent a3d4ae3d40
commit 25fd8b9034
2 changed files with 9 additions and 8 deletions

View File

@ -106,7 +106,7 @@ def editconfig(path, section, name, value):
path = os.path.realpath(path)
content = ""
try:
content = util.readfile(path)
content = util.readfileutf8(path)
except IOError as ex:
if ex.errno != errno.ENOENT:
raise
@ -119,7 +119,7 @@ def editconfig(path, section, name, value):
if source.startswith(":"):
# line index
index = int(source[1:]) - 1
lines = mdiff.splitnewlines(content)
lines = content.splitlines(True)
# for simple case, we can edit the line in-place
if ( # config line should still exist
index < len(lines)
@ -131,12 +131,14 @@ def editconfig(path, section, name, value):
edited = True
# edit the line
content = "".join(
lines[:index] + ["%s = %s\n" % (name, value)] + lines[index + 1 :]
lines[:index]
+ ["%s = %s%s" % (name, value, os.linesep)]
+ lines[index + 1 :]
)
if not edited:
# append as new config
if content:
content += "\n"
content += "[%s]\n%s = %s\n" % (section, name, value)
content += os.linesep
content += "[%s]%s%s = %s%s" % (section, os.linesep, name, value, os.linesep)
with util.atomictempfile(path) as f:
f.write(content)
f.write(pycompat.encodeutf8(content))

View File

@ -1,5 +1,4 @@
#require py2
#chg-compatible
`#chg-compatible
$ newext showhint << EOF
> from edenscm.mercurial import (