Patchwork D9980: procutil: add a way to unset and environment variable

login
register
mail settings
Submitter phabricator
Date Feb. 10, 2021, 11:47 p.m.
Message ID <differential-rev-PHID-DREV-d4sprmnaimyh47tm3ept-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48295/
State Superseded
Headers show

Comments

phabricator - Feb. 10, 2021, 11:47 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The only way to not get the HGPLAIN behavior, is to not have the variable set at
  all. Having it set with -any- value will trigger the behavior.
  
  Currently the procutil utility used to spawn the hook have no way to unset an
  environment variable. So we start with adding one such way before we can
  proceed.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -42,6 +42,8 @@ 
 else:
     from .. import posix as platform
 
+UNSET_ENV = object()
+
 
 def isatty(fp):
     try:
@@ -466,7 +468,11 @@ 
 
     env = dict(encoding.environ)
     if environ:
-        env.update((k, py2shell(v)) for k, v in pycompat.iteritems(environ))
+        for k, v in pycompat.iteritems(environ):
+            if v is UNSET_ENV:
+                env.pop(k, None)
+            else:
+                env[k] = py2shell(v)
     env[b'HG'] = hgexecutable()
     return env