Re: [PATCH] py3: use bytes IO to write sample hgrc

2017-08-04 Thread Augie Fackler
On Thu, Aug 03, 2017 at 01:13:20AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara 
> # Date 1501688702 -32400
> #  Thu Aug 03 00:45:02 2017 +0900
> # Node ID 52bbc0a0dc7a3e946ed16bf547929252e95603d4
> # Parent  6a620fd39e4cac88e1a46f18aa7b852639e3b729
> py3: use bytes IO to write sample hgrc

queued, thanks
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH] py3: use bytes IO to write sample hgrc

2017-08-02 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# Date 1501688702 -32400
#  Thu Aug 03 00:45:02 2017 +0900
# Node ID 52bbc0a0dc7a3e946ed16bf547929252e95603d4
# Parent  6a620fd39e4cac88e1a46f18aa7b852639e3b729
py3: use bytes IO to write sample hgrc

Unicode sucks. Stop using Text IO and manually convert line endings.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1644,8 +1644,8 @@ def config(ui, repo, *values, **opts):
 samplehgrc = uimod.samplehgrcs['user']
 
 f = paths[0]
-fp = open(f, "w")
-fp.write(samplehgrc)
+fp = open(f, "wb")
+fp.write(util.tonativeeol(samplehgrc))
 fp.close()
 
 editor = ui.geteditor()
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -641,11 +641,11 @@ def clone(ui, peeropts, source, dest=Non
 destrepo = destpeer.local()
 if destrepo:
 template = uimod.samplehgrcs['cloned']
-fp = destrepo.vfs("hgrc", "w", text=True)
+fp = destrepo.vfs("hgrc", "wb")
 u = util.url(abspath)
 u.passwd = None
-defaulturl = str(u)
-fp.write(template % defaulturl)
+defaulturl = bytes(u)
+fp.write(util.tonativeeol(template % defaulturl))
 fp.close()
 
 destrepo.ui.setconfig('paths', 'default', defaulturl, 'clone')
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -60,7 +60,7 @@ git = 1
 
 samplehgrcs = {
 'user':
-"""# example user config (see 'hg help config' for more info)
+b"""# example user config (see 'hg help config' for more info)
 [ui]
 # name and email, e.g.
 # username = Jane Doe 
@@ -82,7 +82,7 @@ username =
 """,
 
 'cloned':
-"""# example repository config (see 'hg help config' for more info)
+b"""# example repository config (see 'hg help config' for more info)
 [paths]
 default = %s
 
@@ -99,7 +99,7 @@ default = %s
 """,
 
 'local':
-"""# example repository config (see 'hg help config' for more info)
+b"""# example repository config (see 'hg help config' for more info)
 [paths]
 # path aliases to other clones of this repo in URLs or filesystem paths
 # (see 'hg help config.paths' for more info)
@@ -115,7 +115,7 @@ default = %s
 """,
 
 'global':
-"""# example system-wide hg config (see 'hg help config' for more info)
+b"""# example system-wide hg config (see 'hg help config' for more info)
 
 [ui]
 # uncomment to disable color in command output
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel