Changeset - 9584eb51ae52
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2020-01-03 02:16:42
mads@kiilerich.com
Grafted from: 0d5fb5341e0f
git: initialize hook app environment with paste as we do in other places

We want to use the whole paste / tg stack because it will do more
initialization for us - consistently, and in the right order.

This will allow a next change to avoid a problem in our custom beaker
initialization.

Going through paste might be a bit more heavy and slower than before, but it is
only run once for each git push.

Ultimately, we should probably get rid of the special hook entry point, and
just use kallithea-cli as the only entry point.
1 file changed with 9 insertions and 13 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/hooks.py
Show inline comments
 
@@ -29,13 +29,13 @@ import os
 
import time
 

	
 
import mercurial.scmutil
 

	
 
from kallithea.lib import helpers as h
 
from kallithea.lib.exceptions import UserCreationError
 
from kallithea.lib.utils import action_logger, make_ui, setup_cache_regions
 
from kallithea.lib.utils import action_logger, make_ui
 
from kallithea.lib.utils2 import ascii_str, get_hook_environment, safe_bytes, safe_str, safe_unicode
 
from kallithea.lib.vcs.backends.base import EmptyChangeset
 
from kallithea.model.db import Repository, User
 

	
 

	
 
def _get_scm_size(alias, root_path):
 
@@ -298,27 +298,23 @@ def _hook_environment(repo_path):
 
    db repository.
 

	
 
    Git hooks are executed as subprocess of Git while Kallithea is waiting, and
 
    they thus need enough info to be able to create an app environment and
 
    connect to the database.
 
    """
 
    from paste.deploy import appconfig
 
    from sqlalchemy import engine_from_config
 
    from kallithea.config.environment import load_environment
 
    from kallithea.model.base import init_model
 
    import paste.deploy
 
    import kallithea.config.middleware
 
    import kallithea.lib.utils
 

	
 
    extras = get_hook_environment()
 
    ini_file_path = extras['config']
 

	
 
    path_to_ini_file = extras['config']
 
    kallithea.CONFIG = paste.deploy.appconfig('config:' + path_to_ini_file)
 
    #logging.config.fileConfig(ini_file_path) # Note: we are in a different process - don't use configured logging
 
    app_conf = appconfig('config:%s' % ini_file_path)
 
    conf = load_environment(app_conf.global_conf, app_conf.local_conf)
 

	
 
    setup_cache_regions(conf)
 

	
 
    engine = engine_from_config(conf, 'sqlalchemy.')
 
    init_model(engine)
 
    kallithea.config.middleware.make_app_without_logging(kallithea.CONFIG.global_conf, **kallithea.CONFIG.local_conf)
 
    kallithea.lib.utils.setup_cache_regions(kallithea.CONFIG)
 

	
 
    repo_path = safe_unicode(repo_path)
 
    # fix if it's not a bare repo
 
    if repo_path.endswith(os.sep + '.git'):
 
        repo_path = repo_path[:-5]
 

	
0 comments (0 inline, 0 general)