hg: fsmonitor: fix sockpath propagation from WATCHMAN_SOCK env

Summary:
This unbreaks the watchman/hg integration tests in a more
sustainable and holistic way than the workaround in D19415053.

The issue is that the explicit fsmonitor sockpath configuration option didn't
take into account that the environment needs to take precedence in order for
the appropriate watchman instance to be used by the set of processes in a given
process tree.  It is not feasible to have them all pass `--config` options to
mercurial because that would require teaching several layers about the
fsmonitor extension, and then later to update them as we evolve how mercurial
works.

Reviewed By: quark-zju

Differential Revision: D19415252

fbshipit-source-id: 5872d0462e466bfb5d70f809c3c433d92fb78567
This commit is contained in:
Wez Furlong 2020-01-17 17:34:23 -08:00 committed by Facebook Github Bot
parent fdaf9bffd8
commit 8d85b68d6b

View File

@ -11,7 +11,7 @@ import ctypes
import getpass
import os
from edenscm.mercurial import blackbox, progress, pycompat, util
from edenscm.mercurial import blackbox, encoding, progress, pycompat, util
from edenscm.mercurial.node import hex
from .. import pywatchman
@ -74,12 +74,19 @@ class client(object):
self._sockpath = None
sockpath = repo.ui.config("fsmonitor", "sockpath")
if sockpath and self._user:
sockpath = sockpath.replace("%i", self._user)
# When spawned indirectly by watchman, or the watchman/eden integration
# tests, the appropriate sockpath is passed down to us via the environment
# and must take precedence over other configuration
sockpath = encoding.environ.get("WATCHMAN_SOCK", None)
if sockpath is None:
sockpath = repo.ui.config("fsmonitor", "sockpath")
if sockpath and self._user:
sockpath = sockpath.replace("%i", self._user)
repo.ui.debug("watchman sockpath is set as %s\n" % sockpath)
if sockpath:
if os.path.exists(sockpath):
self._sockpath = sockpath
repo.ui.debug("watchman sockpath is set as %s\n" % sockpath)
self._transport = None
if repo.ui.configbool("fsmonitor", "tcp", False):