##// 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:

r43347:687b865b default
r43703:6469c23a stable
Show More
state.py
149 lines | 4.7 KiB | text/x-python | PythonLexer
Martijn Pieters
fsmonitor: new experimental extension...
r28433 # state.py - fsmonitor persistent state
#
# 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 errno
import os
import socket
import struct
Yuya Nishihara
py3: move up symbol imports to enforce import-checker rules...
r29205 from mercurial.i18n import _
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 from mercurial import (
pathutil,
util,
)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
_version = 4
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _versionformat = b">I"
Martijn Pieters
fsmonitor: new experimental extension...
r28433
Augie Fackler
formatting: blacken the codebase...
r43346
Martijn Pieters
fsmonitor: new experimental extension...
r28433 class state(object):
def __init__(self, repo):
Durham Goode
fsmonitor: remove use of repo.opener...
r31215 self._vfs = repo.vfs
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self._ui = repo.ui
self._rootdir = pathutil.normasprefix(repo.root)
self._lastclock = None
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.mode = self._ui.config(b'fsmonitor', b'mode')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.walk_on_invalidate = self._ui.configbool(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor', b'walk_on_invalidate'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self.timeout = float(self._ui.config(b'fsmonitor', b'timeout'))
Martijn Pieters
fsmonitor: new experimental extension...
r28433
def get(self):
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 file = self._vfs(b'fsmonitor.state', b'rb')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 except IOError as inst:
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 if inst.errno != errno.ENOENT:
raise
return None, None, None
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat.fromfp(file)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 versionbytes = file.read(4)
if len(versionbytes) < 4:
self._ui.log(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor',
b'fsmonitor: state file only has %d bytes, '
b'nuking state\n' % len(versionbytes),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.invalidate()
return None, None, None
try:
diskversion = struct.unpack(_versionformat, versionbytes)[0]
if diskversion != _version:
# different version, nuke state and start over
self._ui.log(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor',
b'fsmonitor: version switch from %d to '
b'%d, nuking state\n' % (diskversion, _version),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.invalidate()
return None, None, None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 state = file.read().split(b'\0')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 # state = hostname\0clock\0ignorehash\0 + list of files, each
# followed by a \0
Simon Farnsworth
fsmonitor: be robust in the face of bad state...
r30539 if len(state) < 3:
self._ui.log(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor',
b'fsmonitor: state file truncated (expected '
b'3 chunks, found %d), nuking state\n',
Augie Fackler
formatting: blacken the codebase...
r43346 len(state),
)
Simon Farnsworth
fsmonitor: be robust in the face of bad state...
r30539 self.invalidate()
return None, None, None
Martijn Pieters
fsmonitor: new experimental extension...
r28433 diskhostname = state[0]
hostname = socket.gethostname()
if diskhostname != hostname:
# file got moved to a different host
Augie Fackler
formatting: blacken the codebase...
r43346 self._ui.log(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor',
b'fsmonitor: stored hostname "%s" '
b'different from current "%s", nuking state\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (diskhostname, hostname),
)
Martijn Pieters
fsmonitor: new experimental extension...
r28433 self.invalidate()
return None, None, None
clock = state[1]
ignorehash = state[2]
# discard the value after the last \0
notefiles = state[3:-1]
finally:
file.close()
return clock, ignorehash, notefiles
def set(self, clock, ignorehash, notefiles):
if clock is None:
self.invalidate()
return
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 # Read the identity from the file on disk rather than from the open file
# pointer below, because the latter is actually a brand new file.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 identity = util.filestat.frompath(self._vfs.join(b'fsmonitor.state'))
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 if identity != self._identity:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self._ui.debug(
b'skip updating fsmonitor.state: identity mismatch\n'
)
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 return
Martijn Pieters
fsmonitor: new experimental extension...
r28433 try:
Augie Fackler
formatting: blacken the codebase...
r43346 file = self._vfs(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'fsmonitor.state', b'wb', atomictemp=True, checkambig=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martijn Pieters
fsmonitor: new experimental extension...
r28433 except (IOError, OSError):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 self._ui.warn(_(b"warning: unable to write out fsmonitor state\n"))
Martijn Pieters
fsmonitor: new experimental extension...
r28433 return
Simon Farnsworth
fsmonitor: be robust in the face of bad state...
r30539 with file:
Martijn Pieters
fsmonitor: new experimental extension...
r28433 file.write(struct.pack(_versionformat, _version))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 file.write(socket.gethostname() + b'\0')
file.write(clock + b'\0')
file.write(ignorehash + b'\0')
Martijn Pieters
fsmonitor: new experimental extension...
r28433 if notefiles:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 file.write(b'\0'.join(notefiles))
file.write(b'\0')
Martijn Pieters
fsmonitor: new experimental extension...
r28433
def invalidate(self):
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 os.unlink(os.path.join(self._rootdir, b'.hg', b'fsmonitor.state'))
Martijn Pieters
fsmonitor: new experimental extension...
r28433 except OSError as inst:
if inst.errno != errno.ENOENT:
raise
Siddharth Agarwal
fsmonitor: don't write out state if identity has changed (issue5581)...
r32816 self._identity = util.filestat(None)
Martijn Pieters
fsmonitor: new experimental extension...
r28433
def setlastclock(self, clock):
self._lastclock = clock
def getlastclock(self):
return self._lastclock