Submitter | Augie Fackler |
---|---|
Date | March 12, 2017, 9:51 p.m. |
Message ID | <4455c6cdbf1e9cd524b4.1489355475@augie-macbookair2.roam.corp.google.com> |
Download | mbox | patch |
Permalink | /patch/19239/ |
State | Changes Requested |
Headers | show |
Comments
On Sun, 12 Mar 2017 17:51:15 -0400, Augie Fackler wrote: > # HG changeset patch > # User Augie Fackler <augie@google.com> > # Date 1489303712 14400 > # Sun Mar 12 03:28:32 2017 -0400 > # Node ID 4455c6cdbf1e9cd524b43c69ecefef819e0b4e30 > # Parent 7dd2f51f38ac224cec522d093ff6f805beb0dd3e > encoding: make encoding.encoding be a native str and add encodingb > > It turns out we need the encoding name both ways. Ugh. > > diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py > --- a/mercurial/debugcommands.py > +++ b/mercurial/debugcommands.py > @@ -965,7 +965,7 @@ def debuginstall(ui, **opts): > fm.startitem() > > # encoding > - fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) > + fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encodingb()) We have much more uses of encoding.encoding expecting bytes. Better to make encodingu() a function? % grep encoding.encoding **/*.py | grep -v sysstr | wc -l 41
> On Mar 12, 2017, at 15:08, Yuya Nishihara <yuya@tcha.org> wrote: > > On Sun, 12 Mar 2017 17:51:15 -0400, Augie Fackler wrote: >> # HG changeset patch >> # User Augie Fackler <augie@google.com> >> # Date 1489303712 14400 >> # Sun Mar 12 03:28:32 2017 -0400 >> # Node ID 4455c6cdbf1e9cd524b43c69ecefef819e0b4e30 >> # Parent 7dd2f51f38ac224cec522d093ff6f805beb0dd3e >> encoding: make encoding.encoding be a native str and add encodingb >> >> It turns out we need the encoding name both ways. Ugh. >> >> diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py >> --- a/mercurial/debugcommands.py >> +++ b/mercurial/debugcommands.py >> @@ -965,7 +965,7 @@ def debuginstall(ui, **opts): >> fm.startitem() >> >> # encoding >> - fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) >> + fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encodingb()) > > We have much more uses of encoding.encoding expecting bytes. Better to make > encodingu() a function? > > % grep encoding.encoding **/*.py | grep -v sysstr | wc -l > 41 Sure, I'll roll a v3.
> On Mar 12, 2017, at 15:10, Augie Fackler <raf@durin42.com> wrote: > > >> On Mar 12, 2017, at 15:08, Yuya Nishihara <yuya@tcha.org> wrote: >> >> On Sun, 12 Mar 2017 17:51:15 -0400, Augie Fackler wrote: >>> # HG changeset patch >>> # User Augie Fackler <augie@google.com> >>> # Date 1489303712 14400 >>> # Sun Mar 12 03:28:32 2017 -0400 >>> # Node ID 4455c6cdbf1e9cd524b43c69ecefef819e0b4e30 >>> # Parent 7dd2f51f38ac224cec522d093ff6f805beb0dd3e >>> encoding: make encoding.encoding be a native str and add encodingb >>> >>> It turns out we need the encoding name both ways. Ugh. >>> >>> diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py >>> --- a/mercurial/debugcommands.py >>> +++ b/mercurial/debugcommands.py >>> @@ -965,7 +965,7 @@ def debuginstall(ui, **opts): >>> fm.startitem() >>> >>> # encoding >>> - fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) >>> + fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encodingb()) >> >> We have much more uses of encoding.encoding expecting bytes. Better to make >> encodingu() a function? >> >> % grep encoding.encoding **/*.py | grep -v sysstr | wc -l >> 41 > > Sure, I'll roll a v3. I decided to drop the encoding{b,u} idea for now, but maybe we should do it since a lot of places use sysstr()? Anyway, v3 coming shortly.
On Sun, 12 Mar 2017 15:42:06 -0700, Augie Fackler wrote: > > On Mar 12, 2017, at 15:10, Augie Fackler <raf@durin42.com> wrote: > >> On Mar 12, 2017, at 15:08, Yuya Nishihara <yuya@tcha.org> wrote: > >> On Sun, 12 Mar 2017 17:51:15 -0400, Augie Fackler wrote: > >>> # HG changeset patch > >>> # User Augie Fackler <augie@google.com> > >>> # Date 1489303712 14400 > >>> # Sun Mar 12 03:28:32 2017 -0400 > >>> # Node ID 4455c6cdbf1e9cd524b43c69ecefef819e0b4e30 > >>> # Parent 7dd2f51f38ac224cec522d093ff6f805beb0dd3e > >>> encoding: make encoding.encoding be a native str and add encodingb > >>> > >>> It turns out we need the encoding name both ways. Ugh. > >>> > >>> diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py > >>> --- a/mercurial/debugcommands.py > >>> +++ b/mercurial/debugcommands.py > >>> @@ -965,7 +965,7 @@ def debuginstall(ui, **opts): > >>> fm.startitem() > >>> > >>> # encoding > >>> - fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) > >>> + fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encodingb()) > >> > >> We have much more uses of encoding.encoding expecting bytes. Better to make > >> encodingu() a function? > >> > >> % grep encoding.encoding **/*.py | grep -v sysstr | wc -l > >> 41 > > > > Sure, I'll roll a v3. > > I decided to drop the encoding{b,u} idea for now, but maybe we should do it since a lot of places use sysstr()? Anyway, v3 coming shortly. Yeah, we'll need a handful of encoding helpers so people can stop thinking about unicodes.
Patch
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -965,7 +965,7 @@ def debuginstall(ui, **opts): fm.startitem() # encoding - fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) + fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encodingb()) err = None try: encoding.fromlocal("test") diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -100,6 +100,15 @@ except locale.Error: encodingmode = environ.get("HGENCODINGMODE", "strict") fallbackencoding = 'ISO-8859-1' +if pycompat.ispy3: + def encodingb(): + return encoding.encode('ascii') + # TODO: are all encodings sure to be ascii names? + encoding = encoding.decode('ascii') +else: + def encodingb(): + return encoding + class localstr(str): '''This class allows strings that are unmodified to be round-tripped to the local encoding and back''' diff --git a/tests/test-check-code.t b/tests/test-check-code.t --- a/tests/test-check-code.t +++ b/tests/test-check-code.t @@ -22,7 +22,7 @@ New errors are not allowed. Warnings are mercurial/encoding.py:61: > for k, v in os.environ.items()) use encoding.environ instead (py3) - mercurial/encoding.py:203: + mercurial/encoding.py:212: > for k, v in os.environ.items()) use encoding.environ instead (py3) Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)