D9981: hooks: introduce a `:run-with-plain` option for hooks

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Wed Feb 10 23:47:41 UTC 2021


marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D9981

AFFECTED FILES
  mercurial/configitems.py
  mercurial/hook.py
  tests/test-hook.t

CHANGE DETAILS

diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -1404,12 +1404,20 @@
   $ cat << EOF >> .hg/hgrc
   > [hooks]
   > 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)
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -157,7 +157,12 @@
             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'] = procutil.UNSET_ENV
 
     for k, v in pycompat.iteritems(args):
         # transaction changes can accumulate MBs of data, so skip it
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1315,6 +1315,12 @@
     generic=True,
 )
 coreconfigitem(
+    b'hooks',
+    b'.*:run-with-plain',
+    default=True,
+    generic=True,
+)
+coreconfigitem(
     b'hgweb-paths',
     b'.*',
     default=list,



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list