[PATCH 07 of 11] revlog: fix many file handle opens to explicitly use bytes mode

Yuya Nishihara yuya at tcha.org
Thu Mar 30 11:08:56 EDT 2017


On Wed, 29 Mar 2017 19:24:11 -0700, Gregory Szorc wrote:
> On Mon, Mar 27, 2017 at 6:54 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> > On Sun, 26 Mar 2017 18:36:41 -0400, Augie Fackler wrote:
> > > # HG changeset patch
> > > # User Augie Fackler <raf at durin42.com>
> > > # Date 1490567324 14400
> > > #      Sun Mar 26 18:28:44 2017 -0400
> > > # Node ID e7fe3ab60132647a9c3b86b2960b385e61b9dcf0
> > > # Parent  48144fe2d912b7d9fc300955d0c881aceead6930
> > > revlog: fix many file handle opens to explicitly use bytes mode
> > >
> > > This broke on Python 3, but we've probably been getting lucky that
> > > this hasn't caused EOL corruption on Windows or something for
> > > years. :(
> > >
> > > diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> > > --- a/mercurial/revlog.py
> > > +++ b/mercurial/revlog.py
> > > @@ -1467,8 +1467,8 @@ class revlog(object):
> > >
> > >          dfh = None
> > >          if not self._inline:
> > > -            dfh = self.opener(self.datafile, "a+")
> > > -        ifh = self.opener(self.indexfile, "a+",
> > checkambig=self._checkambig)
> > > +            dfh = self.opener(self.datafile, "a+b")
> > > +        ifh = self.opener(self.indexfile, "a+b",
> > checkambig=self._checkambig)
> >
> > 'b' shouldn't be needed since vfs adds 'b' unless text=True is explicitly
> > specified.
> >
> 
> That "text" argument always seemed weird to me because all it does is
> reinvent the wheel for the "mode" argument to open(). I'd prefer we
> deprecate the argument and use explicit mode values so the I/O code more
> closely aligns with what Python does. Principal of least surprise.

Perhaps it exists because 'b' is too subtle and unix programmers would easily
miss it. I'd rather get rid of the text mode at all for Py3 compatibility.
Optionally we can make vfs raise exception if 'b' isn't explicitly specified.


More information about the Mercurial-devel mailing list