changeset 19087:7d82ad4b3727 stable

config: discard "%unset" values defined in the other files read in previously Before this patch, "%unset" can't unset values defined in the other files read in previously, even though online help document says that it can. It can unset only values defined in the same configuration file. For example, the value defined in "~/.hgrc" can't be unset by "%unset" in ".hg/hgrc" of the repository. This patch records "%unset"-ed values in "config.parse()", and discards corresponding values in "config.update()".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 26 Apr 2013 23:36:12 +0900
parents 8fb8dce3f9b6
children ce4472b2edb2
files mercurial/config.py tests/test-config.t
diffstat 2 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/config.py	Fri Apr 26 23:16:25 2013 +0900
+++ b/mercurial/config.py	Fri Apr 26 23:36:12 2013 +0900
@@ -44,6 +44,7 @@
     def __init__(self, data=None):
         self._data = {}
         self._source = {}
+        self._unset = []
         if data:
             for k in data._data:
                 self._data[k] = data[k].copy()
@@ -58,6 +59,10 @@
         for d in self.sections():
             yield d
     def update(self, src):
+        for s, n in src._unset:
+            if s in self and n in self._data[s]:
+                del self._data[s][n]
+                del self._source[(s, n)]
         for s in src:
             if s not in self:
                 self._data[s] = sortdict()
@@ -173,6 +178,7 @@
                     continue
                 if self.get(section, name) is not None:
                     del self._data[section][name]
+                self._unset.append((section, name))
                 continue
 
             raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line)))
--- a/tests/test-config.t	Fri Apr 26 23:16:25 2013 +0900
+++ b/tests/test-config.t	Fri Apr 26 23:36:12 2013 +0900
@@ -11,3 +11,34 @@
   Section.KeY=Case Sensitive
   Section.key=lower case
 
+Test "%unset"
+
+  $ cat >> $HGRCPATH <<EOF
+  > [unsettest]
+  > local-hgrcpath = should be unset (HGRCPATH)
+  > %unset local-hgrcpath
+  > 
+  > global = should be unset (HGRCPATH)
+  > 
+  > both = should be unset (HGRCPATH)
+  > 
+  > set-after-unset = should be unset (HGRCPATH)
+  > EOF
+
+  $ cat >> .hg/hgrc <<EOF
+  > [unsettest]
+  > local-hgrc = should be unset (.hg/hgrc)
+  > %unset local-hgrc
+  > 
+  > %unset global
+  > 
+  > both = should be unset (.hg/hgrc)
+  > %unset both
+  > 
+  > set-after-unset = should be unset (.hg/hgrc)
+  > %unset set-after-unset
+  > set-after-unset = should be set (.hg/hgrc)
+  > EOF
+
+  $ hg showconfig unsettest
+  unsettest.set-after-unset=should be set (.hg/hgrc)