[PATCH 08 of 10] py3: implement __bytes__ for committablectx

Yuya Nishihara yuya at tcha.org
Thu Jun 1 11:20:09 EDT 2017


On Thu, 01 Jun 2017 03:17:04 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1496264118 -19800
> #      Thu Jun 01 02:25:18 2017 +0530
> # Node ID a5498ec51c800ca99be644710b13b0e78a4997b6
> # Parent  25320a995bedaaabc4e7a7f40651d07a9bfb4803
> py3: implement __bytes__ for committablectx
> 
> Before this method, calling bytes on workingctx or memctx calls
> basectx.__bytes__ since the magic method was not defined for this class. When it
> calls the method from basectx class, it returns TypeError because None is passed
> into it.
> 
> After this commit `hg update -C` works on Python 3 if eol is not enabled.
> 
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -47,7 +47,7 @@
>          last, lrev = bin(last), int(lrev)
>          filteredhash = None
>          if len(cachekey) > 2:
> -            filteredhash = bin(cachekey[2])
> +            filteredhash = bin(cachekey[2:3][0])
>          partial = branchcache(tipnode=last, tiprev=lrev,
>                                filteredhash=filteredhash)
>          if not partial.validfor(repo):
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -1408,6 +1408,9 @@
>      def __str__(self):
>          return str(self._parents[0]) + r"+"
>  
> +    def __bytes__(self):
> +        return bytes(self._parents[0]) + "+"

Just an idea. I'm thinking of adding (pycompat|encoding).forwardtobytes(self)
and do:

  __str__ = forwardtobytes

> diff --git a/mercurial/hook.py b/mercurial/hook.py
> --- a/mercurial/hook.py
> +++ b/mercurial/hook.py
> @@ -97,7 +97,7 @@
>                           (hname, exc.args[0]))
>          else:
>              ui.warn(_('error: %s hook raised an exception: '
> -                           '%s\n') % (hname, exc))
> +                           '%s\n') % (hname, pycompat.sysbytes(str(exc))))

encoding.strtolocal(str(exc)) should be better. exc may be IOError which
could contain a valid non-ascii unicode on Python 3.


More information about the Mercurial-devel mailing list