[PATCH 2 of 2 STABLE] config: discard "%unset" values defined in the other files read in previously

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Apr 26 09:38:28 CDT 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1366986972 -32400
#      Fri Apr 26 23:36:12 2013 +0900
# Branch stable
# Node ID 7d82ad4b37276430786a32103f293396aa1ea45c
# Parent  8fb8dce3f9b6ca126bcef2780befc3d3093d4b6b
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()".

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -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)))
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -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)


More information about the Mercurial-devel mailing list