fsmonitor: normalize Watchman paths to bytes stable
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 02 Nov 2019 14:26:06 -0700
branchstable
changeset 43395 2b8be670dcb6
parent 43394 d359dfc15aca
child 43396 2b5aab5e9e36
fsmonitor: normalize Watchman paths to bytes Otherwise it will be a str on Python 3 and operations below which operate in the bytes domain will fail. Differential Revision: https://phab.mercurial-scm.org/D7211
hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py	Sat Nov 02 14:17:48 2019 -0700
+++ b/hgext/fsmonitor/__init__.py	Sat Nov 02 14:26:06 2019 -0700
@@ -407,8 +407,15 @@
     # for name case changes.
     for entry in result[b'files']:
         fname = entry[b'name']
+
+        # Watchman always give us a str. Normalize to bytes on Python 3
+        # using Watchman's encoding, if needed.
+        if not isinstance(fname, bytes):
+            fname = fname.encode(_watchmanencoding)
+
         if _fixencoding:
             fname = _watchmantofsencoding(fname)
+
         if switch_slashes:
             fname = fname.replace(b'\\', b'/')
         if normalize: