aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilo Casagrande <milo@ubuntu.com>2013-04-24 14:34:31 +0200
committerMilo Casagrande <milo@ubuntu.com>2013-04-24 14:34:31 +0200
commit362c82ad3631705e5d46721ce9d45cd366a61af2 (patch)
tree5e085d07cfd7d90528c84ae84d18da23a97ca296
parent6ff9ed18f155a77acae0a6e3a14d6c0751a8b1db (diff)
Refactored and cleaned some code, added cache.
* Did some refactoring to clean up some code and avoid not necessary calls. * Added caching mechanism based on the Cache class to store "apps": in this case a couple of classes that are created every time for each similar request.
-rw-r--r--rhodecode/lib/middleware/pygrack.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/rhodecode/lib/middleware/pygrack.py b/rhodecode/lib/middleware/pygrack.py
index 69ae0281..94ca4f97 100644
--- a/rhodecode/lib/middleware/pygrack.py
+++ b/rhodecode/lib/middleware/pygrack.py
@@ -67,7 +67,7 @@ class GitRepository(object):
"""
return path.split(self.repo_name, 1)[-1].strip('/')
- def inforefs(self, request, environ):
+ def inforefs(self, request, environ, git_path=None):
"""
WSGI Response producer for HTTP GET Git Smart
HTTP /info/refs request.
@@ -77,7 +77,8 @@ class GitRepository(object):
if self.dumb:
log.debug('Using dumb HTTP git protocol')
- git_path = self._get_fixedpath(request.path_info)
+ if not git_path:
+ git_path = self._get_fixedpath(request.path_info)
filename = os.path.join(self.content_path, git_path)
if os.path.isfile(filename):
@@ -127,20 +128,20 @@ class GitRepository(object):
return resp
- def backend(self, request, environ):
+ def backend(self, request, environ, git_path=None):
"""
WSGI Response producer for HTTP POST Git Smart HTTP requests.
Reads commands and data from HTTP POST's body.
returns an iterator obj with contents of git command's
response to stdout
"""
- git_command = self._get_fixedpath(request.path_info)
+ if not git_path:
+ git_path = self._get_fixedpath(request.path_info)
resp = Response()
if self.dumb:
log.debug('Using dumb HTTP git protocol')
- filename = os.path.join(self.content_path, git_command)
- git_path = self._get_fixedpath(request.path_info)
+ filename = os.path.join(self.content_path, git_path)
if os.path.isfile(filename):
mime_type, encoding = mimetypes.guess_type(filename)
@@ -155,8 +156,8 @@ class GitRepository(object):
log.info("File not found: %s" % git_path)
resp.status = 404
else:
- if git_command not in self.commands:
- log.debug('command %s not allowed' % git_command)
+ if git_path not in self.commands:
+ log.debug('command %s not allowed' % git_path)
return exc.HTTPMethodNotAllowed()
if 'CONTENT_LENGTH' in environ:
@@ -175,7 +176,7 @@ class GitRepository(object):
env=gitenv,
cwd=os.getcwd()
)
- cmd = r'git %s --stateless-rpc "%s"' % (git_command[4:],
+ cmd = r'git %s --stateless-rpc "%s"' % (git_path[4:],
self.content_path),
log.debug('handling cmd %s' % cmd)
out = subprocessio.SubprocessIOChunker(
@@ -187,12 +188,12 @@ class GitRepository(object):
log.error(traceback.format_exc())
raise exc.HTTPExpectationFailed()
- resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
+ resp.content_type = 'application/x-%s-result' % git_path.encode('utf8')
resp.status = 200
resp.charset = None
resp.app_iter = out
- if git_command in [u'git-receive-pack']:
+ if git_path in [u'git-receive-pack']:
# updating refs manually after each push.
# Needed for pre-1.7.0.4 git clients using regular HTTP mode.
cmd = (u'git --git-dir "%s" '
@@ -210,7 +211,7 @@ class GitRepository(object):
elif [a for a in self.valid_accepts if a in request.accept]:
app = self.backend
try:
- resp = app(request, environ)
+ resp = app(request, environ, git_path=_path)
except exc.HTTPException, e:
resp = e
log.error(traceback.format_exc())