##// END OF EJS Templates
branchmap: explicitly warm+write all subsets of the branchmap caches...
branchmap: explicitly warm+write all subsets of the branchmap caches 'full' claims it will warm all of the caches that are known about, but this was not the case - it did not actually warm the branchmap caches for subsets that we haven't requested, or for subsets that are still considered "valid". By explicitly writing them to disk, we can force the subsets for ex: "served" to be written ("immutable" and "base"), making it cheaper to calculate "served" the next time it needs to be updated. Differential Revision: https://phab.mercurial-scm.org/D6710

File last commit:

r42874:f3c594dd default
r42940:cdf0e952 default
Show More
watchmanclient.py
111 lines | 3.5 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
from . import pywatchman
class Unavailable(Exception):
def __init__(self, msg, warn=True, invalidate=False):
self.msg = msg
self.warn = warn
if self.msg == 'timed out waiting for response':
self.warn = False
self.invalidate = invalidate
def __str__(self):
if self.warn:
return 'warning: Watchman unavailable: %s' % self.msg
else:
return 'Watchman unavailable: %s' % self.msg
class WatchmanNoRoot(Unavailable):
def __init__(self, root, msg):
self.root = root
super(WatchmanNoRoot, self).__init__(msg)
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:
err = "couldn't get user"
warn = True
Augie Fackler
fsmonitor: refactor watchmanclient.client to accept ui and repo path...
r42877 if self._user in ui.configlist('fsmonitor', 'blacklistusers'):
Martijn Pieters
fsmonitor: new experimental extension...
r28433 err = 'user %s in blacklist' % self._user
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):
result = self.command('clock')
if not util.safehasattr(result, 'clock'):
raise Unavailable('clock result is missing clock value',
invalidate=True)
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
Boris Feld
watchman: add the possibility to set the exact watchman binary location...
r42134 watchman_exe = self._ui.configpath('fsmonitor', '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,
watchman_exe=watchman_exe)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 return self._watchmanclient.query(*watchmanargs)
except pywatchman.CommandError as ex:
zphricz
fsmonitor: fix exception message scraping...
r30649 if '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
self._command('watch')
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