diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -72,8 +72,10 @@ class _shlexpy3proxy: return _encodeornone(self._l.get_token()) @property - def infile(self): - return self._l.infile or b'' + def infile(self) -> bytes: + if self._l.infile is not None: + return encoding.strtolocal(self._l.infile) + return b'' @property def lineno(self) -> int: @@ -82,7 +84,7 @@ class _shlexpy3proxy: def shlexer( data=None, - filepath: Optional[str] = None, + filepath: Optional[bytes] = None, wordchars: Optional[bytes] = None, whitespace: Optional[bytes] = None, ): @@ -94,7 +96,8 @@ def shlexer( b'shlexer only accepts data or filepath, not both' ) data = data.decode('latin1') - l = shlex.shlex(data, infile=filepath, posix=True) + infile = encoding.strfromlocal(filepath) if filepath is not None else None + l = shlex.shlex(data, infile=infile, posix=True) if whitespace is not None: l.whitespace_split = True l.whitespace += whitespace.decode('latin1') diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py --- a/hgext/convert/filemap.py +++ b/hgext/convert/filemap.py @@ -76,7 +76,7 @@ class filemapper: rename: MutableMapping[bytes, bytes] targetprefixes: Optional[Set[bytes]] - def __init__(self, ui: "uimod.ui", path=None) -> None: + def __init__(self, ui: "uimod.ui", path: Optional[bytes] = None) -> None: self.ui = ui self.include = {} self.exclude = {} @@ -86,8 +86,7 @@ class filemapper: if self.parse(path): raise error.Abort(_(b'errors in filemap')) - # TODO: cmd==b'source' case breaks if ``path``is str - def parse(self, path) -> int: + def parse(self, path: Optional[bytes]) -> int: errs = 0 def check(name: bytes, mapping, listname: bytes): @@ -218,7 +217,9 @@ class filemapper: class filemap_source(common.converter_source): - def __init__(self, ui: "uimod.ui", baseconverter, filemap) -> None: + def __init__( + self, ui: "uimod.ui", baseconverter, filemap: Optional[bytes] + ) -> None: super(filemap_source, self).__init__(ui, baseconverter.repotype) self.base = baseconverter self.filemapper = filemapper(ui, filemap)