##// END OF EJS Templates
vcs: use single base for shared functions of Remote objects
marcink -
r749:34388801 default
parent child Browse files
Show More
@@ -0,0 +1,28 b''
1 # RhodeCode VCSServer provides access to different vcs backends via network.
2 # Copyright (C) 2014-2019 RhodeCode GmbH
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18
19 class RemoteBase(object):
20 EMPTY_COMMIT = '0' * 40
21
22 def _cache_on(self, wire):
23 context = wire.get('context', '')
24 context_uid = '{}'.format(context)
25 repo_id = wire.get('repo_id', '')
26 cache = wire.get('cache', True)
27 cache_on = context and cache
28 return cache_on, context_uid, repo_id
@@ -44,6 +44,7 b' from vcsserver.base import RepoFactory, '
44 from vcsserver.hgcompat import (
44 from vcsserver.hgcompat import (
45 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
45 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
46 from vcsserver.git_lfs.lib import LFSOidStore
46 from vcsserver.git_lfs.lib import LFSOidStore
47 from vcsserver.vcs_base import RemoteBase
47
48
48 DIR_STAT = stat.S_IFDIR
49 DIR_STAT = stat.S_IFDIR
49 FILE_MODE = stat.S_IFMT
50 FILE_MODE = stat.S_IFMT
@@ -127,8 +128,7 b' class GitFactory(RepoFactory):'
127 return self.repo(wire, use_libgit2=True)
128 return self.repo(wire, use_libgit2=True)
128
129
129
130
130 class GitRemote(object):
131 class GitRemote(RemoteBase):
131 EMPTY_COMMIT = '0' * 40
132
132
133 def __init__(self, factory):
133 def __init__(self, factory):
134 self._factory = factory
134 self._factory = factory
@@ -156,14 +156,6 b' class GitRemote(object):'
156 params.extend(['-c', 'http.sslCAinfo={}'.format(ssl_cert_dir)])
156 params.extend(['-c', 'http.sslCAinfo={}'.format(ssl_cert_dir)])
157 return params
157 return params
158
158
159 def _cache_on(self, wire):
160 context = wire.get('context', '')
161 context_uid = '{}'.format(context)
162 repo_id = wire.get('repo_id', '')
163 cache = wire.get('cache', True)
164 cache_on = context and cache
165 return cache_on, context_uid, repo_id
166
167 @reraise_safe_exceptions
159 @reraise_safe_exceptions
168 def discover_git_version(self):
160 def discover_git_version(self):
169 stdout, _ = self.run_git_command(
161 stdout, _ = self.run_git_command(
@@ -404,7 +396,6 b' class GitRemote(object):'
404 @reraise_safe_exceptions
396 @reraise_safe_exceptions
405 def branch(self, wire, commit_id):
397 def branch(self, wire, commit_id):
406 cache_on, context_uid, repo_id = self._cache_on(wire)
398 cache_on, context_uid, repo_id = self._cache_on(wire)
407 cache_on = False
408 @self.region.conditional_cache_on_arguments(condition=cache_on)
399 @self.region.conditional_cache_on_arguments(condition=cache_on)
409 def _branch(_context_uid, _repo_id, _commit_id):
400 def _branch(_context_uid, _repo_id, _commit_id):
410 regex = re.compile('^refs/heads')
401 regex = re.compile('^refs/heads')
@@ -37,6 +37,7 b' from vcsserver.hgcompat import ('
37 makepeer, instance, match, memctx, exchange, memfilectx, nullrev, hg_merge,
37 makepeer, instance, match, memctx, exchange, memfilectx, nullrev, hg_merge,
38 patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError,
38 patch, peer, revrange, ui, hg_tag, Abort, LookupError, RepoError,
39 RepoLookupError, InterventionRequired, RequirementError)
39 RepoLookupError, InterventionRequired, RequirementError)
40 from vcsserver.vcs_base import RemoteBase
40
41
41 log = logging.getLogger(__name__)
42 log = logging.getLogger(__name__)
42
43
@@ -150,7 +151,7 b' class MercurialFactory(RepoFactory):'
150 return self._create_repo(wire, create)
151 return self._create_repo(wire, create)
151
152
152
153
153 class HgRemote(object):
154 class HgRemote(RemoteBase):
154
155
155 def __init__(self, factory):
156 def __init__(self, factory):
156 self._factory = factory
157 self._factory = factory
@@ -173,14 +174,6 b' class HgRemote(object):'
173 def _get_ctx(self, repo, ref):
174 def _get_ctx(self, repo, ref):
174 return get_ctx(repo, ref)
175 return get_ctx(repo, ref)
175
176
176 def _cache_on(self, wire):
177 context = wire.get('context', '')
178 context_uid = '{}'.format(context)
179 repo_id = wire.get('repo_id', '')
180 cache = wire.get('cache', True)
181 cache_on = context and cache
182 return cache_on, context_uid, repo_id
183
184 @reraise_safe_exceptions
177 @reraise_safe_exceptions
185 def discover_hg_version(self):
178 def discover_hg_version(self):
186 from mercurial import util
179 from mercurial import util
@@ -36,6 +36,7 b' import svn.repos'
36
36
37 from vcsserver import svn_diff, exceptions, subprocessio, settings
37 from vcsserver import svn_diff, exceptions, subprocessio, settings
38 from vcsserver.base import RepoFactory, raise_from_original
38 from vcsserver.base import RepoFactory, raise_from_original
39 from vcsserver.vcs_base import RemoteBase
39
40
40 log = logging.getLogger(__name__)
41 log = logging.getLogger(__name__)
41
42
@@ -107,7 +108,7 b' NODE_TYPE_MAPPING = {'
107 }
108 }
108
109
109
110
110 class SvnRemote(object):
111 class SvnRemote(RemoteBase):
111
112
112 def __init__(self, factory, hg_factory=None):
113 def __init__(self, factory, hg_factory=None):
113 self._factory = factory
114 self._factory = factory
@@ -116,14 +117,6 b' class SvnRemote(object):'
116 self._hg_factory = hg_factory
117 self._hg_factory = hg_factory
117 self.region = self._factory._cache_region
118 self.region = self._factory._cache_region
118
119
119 def _cache_on(self, wire):
120 context = wire.get('context', '')
121 context_uid = '{}'.format(context)
122 repo_id = wire.get('repo_id', '')
123 cache = wire.get('cache', True)
124 cache_on = context and cache
125 return cache_on, context_uid, repo_id
126
127 @reraise_safe_exceptions
120 @reraise_safe_exceptions
128 def discover_svn_version(self):
121 def discover_svn_version(self):
129 try:
122 try:
General Comments 0
You need to be logged in to leave comments. Login now