[PATCH] ui: do not translate empty configsource() to 'none' (API)

Augie Fackler raf at durin42.com
Mon Dec 19 16:33:40 EST 2016


On Sun, Dec 18, 2016 at 06:54:27PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1477212420 -32400
> #      Sun Oct 23 17:47:00 2016 +0900
> # Node ID f2565fc73557e6cbf78119da2953bfae6d457f94
> # Parent  7d505a99f16d0a7faae231432deef5c9bcfd3ad1
> ui: do not translate empty configsource() to 'none' (API)

Sure, queued, thanks.

>
> It should be processed when displaying data, so we can get "source": "" in
> JSON output.
>
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -271,9 +271,6 @@ def _loadnewui(srcui, args):
>          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
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1804,29 +1804,28 @@ def config(ui, repo, *values, **opts):
>              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()
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -249,8 +249,9 @@ class ui(object):
>                      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 @@ class ui(object):
>          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):
> diff --git a/tests/test-config.t b/tests/test-config.t
> --- a/tests/test-config.t
> +++ b/tests/test-config.t
> @@ -84,6 +84,32 @@ Test case sensitive configuration
>     }
>    ]
>
> +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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list