# HG changeset patch # User RhodeCode Admin # Date 2021-06-23 19:38:16 # Node ID c3d9862a10c96e2b3f501a8ffe5748f85d4b190d # Parent bdcbd118d7cf7ba48eeac371f05d57e72ebe250b ssh: use pre-compiled backends for faster matching of vcs detection. diff --git a/rhodecode/apps/ssh_support/lib/backends/__init__.py b/rhodecode/apps/ssh_support/lib/backends/__init__.py --- a/rhodecode/apps/ssh_support/lib/backends/__init__.py +++ b/rhodecode/apps/ssh_support/lib/backends/__init__.py @@ -34,6 +34,9 @@ log = logging.getLogger(__name__) class SshWrapper(object): + hg_cmd_pat = re.compile(r'^hg\s+\-R\s+(\S+)\s+serve\s+\-\-stdio$') + git_cmd_pat = re.compile(r'^git-(receive-pack|upload-pack)\s\'[/]?(\S+?)(|\.git)\'$') + svn_cmd_pat = re.compile(r'^svnserve -t') def __init__(self, command, connection_info, mode, user, user_id, key_id, shell, ini_path, env): @@ -101,24 +104,20 @@ class SshWrapper(object): vcs_type = mode if mode in ['svn', 'hg', 'git'] else None repo_name = None - hg_pattern = r'^hg\s+\-R\s+(\S+)\s+serve\s+\-\-stdio$' - hg_match = re.match(hg_pattern, self.command) + hg_match = self.hg_cmd_pat.match(self.command) if hg_match is not None: vcs_type = 'hg' repo_name = self.maybe_translate_repo_uid(hg_match.group(1).strip('/')) return vcs_type, repo_name, mode - git_pattern = r'^git-(receive-pack|upload-pack)\s\'[/]?(\S+?)(|\.git)\'$' - git_match = re.match(git_pattern, self.command) + git_match = self.git_cmd_pat.match(self.command) if git_match is not None: vcs_type = 'git' repo_name = self.maybe_translate_repo_uid(git_match.group(2).strip('/')) mode = git_match.group(1) return vcs_type, repo_name, mode - svn_pattern = r'^svnserve -t' - svn_match = re.match(svn_pattern, self.command) - + svn_match = self.svn_cmd_pat.match(self.command) if svn_match is not None: vcs_type = 'svn' # Repo name should be extracted from the input stream, we're unable to