changeset 43395:2b8be670dcb6 stable

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 02 Nov 2019 14:26:06 -0700
parents d359dfc15aca
children 2b5aab5e9e36
files hgext/fsmonitor/__init__.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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: