Patchwork [2,of,2] py3: accept both unicode and byte strings as filename carried by IOError

login
register
mail settings
Submitter Yuya Nishihara
Date March 3, 2018, 8:52 p.m.
Message ID <1880fc2cbfc27c8b2fb0.1520110361@mimosa>
Download mbox | patch
Permalink /patch/28842/
State Accepted
Headers show

Comments

Yuya Nishihara - March 3, 2018, 8:52 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1520109672 18000
#      Sat Mar 03 15:41:12 2018 -0500
# Node ID 1880fc2cbfc27c8b2fb0073f8aa9c0fa54937969
# Parent  8e3fd6529bad7f4d524f160761c766a7f5267a0f
py3: accept both unicode and byte strings as filename carried by IOError

Follows up 77f98867538f. We could assume there's no bytes filename in our
codebase, but it's probably better to not raise UnicodeError because of
a unicode filename.
Augie Fackler - March 3, 2018, 9:23 p.m.
On Sat, Mar 03, 2018 at 03:52:41PM -0500, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1520109672 18000
> #      Sat Mar 03 15:41:12 2018 -0500
> # Node ID 1880fc2cbfc27c8b2fb0073f8aa9c0fa54937969
> # Parent  8e3fd6529bad7f4d524f160761c766a7f5267a0f
> py3: accept both unicode and byte strings as filename carried by IOError

queued, thanks

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -163,12 +163,12 @@  def callcatch(ui, func):
         else:
             reason = _('lock held by %r') % inst.locker
         ui.warn(_("abort: %s: %s\n")
-                % (inst.desc or encoding.strtolocal(inst.filename), reason))
+                % (inst.desc or util.forcebytestr(inst.filename), reason))
         if not inst.locker:
             ui.warn(_("(lock might be very busy)\n"))
     except error.LockUnavailable as inst:
         ui.warn(_("abort: could not lock %s: %s\n") %
-                (inst.desc or encoding.strtolocal(inst.filename),
+                (inst.desc or util.forcebytestr(inst.filename),
                  encoding.strtolocal(inst.strerror)))
     except error.OutOfBandError as inst:
         if inst.args:
@@ -234,7 +234,7 @@  def callcatch(ui, func):
             if getattr(inst, "filename", None):
                 ui.warn(_("abort: %s: %s\n") % (
                     encoding.strtolocal(inst.strerror),
-                    encoding.strtolocal(inst.filename)))
+                    util.forcebytestr(inst.filename)))
             else:
                 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
         else:
@@ -243,7 +243,7 @@  def callcatch(ui, func):
         if getattr(inst, "filename", None) is not None:
             ui.warn(_("abort: %s: '%s'\n") % (
                 encoding.strtolocal(inst.strerror),
-                encoding.strtolocal(inst.filename)))
+                util.forcebytestr(inst.filename)))
         else:
             ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
     except MemoryError: