Patchwork D9924: config: use a new `alter` method in `fixconfig`

login
register
mail settings
Submitter phabricator
Date Jan. 30, 2021, 1:40 a.m.
Message ID <differential-rev-PHID-DREV-7rtw7m7qrtozgsxuvo55-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48236/
State Superseded
Headers show

Comments

phabricator - Jan. 30, 2021, 1:40 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `set` function is doing various work related to metadata (eg: the source,
  later the level). However the `fixconfig` call only updating some values
  according to standard processing, not changing any of the related metadata. So
  we introduce a new method and use it there.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/config.py
  mercurial/ui.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -556,7 +556,7 @@ 
                     p = util.expandpath(p)
                     if not util.hasscheme(p) and not os.path.isabs(p):
                         p = os.path.normpath(os.path.join(root, p))
-                    c.set(b"paths", n, p)
+                    c.alter(b"paths", n, p)
 
         if section in (None, b'ui'):
             # update ui options
diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -108,6 +108,14 @@ 
             self._source = self._source.preparewrite()
             self._source[(section, item)] = source
 
+    def alter(self, section, key, new_value):
+        """alter a value, to be used by `ui.fixconfig`"""
+        item = self._data[section][key]
+        size = len(item)
+        new_item = (new_value,) + item[1:]
+        assert len(new_item) == size
+        self._data[section][key] = new_item
+
     def restore(self, data):
         """restore data returned by self.backup"""
         self._source = self._source.preparewrite()