# HG changeset patch # User Mads Kiilerich # Date 1546807534 -3600 # Node ID cad3185863e0a0a556f6b877fceecaa888ed2f2f # Parent 6104f9106a5ab96d33b1db62637ab26ec0f20e1b middleware: simplify pygrack wrapping - there is no need for any extras For symmetry, do the same in simplehg where it is completely unused. diff -r 6104f9106a5a -r cad3185863e0 kallithea/lib/middleware/pygrack.py --- 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)) diff -r 6104f9106a5a -r cad3185863e0 kallithea/lib/middleware/simplegit.py --- 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): """ diff -r 6104f9106a5a -r cad3185863e0 kallithea/lib/middleware/simplehg.py --- 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)