diff --git a/vcsserver/remote/hg_remote.py b/vcsserver/remote/hg_remote.py --- a/vcsserver/remote/hg_remote.py +++ b/vcsserver/remote/hg_remote.py @@ -23,6 +23,7 @@ import sys import urllib.request import urllib.parse import hashlib +import traceback from hgext import largefiles, rebase @@ -759,6 +760,24 @@ class HgRemote(RemoteBase): self._factory.repo(wire, create=create) @reraise_safe_exceptions + def assert_correct_path(self, wire): + cache_on, context_uid, repo_id = self._cache_on(wire) + region = self._region(wire) + + @region.conditional_cache_on_arguments(condition=cache_on) + def _assert_correct_path(_context_uid, _repo_id): + try: + self._factory.repo(wire, create=False) + except Exception: + path = wire.get('path') + tb = traceback.format_exc() + log.debug("Invalid Mercurial path `%s`, tb: %s", path, tb) + return False + return True + + return _assert_correct_path(context_uid, repo_id) + + @reraise_safe_exceptions def lookup(self, wire, revision, both): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire)