##// END OF EJS Templates
fsmonitor: refresh pywatchman with upstream...
fsmonitor: refresh pywatchman with upstream This commit vendors pywatchman commit 259dc66dc9591f9b7ce76d0275bb1065f390c9b1 from upstream without modifications. The previously vendored pywatchman from changeset 16f4b341288d was from Git commit c77452. This commit effectively undoes the following Mercurial changesets: * dd35abc409ee fsmonitor: correct an error message * b1f62cd39b5c fsmonitor: layer on another hack in bser.c for os.stat() compat (issue5811) * c31ce080eb75 py3: convert arguments, cwd and env to native strings when spawning subprocess * 876494fd967d cleanup: delete lots of unused local variables * 57264906a996 watchman: add the possibility to set the exact watchman binary location The newly-vendored code has support for specifying the binary location, so 57264906a996 does not need applied. But we do need to modify our code to specify a proper argument name. 876494fd967d is not important, so it will be ignored. c31ce080eb75 globally changed the code base to always pass str to subprocess. But pywatchman's code is Python 3 clean, so we don't need to do this. This leaves dd35abc409ee and b1f62cd39b5c, which will be re-applied in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D7201

File last commit:

r43703:6469c23a stable
r43703:6469c23a stable
Show More
watchmanclient.py
119 lines | 3.6 KiB | text/x-python | PythonLexer
Martijn Pieters
fsmonitor: new experimental extension...
r28433 # watchmanclient.py - Watchman client for the fsmonitor extension
#
# Copyright 2013-2016 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import getpass
from mercurial import util
Gregory Szorc
fsmonitor: refresh pywatchman with upstream...
r43703 from mercurial.utils import procutil
Martijn Pieters
fsmonitor: new experimental extension...
r28433
from . import pywatchman
Augie Fackler
formatting: blacken the codebase...
r43346
Martijn Pieters
fsmonitor: new experimental extension...
r28433 class Unavailable(Exception):
def __init__(self, msg, warn=True, invalidate=False):
self.msg = msg
self.warn = warn
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if self.msg == b'timed out waiting for response':
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.warn = False
self.invalidate = invalidate
def __str__(self):
if self.warn:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'warning: Watchman unavailable: %s' % self.msg
Martijn Pieters
fsmonitor: new experimental extension...
r28433 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'Watchman unavailable: %s' % self.msg
Martijn Pieters
fsmonitor: new experimental extension...
r28433
Augie Fackler
formatting: blacken the codebase...
r43346
Martijn Pieters
fsmonitor: new experimental extension...
r28433 class WatchmanNoRoot(Unavailable):
def __init__(self, root, msg):
self.root = root
super(WatchmanNoRoot, self).__init__(msg)
Augie Fackler
formatting: blacken the codebase...
r43346
Martijn Pieters
fsmonitor: new experimental extension...
r28433 class client(object):
Augie Fackler
fsmonitor: refactor watchmanclient.client to accept ui and repo path...
r42877 def __init__(self, ui, root, timeout=1.0):
Martijn Pieters
fsmonitor: new experimental extension...
r28433 err = None
if not self._user:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 err = b"couldn't get user"
Martijn Pieters
fsmonitor: new experimental extension...
r28433 warn = True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if self._user in ui.configlist(b'fsmonitor', b'blacklistusers'):
err = b'user %s in blacklist' % self._user
Martijn Pieters
fsmonitor: new experimental extension...
r28433 warn = False
if err:
raise Unavailable(err, warn)
self._timeout = timeout
self._watchmanclient = None
Augie Fackler
fsmonitor: refactor watchmanclient.client to accept ui and repo path...
r42877 self._root = root
self._ui = ui
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self._firsttime = True
def settimeout(self, timeout):
self._timeout = timeout
if self._watchmanclient is not None:
self._watchmanclient.setTimeout(timeout)
def getcurrentclock(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 result = self.command(b'clock')
Martin von Zweigbergk
py3: delete b'' prefix from safehasattr arguments...
r43385 if not util.safehasattr(result, 'clock'):
Augie Fackler
formatting: blacken the codebase...
r43346 raise Unavailable(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'clock result is missing clock value', invalidate=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martijn Pieters
fsmonitor: new experimental extension...
r28433 return result.clock
def clearconnection(self):
self._watchmanclient = None
def available(self):
return self._watchmanclient is not None or self._firsttime
@util.propertycache
def _user(self):
try:
return getpass.getuser()
except KeyError:
# couldn't figure out our user
return None
def _command(self, *args):
watchmanargs = (args[0], self._root) + args[1:]
try:
if self._watchmanclient is None:
self._firsttime = False
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 watchman_exe = self._ui.configpath(
b'fsmonitor', b'watchman_exe'
)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self._watchmanclient = pywatchman.client(
timeout=self._timeout,
Boris Feld
watchman: add the possibility to set the exact watchman binary location...
r42134 useImmutableBser=True,
Gregory Szorc
fsmonitor: refresh pywatchman with upstream...
r43703 binpath=procutil.tonativestr(watchman_exe),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martijn Pieters
fsmonitor: new experimental extension...
r28433 return self._watchmanclient.query(*watchmanargs)
except pywatchman.CommandError as ex:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'unable to resolve root' in ex.msg:
Martijn Pieters
fsmonitor: new experimental extension...
r28433 raise WatchmanNoRoot(self._root, ex.msg)
raise Unavailable(ex.msg)
except pywatchman.WatchmanError as ex:
raise Unavailable(str(ex))
def command(self, *args):
try:
try:
return self._command(*args)
except WatchmanNoRoot:
# this 'watch' command can also raise a WatchmanNoRoot if
# watchman refuses to accept this root
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self._command(b'watch')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 return self._command(*args)
except Unavailable:
# this is in an outer scope to catch Unavailable form any of the
# above _command calls
self._watchmanclient = None
raise