def command(self, *args, **kwargs): ignoreerrors = kwargs.get("ignoreerrors", False) with progress.spinner(self._ui, "querying watchman"): try: try: return self._command(*args) except pywatchman.UseAfterFork: # Ideally we wouldn't let this happen, but if it does happen, # record it in the log and retry the command. blackbox.log( { "debug": { "value": "fork detected. re-connect to watchman socket" } } ) self._watchmanclient = None 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 if not ignoreerrors: self._watchmanclient = None raise
def _command(self, *args): watchmanargs = (args[0], self._resolved_root) + args[1:] error = None needretry = False starttime = util.timer() try: if self._watchmanclient is None: if compat.PYTHON3: encoding = "bser" else: encoding = "bser-v1" self._firsttime = False self._watchmanclient = pywatchman.client( sockpath=self._sockpath, transport=self._transport, tcpAddress=(self._tcp_host, self._tcp_port), timeout=self._timeout, recvEncoding=encoding, sendEncoding=encoding, useImmutableBser=True, ) return self._watchmanclient.query(*watchmanargs) except pywatchman.CommandError as ex: error = ex.msg if "unable to resolve root" in ex.msg: raise WatchmanNoRoot(self._resolved_root, ex.msg) raise Unavailable(ex.msg) except pywatchman.SocketConnectError as ex: error = str(ex) # If fsmonitor.sockpath was specified in the configuration, we will # have skipped running `watchman get-sockname` which has the # consequence of not starting the watchman server up if it happens # to have been stopped. # Rather than just throwing up our hands in that situation, let's # clear the pre-configured sockpath so that the client will probe # and start it up. if not self._ui.config("fsmonitor", "sockpath") or self._sockpath is None: # Either sockpath wasn't configured, or we already tried clearing # it out, so let's propagate this error. raise Unavailable(str(ex)) # Recurse and retry the command, and hopefully it will # start the server this time. self._sockpath = None self._watchmanclient = None needretry = True except pywatchman.WatchmanError as ex: error = str(ex) raise Unavailable(str(ex)) finally: event = { "watchman": { "args": args, "duration_ms": int((util.timer() - starttime) * 1000), } } if error is not None: event["watchman"]["result"] = {"error": error} blackbox.log(event) if needretry: return self._command(*args)
def _peersetup(ui, peer): if peer.capable("clienttelemetry"): logargs = clienttelemetryvaluesfromconfig(ui) logargs.update( {name: f(ui) for name, f in _clienttelemetryfuncs.items()}) logargs.update(_clienttelemetrydata) response = decodeutf8(peer._call("clienttelemetry", **logargs)) responseitems = response.split() peername = responseitems[0] if responseitems else "" peer._realhostname = peername peerinfo = {} for index in range(1, len(responseitems) - 1, 2): peerinfo[responseitems[index]] = responseitems[index + 1] peer._peerinfo = peerinfo blackbox.log( {"clienttelemetry": { "peername": peername, "peerinfo": peerinfo }}) util.info("client-telemetry", peername=peername, **peerinfo) ann = ui.configbool("clienttelemetry", "announceremotehostname", None) if ann is None: ann = not ui.plain() and ui._isatty(ui.ferr) if ann and not ui.quiet: ui.write_err(_("connected to %s\n") % response) perftrace.tracevalue("Server", peername) for item, value in peerinfo.items(): perftrace.tracevalue(f"Server {item}", value)
def _fsmonitorwalk(self, match): fsmonitorevent = {} try: return _walk(self, match, fsmonitorevent) finally: try: blackbox.log({"fsmonitor": fsmonitorevent}) except UnicodeDecodeError: # test-adding-invalid-utf8.t hits this path pass
def _peersetup(ui, peer): if peer.capable("clienttelemetry"): logargs = {name: f(ui) for name, f in _clienttelemetryfuncs.items()} logargs.update(_clienttelemetrydata) peername = decodeutf8(peer._call("clienttelemetry", **logargs)) peer._realhostname = peername blackbox.log({"clienttelemetry": {"peername": peername}}) ann = ui.configbool("clienttelemetry", "announceremotehostname", None) if ann is None: ann = not ui.plain() and ui._isatty(ui.ferr) if ann and not ui.quiet: ui.warn(_("connected to %s\n") % peername) perftrace.tracevalue("Server", peername)
def logsyncop( repo, op, version, oldheads, newheads, oldbm, newbm, oldrbm, newrbm, oldsnapshots, newsnapshots, ): oldheadsset = set(oldheads) newheadsset = set(newheads) oldbmset = set(oldbm) newbmset = set(newbm) oldrbmset = set(oldrbm) newrbmset = set(newrbm) oldsnapset = set(oldsnapshots) newsnapset = set(newsnapshots) addedheads = blackbox.shortlist( [h for h in newheads if h not in oldheadsset]) removedheads = blackbox.shortlist( [h for h in oldheads if h not in newheadsset]) addedbm = blackbox.shortlist([h for h in newbm if h not in oldbmset]) removedbm = blackbox.shortlist([h for h in oldbm if h not in newbmset]) addedrbm = blackbox.shortlist([h for h in newrbm if h not in oldrbmset]) removedrbm = blackbox.shortlist([h for h in oldrbm if h not in newrbmset]) addedsnaps = blackbox.shortlist( [h for h in newsnapshots if h not in oldsnapset]) removedsnaps = blackbox.shortlist( [h for h in oldsnapshots if h not in newsnapset]) blackbox.log({ "commit_cloud_sync": { "op": op, "version": version, "added_heads": addedheads, "removed_heads": removedheads, "added_bookmarks": addedbm, "removed_bookmarks": removedbm, "added_remote_bookmarks": addedrbm, "removed_remote_bookmarks": removedrbm, "added_snapshots": addedsnaps, "removed_snapshots": removedsnaps, } }) util.info("commit-cloud-sync", op=op, version=version)