Changeset - 3f8cd215f5eb
[Not reviewed]
default
0 3 0
Mads Kiilerich (mads) - 5 years ago 2020-11-02 15:40:18
mads@kiilerich.com
hooks: don't pass arguments to log_pull_action when calling from git - it uses set_hook_environment
3 files changed with 3 insertions and 9 deletions:
0 comments (0 inline, 0 general)
kallithea/config/middleware/simplegit.py
Show inline comments
 
@@ -31,14 +31,12 @@ Original author and date, and relevant c
 
import logging
 
import re
 

	
 
from kallithea.config.middleware.pygrack import make_wsgi_app
 
from kallithea.lib import hooks
 
from kallithea.lib.base import BaseVCSController, get_path_info
 
from kallithea.lib.utils import make_ui
 
from kallithea.model import db
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)$')
 
@@ -83,16 +81,13 @@ class SimpleGit(BaseVCSController):
 
        pygrack_app = make_wsgi_app(parsed_request.repo_name, self.basepath)
 

	
 
        def wrapper_app(environ, start_response):
 
            if (parsed_request.cmd == 'info/refs' and
 
                parsed_request.service == 'git-upload-pack'
 
            ):
 
                baseui = make_ui()
 
                repo = db.Repository.get_by_repo_name(parsed_request.repo_name)
 
                scm_repo = repo.scm_instance
 
                # Run hooks like Mercurial outgoing.kallithea_log_pull_action does
 
                hooks.log_pull_action(ui=baseui, repo=scm_repo._repo)
 
                hooks.log_pull_action()
 
            # Note: push hooks are handled by post-receive hook
 

	
 
            return pygrack_app(environ, start_response)
 

	
 
        return wrapper_app
kallithea/lib/hooks.py
Show inline comments
 
@@ -80,13 +80,13 @@ def repo_size(ui, repo, hooktype=None, *
 
           'Last revision is now r%s:%s\n') % (
 
        size_hg_f, size_root_f, size_total_f, last_cs.rev(), ascii_str(last_cs.hex())[:12]
 
    )
 
    ui.status(safe_bytes(msg))
 

	
 

	
 
def log_pull_action(ui, repo, **kwargs):
 
def log_pull_action(*args, **kwargs):
 
    """Logs user last pull action
 

	
 
    Called as Mercurial hook outgoing.kallithea_log_pull_action or from Kallithea before invoking Git.
 

	
 
    Does *not* use the action from the hook environment but is always 'pull'.
 
    """
kallithea/lib/vcs/ssh/git.py
Show inline comments
 
@@ -13,13 +13,12 @@
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import logging
 
import os
 

	
 
from kallithea.lib import hooks
 
from kallithea.lib.utils import make_ui
 
from kallithea.lib.vcs.ssh import base
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
@@ -63,13 +62,13 @@ class GitSshHandler(base.BaseSshHandler)
 
        base.BaseSshHandler.__init__(self, repo_name)
 
        self.verb = verb
 

	
 
    def _serve(self):
 
        if self.verb == 'git-upload-pack': # action 'pull'
 
            # base class called set_hook_environment with 'push' action ... but log_pull_action ignores that and will 'pull'
 
            hooks.log_pull_action(ui=make_ui(), repo=self.db_repo.scm_instance._repo)
 
            hooks.log_pull_action()
 
        else: # probably verb 'git-receive-pack', action 'push'
 
            if not self.allow_push:
 
                self.exit('Push access to %r denied' % self.repo_name)
 
            # Note: push logging is handled by Git post-receive hook
 

	
 
        # git shell is not a real shell but use shell inspired quoting *inside* the argument.
0 comments (0 inline, 0 general)