ui: do not translate empty configsource() to 'none' (API)
authorYuya Nishihara <yuya@tcha.org>
Sun, 23 Oct 2016 17:47:00 +0900
changeset 30618 201b44c8875c
parent 30617 32a07b8a9f77
child 30619 88efb4fb1975
ui: do not translate empty configsource() to 'none' (API) It should be processed when displaying data, so we can get "source": "" in JSON output.
mercurial/chgserver.py
mercurial/commands.py
mercurial/ui.py
tests/test-config.t
--- a/mercurial/chgserver.py	Sun Dec 18 16:20:04 2016 +0900
+++ b/mercurial/chgserver.py	Sun Oct 23 17:47:00 2016 +0900
@@ -271,9 +271,6 @@
         if ':' in source or source == '--config':
             # path:line or command line
             continue
-        if source == 'none':
-            # ui.configsource returns 'none' by default
-            source = ''
         newui.setconfig(section, name, value, source)
 
     # load wd and repo config, copied from dispatch.py
--- a/mercurial/commands.py	Sun Dec 18 16:20:04 2016 +0900
+++ b/mercurial/commands.py	Sun Oct 23 17:47:00 2016 +0900
@@ -1804,29 +1804,28 @@
             raise error.Abort(_('only one config item permitted'))
     matched = False
     for section, name, value in ui.walkconfig(untrusted=untrusted):
+        source = ui.configsource(section, name, untrusted)
         value = str(value)
         if fm.isplain():
+            source = source or 'none'
             value = value.replace('\n', '\\n')
         entryname = section + '.' + name
         if values:
             for v in values:
                 if v == section:
                     fm.startitem()
-                    fm.condwrite(ui.debugflag, 'source', '%s: ',
-                                 ui.configsource(section, name, untrusted))
+                    fm.condwrite(ui.debugflag, 'source', '%s: ', source)
                     fm.write('name value', '%s=%s\n', entryname, value)
                     matched = True
                 elif v == entryname:
                     fm.startitem()
-                    fm.condwrite(ui.debugflag, 'source', '%s: ',
-                                 ui.configsource(section, name, untrusted))
+                    fm.condwrite(ui.debugflag, 'source', '%s: ', source)
                     fm.write('value', '%s\n', value)
                     fm.data(name=entryname)
                     matched = True
         else:
             fm.startitem()
-            fm.condwrite(ui.debugflag, 'source', '%s: ',
-                         ui.configsource(section, name, untrusted))
+            fm.condwrite(ui.debugflag, 'source', '%s: ', source)
             fm.write('name value', '%s=%s\n', entryname, value)
             matched = True
     fm.end()
--- a/mercurial/ui.py	Sun Dec 18 16:20:04 2016 +0900
+++ b/mercurial/ui.py	Sun Oct 23 17:47:00 2016 +0900
@@ -249,8 +249,9 @@
                     if not p:
                         continue
                     if '%%' in p:
+                        s = self.configsource('paths', n) or 'none'
                         self.warn(_("(deprecated '%%' in path %s=%s from %s)\n")
-                                  % (n, p, self.configsource('paths', n)))
+                                  % (n, p, s))
                         p = p.replace('%%', '%')
                     p = util.expandpath(p)
                     if not util.hasscheme(p) and not os.path.isabs(p):
@@ -291,7 +292,7 @@
         return untrusted and self._ucfg or self._tcfg
 
     def configsource(self, section, name, untrusted=False):
-        return self._data(untrusted).source(section, name) or 'none'
+        return self._data(untrusted).source(section, name)
 
     def config(self, section, name, default=None, untrusted=False):
         if isinstance(name, list):
--- a/tests/test-config.t	Sun Dec 18 16:20:04 2016 +0900
+++ b/tests/test-config.t	Sun Oct 23 17:47:00 2016 +0900
@@ -84,6 +84,32 @@
    }
   ]
 
+Test empty config source:
+
+  $ cat <<EOF > emptysource.py
+  > def reposetup(ui, repo):
+  >     ui.setconfig('empty', 'source', 'value')
+  > EOF
+  $ cp .hg/hgrc .hg/hgrc.orig
+  $ cat <<EOF >> .hg/hgrc
+  > [extensions]
+  > emptysource = `pwd`/emptysource.py
+  > EOF
+
+  $ hg config --debug empty.source
+  read config from: * (glob)
+  none: value
+  $ hg config empty.source -Tjson
+  [
+   {
+    "name": "empty.source",
+    "source": "",
+    "value": "value"
+   }
+  ]
+
+  $ cp .hg/hgrc.orig .hg/hgrc
+
 Test "%unset"
 
   $ cat >> $HGRCPATH <<EOF