From 13adf4b2341fd84fce5b8cc44bb76b190e396eb7 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 20 Feb 2019 11:56:10 +0100 Subject: [PATCH] fixed PreReceiveRepositoryHooks for newer versions of mercurial --- .../main/resources/sonia/scm/python/hgweb.py | 4 +-- .../resources/sonia/scm/python/scmhooks.py | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py index b14c8e8026..aeb5d6d588 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/hgweb.py @@ -46,8 +46,8 @@ u.setconfig('web', 'push_ssl', 'false') u.setconfig('web', 'allow_read', '*') u.setconfig('web', 'allow_push', '*') -u.setconfig('hooks', 'changegroup.scm', 'python:scmhooks.callback') -u.setconfig('hooks', 'pretxnchangegroup.scm', 'python:scmhooks.callback') +u.setconfig('hooks', 'changegroup.scm', 'python:scmhooks.postHook') +u.setconfig('hooks', 'pretxnchangegroup.scm', 'python:scmhooks.preHook') # pass SCM_HTTP_POST_ARGS to enable experimental httppostargs protocol of mercurial # SCM_HTTP_POST_ARGS is set by HgCGIServlet diff --git a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py index c64a63abfa..da4da7f742 100644 --- a/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py +++ b/scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/python/scmhooks.py @@ -85,9 +85,7 @@ def callHookUrl(ui, repo, hooktype, node): ui.traceback() return abort -def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): - if pending != None: - pending() +def callback(ui, repo, hooktype, node=None): abort = True if node != None: if len(baseUrl) > 0: @@ -98,3 +96,32 @@ def callback(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs) else: ui.warn("changeset node is not available") return abort + +def preHook(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): + log_file = open("/tmp/hg_callback.log", "a") + log_file.write("in callHookUrl\n") + log_file.close() + + # older mercurial versions + if pending != None: + pending() + + # newer mercurial version + # we have to make in-memory changes visible to external process + # this does not happen automatically, because mercurial treat our hooks as internal hooks + # see hook.py at mercurial sources _exthook + try: + if repo is not None: + tr = repo.currenttransaction() + repo.dirstate.write(tr) + if tr and not tr.writepending(): + ui.warn("no pending write transaction found") + except AttributeError: + ui.debug("mercurial does not support currenttransation") + # do nothing + + return callback(ui, repo, hooktype, node) + +def postHook(ui, repo, hooktype, node=None, source=None, pending=None, **kwargs): + return callback(ui, repo, hooktype, node) +