[PATCH] util.system: Clear environment vars before deleting - just in case deletion fails

Mads Kiilerich mads at kiilerich.com
Tue Sep 8 19:12:07 CDT 2009


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1252455081 -7200
# Node ID 7b8ca6945311e48aac47ba4c80b376e006677789
# Parent  fef209e657579ddd0b87ed728f1fee8912960eab
util.system: Clear environment vars before deleting - just in case deletion fails

Environment variables can't (easily) be deleted in Python on solaris:

Python 2.6.2 (r262:71600, May 27 2009, 13:06:14) [C] on sunos5
>>> import os
>>> os.environ['x'] = 'y'
>>> os.system('echo $x')
y
0
>>> del os.environ['x']
>>> os.system('echo $x')
y
0
>>> os.unsetenv('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'unsetenv'
>>>

This change "fixes" an error on solaris found by test-hook. The HG_PENDING
variable survives being del'ed and was thus set for too many hooks. Setting it
to empty string makes printenv.py skip it anyway. I don't know if that makes it
a real fix ...

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -387,6 +387,7 @@
     finally:
         for k, v in oldenv.iteritems():
             if v is None:
+                os.environ[k] = ''
                 del os.environ[k]
             else:
                 os.environ[k] = v


More information about the Mercurial-devel mailing list