Ejemplo n.º 1
0
def disconnected(repo):
    """
    Returns True if the user has manually disconnected from a workspace.
    """
    disconnected = _get(repo, "disconnected")
    if disconnected is None or isinstance(disconnected, bool):
        return disconnected
    return util.parsebool(disconnected)
Ejemplo n.º 2
0
    def _detectrace(self, match=None):
        ui = self._ui
        detectrace = ui.configbool(
            "fsmonitor", "detectrace") or util.parsebool(
                encoding.environ.get("HGDETECTRACE", ""))
        if detectrace:
            state = self._fsmonitorstate
            client = self._watchmanclient
            try:
                startclock = client.command(
                    "clock",
                    {"sync_timeout": int(state.timeout * 1000)})["clock"]
            except Exception as ex:
                ui.warn(_("cannot detect status race: %s\n") % ex)
                detectrace = False

        yield

        if detectrace:
            raceresult = client.command(
                "query",
                {
                    "fields": ["name"],
                    "since":
                    startclock,
                    "expression": [
                        "allof",
                        ["type", "f"],
                        ["not", ["anyof", ["dirname", ".hg"]]],
                    ],
                    "sync_timeout":
                    int(state.timeout * 1000),
                    "empty_on_fresh_instance":
                    True,
                },
            )
            ignore = self._repo.dirstate._ignore
            racenames = [
                name for name in raceresult["files"]
                # hg-checklink*, hg-checkexec* are ignored.
                # Ignored files are allowed. "listignore" was checked before.
                if not name.startswith("hg-check") and not ignore(name) and (
                    match is None or match(name))
            ]
            if racenames:
                msg = _(
                    "[race-detector] files changed when scanning changes in working copy:\n%s"
                ) % "".join("  %s\n" % name for name in sorted(racenames))
                raise error.WorkingCopyRaced(
                    msg,
                    hint=
                    _("this is an error because HGDETECTRACE or fsmonitor.detectrace is set to true"
                      ),
                )
Ejemplo n.º 3
0
def _racedetect(orig, self, other, s, match, listignored, listclean,
                listunknown):
    repo = self._repo
    detectrace = repo.ui.configbool(
        "fsmonitor", "detectrace") or util.parsebool(
            encoding.environ.get("HGDETECTRACE", ""))
    if detectrace and util.safehasattr(repo.dirstate._fs, "_watchmanclient"):
        state = repo.dirstate._fs._fsmonitorstate
        try:
            startclock = repo.dirstate._fs._watchmanclient.command(
                "clock", {"sync_timeout": int(state.timeout * 1000)})["clock"]
        except Exception as ex:
            repo.ui.warn(_("cannot detect status race: %s\n") % ex)
            detectrace = False
    result = orig(self, other, s, match, listignored, listclean, listunknown)
    if detectrace and util.safehasattr(repo.dirstate._fs, "_fsmonitorstate"):
        raceresult = repo._watchmanclient.command(
            "query",
            {
                "fields": ["name"],
                "since":
                startclock,
                "expression": [
                    "allof",
                    ["type", "f"],
                    ["not", ["anyof", ["dirname", ".hg"]]],
                ],
                "sync_timeout":
                int(state.timeout * 1000),
                "empty_on_fresh_instance":
                True,
            },
        )
        ignore = repo.dirstate._ignore
        racenames = [
            name for name in raceresult["files"]
            # hg-checklink*, hg-checkexec* are ignored.
            # Ignored files are allowed unless listignored is set.
            if not name.startswith("hg-check") and (
                listignored or not ignore(name))
        ]
        if racenames:
            msg = _(
                "[race-detector] files changed when scanning changes in working copy:\n%s"
            ) % "".join("  %s\n" % name for name in sorted(racenames))
            raise error.WorkingCopyRaced(
                msg,
                hint=
                _("this is an error because HGDETECTRACE or fsmonitor.detectrace is set to true"
                  ),
            )
    return result