# HG changeset patch # User Marcin Kuzminski # Date 2019-07-22 14:08:09 # Node ID 343888016f9ec4a03929311fe1a0e7e7347f1b62 # Parent 9b226112f6c124e54f24fc595027866759b884ee vcs: use single base for shared functions of Remote objects diff --git a/vcsserver/git.py b/vcsserver/git.py --- a/vcsserver/git.py +++ b/vcsserver/git.py @@ -44,6 +44,7 @@ from vcsserver.base import RepoFactory, from vcsserver.hgcompat import ( hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) from vcsserver.git_lfs.lib import LFSOidStore +from vcsserver.vcs_base import RemoteBase DIR_STAT = stat.S_IFDIR FILE_MODE = stat.S_IFMT @@ -127,8 +128,7 @@ class GitFactory(RepoFactory): return self.repo(wire, use_libgit2=True) -class GitRemote(object): - EMPTY_COMMIT = '0' * 40 +class GitRemote(RemoteBase): def __init__(self, factory): self._factory = factory @@ -156,14 +156,6 @@ class GitRemote(object): params.extend(['-c', 'http.sslCAinfo={}'.format(ssl_cert_dir)]) return params - def _cache_on(self, wire): - context = wire.get('context', '') - context_uid = '{}'.format(context) - repo_id = wire.get('repo_id', '') - cache = wire.get('cache', True) - cache_on = context and cache - return cache_on, context_uid, repo_id - @reraise_safe_exceptions def discover_git_version(self): stdout, _ = self.run_git_command( @@ -404,7 +396,6 @@ class GitRemote(object): @reraise_safe_exceptions def branch(self, wire, commit_id): cache_on, context_uid, repo_id = self._cache_on(wire) - cache_on = False @self.region.conditional_cache_on_arguments(condition=cache_on) def _branch(_context_uid, _repo_id, _commit_id): regex = re.compile('^refs/heads') diff --git a/vcsserver/hg.py b/vcsserver/hg.py --- a/vcsserver/hg.py +++ b/vcsserver/hg.py @@ -37,6 +37,7 @@ from vcsserver.hgcompat import ( makepeer, instance, match, memctx, exchange, memfilectx, nullrev, hg_merge, patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError, RepoLookupError, InterventionRequired, RequirementError) +from vcsserver.vcs_base import RemoteBase log = logging.getLogger(__name__) @@ -150,7 +151,7 @@ class MercurialFactory(RepoFactory): return self._create_repo(wire, create) -class HgRemote(object): +class HgRemote(RemoteBase): def __init__(self, factory): self._factory = factory @@ -173,14 +174,6 @@ class HgRemote(object): def _get_ctx(self, repo, ref): return get_ctx(repo, ref) - def _cache_on(self, wire): - context = wire.get('context', '') - context_uid = '{}'.format(context) - repo_id = wire.get('repo_id', '') - cache = wire.get('cache', True) - cache_on = context and cache - return cache_on, context_uid, repo_id - @reraise_safe_exceptions def discover_hg_version(self): from mercurial import util diff --git a/vcsserver/svn.py b/vcsserver/svn.py --- a/vcsserver/svn.py +++ b/vcsserver/svn.py @@ -36,6 +36,7 @@ import svn.repos from vcsserver import svn_diff, exceptions, subprocessio, settings from vcsserver.base import RepoFactory, raise_from_original +from vcsserver.vcs_base import RemoteBase log = logging.getLogger(__name__) @@ -107,7 +108,7 @@ NODE_TYPE_MAPPING = { } -class SvnRemote(object): +class SvnRemote(RemoteBase): def __init__(self, factory, hg_factory=None): self._factory = factory @@ -116,14 +117,6 @@ class SvnRemote(object): self._hg_factory = hg_factory self.region = self._factory._cache_region - def _cache_on(self, wire): - context = wire.get('context', '') - context_uid = '{}'.format(context) - repo_id = wire.get('repo_id', '') - cache = wire.get('cache', True) - cache_on = context and cache - return cache_on, context_uid, repo_id - @reraise_safe_exceptions def discover_svn_version(self): try: diff --git a/vcsserver/vcs_base.py b/vcsserver/vcs_base.py new file mode 100644 --- /dev/null +++ b/vcsserver/vcs_base.py @@ -0,0 +1,28 @@ +# RhodeCode VCSServer provides access to different vcs backends via network. +# Copyright (C) 2014-2019 RhodeCode GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +class RemoteBase(object): + EMPTY_COMMIT = '0' * 40 + + def _cache_on(self, wire): + context = wire.get('context', '') + context_uid = '{}'.format(context) + repo_id = wire.get('repo_id', '') + cache = wire.get('cache', True) + cache_on = context and cache + return cache_on, context_uid, repo_id