changeset 7705:cad3185863e0

middleware: simplify pygrack wrapping - there is no need for any extras For symmetry, do the same in simplehg where it is completely unused.
author Mads Kiilerich <mads@kiilerich.com>
date Sun, 06 Jan 2019 21:45:34 +0100
parents 6104f9106a5a
children 7268209e8843
files kallithea/lib/middleware/pygrack.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py
diffstat 3 files changed, 15 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/middleware/pygrack.py	Fri Jan 04 03:51:45 2019 +0100
+++ b/kallithea/lib/middleware/pygrack.py	Sun Jan 06 21:45:34 2019 +0100
@@ -70,7 +70,7 @@
     git_folder_signature = set(['config', 'head', 'info', 'objects', 'refs'])
     commands = ['git-upload-pack', 'git-receive-pack']
 
-    def __init__(self, repo_name, content_path, extras):
+    def __init__(self, repo_name, content_path):
         files = set([f.lower() for f in os.listdir(content_path)])
         if not (self.git_folder_signature.intersection(files)
                 == self.git_folder_signature):
@@ -79,7 +79,6 @@
         self.valid_accepts = ['application/x-%s-result' %
                               c for c in self.commands]
         self.repo_name = repo_name
-        self.extras = extras
 
     def _get_fixedpath(self, path):
         """
@@ -201,7 +200,7 @@
 
 class GitDirectory(object):
 
-    def __init__(self, repo_root, repo_name, extras):
+    def __init__(self, repo_root, repo_name):
         repo_location = os.path.join(repo_root, repo_name)
         if not os.path.isdir(repo_location):
             raise OSError(repo_location)
@@ -209,22 +208,21 @@
         self.content_path = repo_location
         self.repo_name = repo_name
         self.repo_location = repo_location
-        self.extras = extras
 
     def __call__(self, environ, start_response):
         content_path = self.content_path
         try:
-            app = GitRepository(self.repo_name, content_path, self.extras)
+            app = GitRepository(self.repo_name, content_path)
         except (AssertionError, OSError):
             content_path = os.path.join(content_path, '.git')
             if os.path.isdir(content_path):
-                app = GitRepository(self.repo_name, content_path, self.extras)
+                app = GitRepository(self.repo_name, content_path)
             else:
                 return exc.HTTPNotFound()(environ, start_response)
         return app(environ, start_response)
 
 
-def make_wsgi_app(repo_name, repo_root, extras):
+def make_wsgi_app(repo_name, repo_root):
     from dulwich.web import LimitedInputFilter, GunzipFilter
-    app = GitDirectory(repo_root, repo_name, extras)
+    app = GitDirectory(repo_root, repo_name)
     return GunzipFilter(LimitedInputFilter(app))
--- a/kallithea/lib/middleware/simplegit.py	Fri Jan 04 03:51:45 2019 +0100
+++ b/kallithea/lib/middleware/simplegit.py	Sun Jan 06 21:45:34 2019 +0100
@@ -41,6 +41,7 @@
     _set_extras
 from kallithea.lib.base import BaseVCSController
 from kallithea.lib.utils import make_ui, is_valid_repo
+from kallithea.lib.middleware.pygrack import make_wsgi_app
 
 log = logging.getLogger(__name__)
 
@@ -113,9 +114,6 @@
         #===================================================================
         # GIT REQUEST HANDLING
         #===================================================================
-        repo_path = os.path.join(safe_str(self.basepath), str_repo_name)
-        log.debug('Repository path is %s', repo_path)
-
         fix_PATH()
         log.debug('HOOKS extras is %s', extras)
         baseui = make_ui()
@@ -125,27 +123,17 @@
             self._handle_githooks(repo_name, action, baseui, environ)
             log.info('%s action on Git repo "%s" by "%s" from %s',
                      action, str_repo_name, safe_str(user.username), ip_addr)
-            app = self.__make_app(repo_name, repo_path, extras)
+            app = self.__make_app(repo_name)
             return app(environ, start_response)
         except Exception:
             log.error(traceback.format_exc())
             return HTTPInternalServerError()(environ, start_response)
 
-    def __make_app(self, repo_name, repo_path, extras):
-        """
-        Make an wsgi application using dulserver
-
-        :param repo_name: name of the repository
-        :param repo_path: full path to the repository
+    def __make_app(self, repo_name):
         """
-
-        from kallithea.lib.middleware.pygrack import make_wsgi_app
-        app = make_wsgi_app(
-            repo_root=safe_str(self.basepath),
-            repo_name=safe_unicode(repo_name),
-            extras=extras,
-        )
-        return app
+        Return a pygrack wsgi application.
+        """
+        return make_wsgi_app(repo_name, safe_str(self.basepath)) # FIXME: safe_str???
 
     def __get_repository(self, environ):
         """
--- a/kallithea/lib/middleware/simplehg.py	Fri Jan 04 03:51:45 2019 +0100
+++ b/kallithea/lib/middleware/simplehg.py	Sun Jan 06 21:45:34 2019 +0100
@@ -149,7 +149,7 @@
             log.info('%s action on Mercurial repo "%s" by "%s" from %s',
                      action, str_repo_name, safe_str(user.username), ip_addr)
             environ['REPO_NAME'] = str_repo_name # used by hgweb_mod.hgweb
-            app = self.__make_app(repo_path, baseui, extras)
+            app = self.__make_app(repo_path, baseui)
             return app(environ, start_response)
         except RepoError as e:
             if str(e).find('not found') != -1:
@@ -158,10 +158,9 @@
             log.error(traceback.format_exc())
             return HTTPInternalServerError()(environ, start_response)
 
-    def __make_app(self, repo_name, baseui, extras):
+    def __make_app(self, repo_name, baseui):
         """
-        Make an wsgi application using hgweb, and inject generated baseui
-        instance, additionally inject some extras into ui object
+        Make an hgweb wsgi application using baseui.
         """
         return hgweb_mod.hgweb(repo_name, name=repo_name, baseui=baseui)