Patchwork D2648: py3: use pycompat.bytestr instead of str

login
register
mail settings
Submitter phabricator
Date March 4, 2018, 5:29 p.m.
Message ID <differential-rev-PHID-DREV-ffbdq5ylnmlna4vevsqd-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28942/
State Superseded
Headers show

Comments

phabricator - March 4, 2018, 5:29 p.m.
pulkit created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2648

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py
  mercurial/context.py
  mercurial/debugcommands.py
  mercurial/dispatch.py
  mercurial/revlog.py
  mercurial/subrepo.py
  mercurial/wireproto.py

CHANGE DETAILS




To: pulkit, indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - March 4, 2018, 6:02 p.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> context.py:436
>              if not pycompat.ispy3 and isinstance(changeid, long):
> -                changeid = str(changeid)
> +                changeid = pycompat.bytestr(changeid)
>              if changeid == 'null':

Nit: could be %d.

> dispatch.py:993
>          if not isinstance(testedwith, (bytes, str)):
> -            testedwith = '.'.join([str(c) for c in testedwith])
> +            testedwith = '.'.join([pycompat.bytestr(c) for c in testedwith])
>          warning = (_('** Unknown exception encountered with '

Better to use forcebytestr() here because we are blaming a bad extension
which may put anything into `testedwith`.

> revlog.py:2470
>                      if dp != nullrev:
> -                        cachedelta = (dp, str(self._chunk(rev)))
> +                        cachedelta = (dp, pycompat.bytestr(self._chunk(rev)))
>  

Perhaps bytes() is more appropriate here. I think this is just making a sort of bytes
immutable.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2648

To: pulkit, indygreg, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -1043,7 +1043,7 @@ 
                         util.stderr.write("(%s)\n" % exc.hint)
                     return pushres(0, output.getvalue() if output else '')
                 except error.PushRaced:
-                    return pusherr(str(exc),
+                    return pusherr(pycompat.bytestr(exc),
                                    output.getvalue() if output else '')
 
             bundler = bundle2.bundle20(repo.ui)
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1123,7 +1123,7 @@ 
         doc = xml.dom.minidom.parseString(output)
         paths = []
         for e in doc.getElementsByTagName('entry'):
-            kind = str(e.getAttribute('kind'))
+            kind = pycompat.bytestr(e.getAttribute('kind'))
             if kind != 'file':
                 continue
             name = ''.join(c.data for c
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2467,7 +2467,7 @@ 
                 if populatecachedelta:
                     dp = self.deltaparent(rev)
                     if dp != nullrev:
-                        cachedelta = (dp, str(self._chunk(rev)))
+                        cachedelta = (dp, pycompat.bytestr(self._chunk(rev)))
 
                 if not cachedelta:
                     rawtext = self.revision(rev, raw=True)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -990,7 +990,7 @@ 
     if worst[0] is not None:
         name, testedwith, report = worst
         if not isinstance(testedwith, (bytes, str)):
-            testedwith = '.'.join([str(c) for c in testedwith])
+            testedwith = '.'.join([pycompat.bytestr(c) for c in testedwith])
         warning = (_('** Unknown exception encountered with '
                      'possibly-broken third-party extension %s\n'
                      '** which supports versions %s of Mercurial.\n'
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1811,7 +1811,7 @@ 
     if keyinfo:
         key, old, new = keyinfo
         r = target.pushkey(namespace, key, old, new)
-        ui.status(str(r) + '\n')
+        ui.status(pycompat.bytestr(r) + '\n')
         return not r
     else:
         for k, v in sorted(target.listkeys(namespace).iteritems()):
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -433,7 +433,7 @@ 
                 self._rev = changeid
                 return
             if not pycompat.ispy3 and isinstance(changeid, long):
-                changeid = str(changeid)
+                changeid = pycompat.bytestr(changeid)
             if changeid == 'null':
                 self._node = nullid
                 self._rev = nullrev
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1197,7 +1197,7 @@ 
         bcompression, cgversion, params = exchange.parsebundlespec(
                 repo, bundletype, strict=False)
     except error.UnsupportedBundleSpecification as e:
-        raise error.Abort(str(e),
+        raise error.Abort(pycompat.bytestr(e),
                           hint=_("see 'hg help bundlespec' for supported "
                                  "values for --type"))
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -362,7 +362,7 @@ 
                     ui.debug(fp.getvalue())
                     patch.internalpatch(ui, repo, fp, 1, eolmode=None)
                 except error.PatchError as err:
-                    raise error.Abort(str(err))
+                    raise error.Abort(pycompat.bytestr(err))
             del fp
 
             # 4. We prepared working directory according to filtered
@@ -1432,7 +1432,7 @@ 
                             files=files, eolmode=None, similarity=sim / 100.0)
             except error.PatchError as e:
                 if not partial:
-                    raise error.Abort(str(e))
+                    raise error.Abort(pycompat.bytestr(e))
                 if partial:
                     rejects = True
 
@@ -3043,7 +3043,7 @@ 
             try:
                 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None)
             except error.PatchError as err:
-                raise error.Abort(str(err))
+                raise error.Abort(pycompat.bytestr(err))
         del fp
     else:
         for f in actions['revert'][0]: