# HG changeset patch # User Pierre-Yves David # Date 2021-02-10 22:21:21 # Node ID 7289eac777eca454dbc08f2c0cbe1b368b1b2ae1 # Parent 0760282995cf781e24e678459e2bf633b3eb5729 hooks: introduce a `:run-with-plain` option for hooks This option control if HGPLAIN should be set or not for the hooks. This is the first step to give user some control of the HGPLAIN setting for they hooks. Some hooks (eg: consistency checking) deserve to be run with HGPLAIN, some other (eg: user set visual helper) might need to respect the user config and setting. So both usage are valid and we need to restore the ability to run -without- HGPLAIN that got lost in Mercurial 5.7. This does not offer a way to restore the pre-5.7 behavior yet (respect whatever HGPLAIN setting from the shell), this will be dealt with in the next changeset. The option name is a bit verbose because implementing this highlighs the need for another option: `:run-if-plain`. That would make it possible for some hooks to be easily disabled if HG PLAIN is set. However such option would be a new feature, not something introduced to mitigate a behavior change introduced in 5.7, so the `:run-if-plain` option belong to the default branch and is not part of this series. Differential Revision: https://phab.mercurial-scm.org/D9981 diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1315,6 +1315,12 @@ coreconfigitem( generic=True, ) coreconfigitem( + b'hooks', + b'.*:run-with-plain', + default=True, + generic=True, +) +coreconfigitem( b'hgweb-paths', b'.*', default=list, diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt --- a/mercurial/helptext/config.txt +++ b/mercurial/helptext/config.txt @@ -1027,6 +1027,11 @@ Example ``.hg/hgrc``:: incoming.autobuild = /my/build/hook # force autobuild hook to run before other incoming hooks priority.incoming.autobuild = 1 + ### control HGPLAIN setting when running autobuild hook + # HGPLAIN always set (default from Mercurial 5.7) + incoming.autobuild:run-with-plain = yes + # HGPLAIN never set + incoming.autobuild:run-with-plain = no Most hooks are run with environment variables set that give useful additional information. For each hook below, the environment variables diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -157,7 +157,12 @@ def _exthook(ui, repo, htype, name, cmd, env[b'HG_PENDING'] = repo.root env[b'HG_HOOKTYPE'] = htype env[b'HG_HOOKNAME'] = name - env[b'HGPLAIN'] = b'1' + + plain = ui.configbool(b'hooks', b'%s:run-with-plain' % name) + if plain: + env[b'HGPLAIN'] = b'1' + else: + env[b'HGPLAIN'] = b'' for k, v in pycompat.iteritems(args): # transaction changes can accumulate MBs of data, so skip it diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -1407,13 +1407,21 @@ HGPLAIN setting in hooks $ cat << EOF >> .hg/hgrc > [hooks] - > pre-version.testing-default=echo '### default ###' plain: \$HGPLAIN + > pre-version.testing-default=echo '### default ###' plain: \${HGPLAIN:-''} + > pre-version.testing-yes=echo '### yes #######' plain: \${HGPLAIN:-''} + > pre-version.testing-yes:run-with-plain=yes + > pre-version.testing-no=echo '### no ########' plain: \${HGPLAIN:-''} + > pre-version.testing-no:run-with-plain=no > EOF $ (unset HGPLAIN; hg version --quiet) ### default ### plain: 1 + ### yes ####### plain: 1 + ### no ######## plain: Mercurial Distributed SCM (*) (glob) $ HGPLAIN=1 hg version --quiet ### default ### plain: 1 + ### yes ####### plain: 1 + ### no ######## plain: Mercurial Distributed SCM (*) (glob)