##// END OF EJS Templates
vcs: do an early detection of vcs-type request....
marcink -
r1297:de699d5e default
parent child Browse files
Show More
@@ -165,7 +165,7 b' class SimpleVCS(object):'
165 165 self.acl_repo_name = acl_repo_name
166 166 self.is_shadow_repo = True
167 167
168 log.debug('Repository names: %s', {
168 log.debug('Setting all VCS repository names: %s', {
169 169 'acl_repo_name': self.acl_repo_name,
170 170 'url_repo_name': self.url_repo_name,
171 171 'vcs_repo_name': self.vcs_repo_name,
@@ -35,6 +35,9 b' from rhodecode.model.settings import Vcs'
35 35
36 36 log = logging.getLogger(__name__)
37 37
38 VCS_TYPE_KEY = '_rc_vcs_type'
39 VCS_TYPE_SKIP = '_rc_vcs_skip'
40
38 41
39 42 def is_git(environ):
40 43 """
@@ -126,6 +129,43 b' class GunzipMiddleware(object):'
126 129 return self.app(environ, start_response)
127 130
128 131
132 def is_vcs_call(environ):
133 if VCS_TYPE_KEY in environ:
134 raw_type = environ[VCS_TYPE_KEY]
135 return raw_type and raw_type != VCS_TYPE_SKIP
136 return False
137
138
139 def detect_vcs_request(environ, backends):
140 checks = {
141 'hg': (is_hg, SimpleHg),
142 'git': (is_git, SimpleGit),
143 'svn': (is_svn, SimpleSvn),
144 }
145 handler = None
146
147 if VCS_TYPE_KEY in environ:
148 raw_type = environ[VCS_TYPE_KEY]
149 if raw_type == VCS_TYPE_SKIP:
150 log.debug('got `skip` marker for vcs detection, skipping...')
151 return handler
152
153 _check, handler = checks.get(raw_type) or [None, None]
154 if handler:
155 log.debug('got handler:%s from environ', handler)
156
157 if not handler:
158 log.debug('checking if request is of VCS type in order: %s', backends)
159 for vcs_type in backends:
160 vcs_check, _handler = checks[vcs_type]
161 if vcs_check(environ):
162 log.debug('vcs handler found %s', _handler)
163 handler = _handler
164 break
165
166 return handler
167
168
129 169 class VCSMiddleware(object):
130 170
131 171 def __init__(self, app, config, appenlight_client, registry):
@@ -136,11 +176,6 b' class VCSMiddleware(object):'
136 176 self.use_gzip = True
137 177 # order in which we check the middlewares, based on vcs.backends config
138 178 self.check_middlewares = config['vcs.backends']
139 self.checks = {
140 'hg': (is_hg, SimpleHg),
141 'git': (is_git, SimpleGit),
142 'svn': (is_svn, SimpleSvn),
143 }
144 179
145 180 def vcs_config(self, repo_name=None):
146 181 """
@@ -155,14 +190,10 b' class VCSMiddleware(object):'
155 190
156 191 def _get_handler_app(self, environ):
157 192 app = None
158 log.debug('Checking vcs types in order: %r', self.check_middlewares)
159 for vcs_type in self.check_middlewares:
160 vcs_check, handler = self.checks[vcs_type]
161 if vcs_check(environ):
162 log.debug(
163 'Found VCS Middleware to handle the request %s', handler)
164 app = handler(self.application, self.config, self.registry)
165 break
193 log.debug('VCSMiddleware: detecting vcs type.')
194 handler = detect_vcs_request(environ, self.check_middlewares)
195 if handler:
196 app = handler(self.application, self.config, self.registry)
166 197
167 198 return app
168 199
@@ -28,12 +28,16 b' from pylons.util import ContextObj'
28 28 from routes.util import URLGenerator
29 29
30 30 from rhodecode.lib.base import attach_context_attributes, get_auth_user
31 from rhodecode.lib.middleware.vcs import (
32 detect_vcs_request, VCS_TYPE_KEY, VCS_TYPE_SKIP)
31 33 from rhodecode.model import meta
32 34
35
33 36 log = logging.getLogger(__name__)
34 37
35 38
36 39 def pylons_compatibility_tween_factory(handler, registry):
40
37 41 def pylons_compatibility_tween(request):
38 42 """
39 43 While migrating from pylons to pyramid we need to call some pylons code
@@ -43,13 +47,23 b' def pylons_compatibility_tween_factory(h'
43 47 config = rhodecode.CONFIG
44 48 environ = request.environ
45 49 session = request.session
46 session_key = (config['pylons.environ_config']
47 .get('session', 'beaker.session'))
50
51 vcs_handler = detect_vcs_request(
52 request.environ, request.registry.settings.get('vcs.backends'))
53
54 if vcs_handler:
55 request.environ[VCS_TYPE_KEY] = vcs_handler.SCM
56 return handler(request)
57
58 request.environ[VCS_TYPE_KEY] = VCS_TYPE_SKIP
48 59
49 60 # Setup pylons globals.
50 61 pylons.config._push_object(config)
51 62 pylons.request._push_object(request)
52 63 pylons.session._push_object(session)
64
65 session_key = (
66 config['pylons.environ_config'].get('session', 'beaker.session'))
53 67 environ[session_key] = session
54 68 pylons.url._push_object(URLGenerator(config['routes.map'],
55 69 environ))
General Comments 0
You need to be logged in to leave comments. Login now