# HG changeset patch # User FUJIWARA Katsunori # Date 1366986972 -32400 # 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 -r 8fb8dce3f9b6 -r 7d82ad4b3727 mercurial/config.py --- 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))) diff -r 8fb8dce3f9b6 -r 7d82ad4b3727 tests/test-config.t --- 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 < [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 < [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)