Patchwork D2269: py3: use pycompat.bytestr instead of str for converting errors to bytes

login
register
mail settings
Submitter phabricator
Date Feb. 14, 2018, 12:36 p.m.
Message ID <differential-rev-PHID-DREV-t5hop5bwipsxnlhdonxg-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27905/
State Superseded
Headers show

Comments

phabricator - Feb. 14, 2018, 12:36 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/transplant.py
  mercurial/patch.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 14, 2018, 1:32 p.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> transplant.py:314
>                  self.log(user, date, message, p1, p2, merge=merge)
> -                self.ui.write(str(inst) + '\n')
> +                self.ui.write(pycompat.bytestr(inst) + '\n')
>                  raise TransplantError(_('fix up the working directory and run '

Use `util.forcebytestr()` to stringify an exception object of unknown encoding.

> patch.py:1462
>                  raise PatchError(_('could not decode "%s" binary patch: %s')
> -                                 % (self._fname, str(e)))
> +                                 % (self._fname, pycompat.bytestr(e)))
>              line = getline(lr, self.hunk)

Here `bytestr()` is probably fine, but could be `forcebytestr()`, too.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1459,7 +1459,7 @@ 
                 dec.append(util.b85decode(line[1:])[:l])
             except ValueError as e:
                 raise PatchError(_('could not decode "%s" binary patch: %s')
-                                 % (self._fname, str(e)))
+                                 % (self._fname, pycompat.bytestr(e)))
             line = getline(lr, self.hunk)
         text = zlib.decompress(''.join(dec))
         if len(text) != size:
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -311,7 +311,7 @@ 
                 p1 = repo.dirstate.p1()
                 p2 = node
                 self.log(user, date, message, p1, p2, merge=merge)
-                self.ui.write(str(inst) + '\n')
+                self.ui.write(pycompat.bytestr(inst) + '\n')
                 raise TransplantError(_('fix up the working directory and run '
                                         'hg transplant --continue'))
         else: