Mercurial > kallithea
changeset 7673:642847355a10
hooks: make sure push and pull hooks always are enabled
Don't put things in the database when we pretty much assume they always have
exact content, without any reasonable use case for customization.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 23 Jan 2019 03:52:13 +0100 |
parents | 99edd97366e3 |
children | 5b551b189459 |
files | kallithea/controllers/admin/settings.py kallithea/lib/db_manage.py kallithea/lib/hooks.py kallithea/lib/middleware/simplegit.py kallithea/lib/utils.py kallithea/model/db.py kallithea/model/forms.py kallithea/templates/admin/settings/settings_vcs.html |
diffstat | 8 files changed, 48 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/settings.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/controllers/admin/settings.py Wed Jan 23 03:52:13 2019 +0100 @@ -109,12 +109,6 @@ sett = Ui.get_by_key('hooks', Ui.HOOK_REPO_SIZE) sett.ui_active = form_result['hooks_changegroup_repo_size'] - sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH_LOG) - sett.ui_active = form_result['hooks_changegroup_push_logger'] - - sett = Ui.get_by_key('hooks', Ui.HOOK_PULL_LOG) - sett.ui_active = form_result['hooks_outgoing_pull_logger'] - ## EXTENSIONS sett = Ui.get_or_create('extensions', 'largefiles') sett.ui_active = form_result['extensions_largefiles']
--- a/kallithea/lib/db_manage.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/lib/db_manage.py Wed Jan 23 03:52:13 2019 +0100 @@ -352,8 +352,6 @@ #('phases', 'publish', 'false', False) ('hooks', Ui.HOOK_UPDATE, 'hg update >&2', False), ('hooks', Ui.HOOK_REPO_SIZE, 'python:kallithea.lib.hooks.repo_size', True), - ('hooks', Ui.HOOK_PUSH_LOG, 'python:kallithea.lib.hooks.log_push_action', True), - ('hooks', Ui.HOOK_PULL_LOG, 'python:kallithea.lib.hooks.log_pull_action', True), ('extensions', 'largefiles', '', True), ('largefiles', 'usercache', os.path.join(path, '.cache', 'largefiles'), True), ('extensions', 'hgsubversion', '', False),
--- a/kallithea/lib/hooks.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/lib/hooks.py Wed Jan 23 03:52:13 2019 +0100 @@ -358,53 +358,51 @@ # the post push hook should never use the cached instance scm_repo = repo.scm_instance_no_cache() - _hooks = dict(baseui.configitems('hooks')) or {} - # if push hook is enabled via web interface - if _hooks.get(Ui.HOOK_PUSH_LOG): - rev_data = [] - for l in git_stdin_lines: - old_rev, new_rev, ref = l.strip().split(' ') - _ref_data = ref.split('/') - if _ref_data[1] in ['tags', 'heads']: - rev_data.append({'old_rev': old_rev, - 'new_rev': new_rev, - 'ref': ref, - 'type': _ref_data[1], - 'name': '/'.join(_ref_data[2:])}) + rev_data = [] + for l in git_stdin_lines: + old_rev, new_rev, ref = l.strip().split(' ') + _ref_data = ref.split('/') + if _ref_data[1] in ['tags', 'heads']: + rev_data.append({'old_rev': old_rev, + 'new_rev': new_rev, + 'ref': ref, + 'type': _ref_data[1], + 'name': '/'.join(_ref_data[2:])}) - git_revs = [] - for push_ref in rev_data: - _type = push_ref['type'] - if _type == 'heads': - if push_ref['old_rev'] == EmptyChangeset().raw_id: - # update the symbolic ref if we push new repo - if scm_repo.is_empty(): - scm_repo._repo.refs.set_symbolic_ref('HEAD', - 'refs/heads/%s' % push_ref['name']) + git_revs = [] + for push_ref in rev_data: + _type = push_ref['type'] + if _type == 'heads': + if push_ref['old_rev'] == EmptyChangeset().raw_id: + # update the symbolic ref if we push new repo + if scm_repo.is_empty(): + scm_repo._repo.refs.set_symbolic_ref('HEAD', + 'refs/heads/%s' % push_ref['name']) - # build exclude list without the ref - cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*'] - stdout, stderr = scm_repo.run_git_command(cmd) - ref = push_ref['ref'] - heads = [head for head in stdout.splitlines() if head != ref] - # now list the git revs while excluding from the list - cmd = ['log', push_ref['new_rev'], '--reverse', '--pretty=format:%H'] - cmd.append('--not') - cmd.extend(heads) # empty list is ok - stdout, stderr = scm_repo.run_git_command(cmd) - git_revs += stdout.splitlines() + # build exclude list without the ref + cmd = ['for-each-ref', '--format=%(refname)', 'refs/heads/*'] + stdout, stderr = scm_repo.run_git_command(cmd) + ref = push_ref['ref'] + heads = [head for head in stdout.splitlines() if head != ref] + # now list the git revs while excluding from the list + cmd = ['log', push_ref['new_rev'], '--reverse', '--pretty=format:%H'] + cmd.append('--not') + cmd.extend(heads) # empty list is ok + stdout, stderr = scm_repo.run_git_command(cmd) + git_revs += stdout.splitlines() - elif push_ref['new_rev'] == EmptyChangeset().raw_id: - # delete branch case - git_revs += ['delete_branch=>%s' % push_ref['name']] - else: - cmd = ['log', '%(old_rev)s..%(new_rev)s' % push_ref, - '--reverse', '--pretty=format:%H'] - stdout, stderr = scm_repo.run_git_command(cmd) - git_revs += stdout.splitlines() + elif push_ref['new_rev'] == EmptyChangeset().raw_id: + # delete branch case + git_revs += ['delete_branch=>%s' % push_ref['name']] + else: + cmd = ['log', '%(old_rev)s..%(new_rev)s' % push_ref, + '--reverse', '--pretty=format:%H'] + stdout, stderr = scm_repo.run_git_command(cmd) + git_revs += stdout.splitlines() - elif _type == 'tags': - git_revs += ['tag=>%s' % push_ref['name']] + elif _type == 'tags': + git_revs += ['tag=>%s' % push_ref['name']] - log_push_action(baseui, scm_repo, _git_revs=git_revs) + log_push_action(baseui, scm_repo, _git_revs=git_revs) + return 0
--- a/kallithea/lib/middleware/simplegit.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/lib/middleware/simplegit.py Wed Jan 23 03:52:13 2019 +0100 @@ -196,6 +196,5 @@ _repo = Repository.get_by_repo_name(repo_name) _repo = _repo.scm_instance - _hooks = dict(baseui.configitems('hooks')) or {} - if action == 'pull' and _hooks.get(Ui.HOOK_PULL_LOG): + if action == 'pull': log_pull_action(ui=baseui, repo=_repo._repo)
--- a/kallithea/lib/utils.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/lib/utils.py Wed Jan 23 03:52:13 2019 +0100 @@ -364,6 +364,9 @@ # prevent interactive questions for ssh password / passphrase ssh = baseui.config('ui', 'ssh', default='ssh') baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh) + # push / pull hooks + baseui.setconfig('hooks', 'changegroup.kallithea_log_push_action', 'python:kallithea.lib.hooks.log_push_action') + baseui.setconfig('hooks', 'outgoing.kallithea_log_pull_action', 'python:kallithea.lib.hooks.log_pull_action') return baseui
--- a/kallithea/model/db.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/model/db.py Wed Jan 23 03:52:13 2019 +0100 @@ -351,8 +351,6 @@ HOOK_UPDATE = 'changegroup.update' HOOK_REPO_SIZE = 'changegroup.repo_size' - HOOK_PUSH_LOG = 'changegroup.push_logger' - HOOK_PULL_LOG = 'outgoing.pull_logger' ui_id = Column(Integer(), primary_key=True) ui_section = Column(String(255), nullable=False) @@ -377,16 +375,14 @@ @classmethod def get_builtin_hooks(cls): q = cls.query() - q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, - cls.HOOK_PUSH_LOG, cls.HOOK_PULL_LOG])) + q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE])) q = q.filter(cls.ui_section == 'hooks') return q.all() @classmethod def get_custom_hooks(cls): q = cls.query() - q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE, - cls.HOOK_PUSH_LOG, cls.HOOK_PULL_LOG])) + q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE])) q = q.filter(cls.ui_section == 'hooks') return q.all()
--- a/kallithea/model/forms.py Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/model/forms.py Wed Jan 23 03:52:13 2019 +0100 @@ -385,8 +385,6 @@ ) hooks_changegroup_update = v.StringBoolean(if_missing=False) hooks_changegroup_repo_size = v.StringBoolean(if_missing=False) - hooks_changegroup_push_logger = v.StringBoolean(if_missing=False) - hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False) extensions_largefiles = v.StringBoolean(if_missing=False) extensions_hgsubversion = v.StringBoolean(if_missing=False)
--- a/kallithea/templates/admin/settings/settings_vcs.html Wed Jan 16 02:32:35 2019 +0100 +++ b/kallithea/templates/admin/settings/settings_vcs.html Wed Jan 23 03:52:13 2019 +0100 @@ -11,18 +11,6 @@ </div> <div class="checkbox"> <label> - ${h.checkbox('hooks_changegroup_push_logger','True')} - ${_('Log user push commands')} - </label> - </div> - <div class="checkbox"> - <label> - ${h.checkbox('hooks_outgoing_pull_logger','True')} - ${_('Log user pull commands')} - </label> - </div> - <div class="checkbox"> - <label> ${h.checkbox('hooks_changegroup_update','True')} ${_('Update repository after push (hg update)')} </label>