py3: accept both unicode and byte strings as filename carried by IOError
authorYuya Nishihara <yuya@tcha.org>
Sat, 03 Mar 2018 15:41:12 -0500
changeset 36687 e1c6c1f9855d
parent 36686 214f61abd865
child 36688 dc11f257ad1d
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.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sat Mar 03 15:33:52 2018 -0500
+++ b/mercurial/scmutil.py	Sat Mar 03 15:41:12 2018 -0500
@@ -163,12 +163,12 @@
         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 @@
             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 @@
         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: