# HG changeset patch # User Pierre-Yves David # Date 1617980679 -7200 # Node ID b1b3127227bed218bfded147414966db3c265131 # Parent 5fbac82a8780732e223135a01f79f7770f4897f2 config: add an experimental option to list all known config That option is not ready for prime-time, hence the `exp-` prefix. However, this is a good base to start going toward completion. This is also quite useful for developer on its own for now. Differential Revision: https://phab.mercurial-scm.org/D10356 diff -r 5fbac82a8780 -r b1b3127227be mercurial/commands.py --- a/mercurial/commands.py Sat Jun 12 00:51:34 2021 -0400 +++ b/mercurial/commands.py Fri Apr 09 17:04:39 2021 +0200 @@ -2200,6 +2200,21 @@ b'config|showconfig|debugconfig', [ (b'u', b'untrusted', None, _(b'show untrusted configuration options')), + # This is experimental because we need + # * reasonable behavior around aliases, + # * decide if we display [debug] [experimental] and [devel] section par + # default + # * some way to display "generic" config entry (the one matching + # regexp, + # * proper display of the different value type + # * a better way to handle values (and variable types), + # * maybe some type information ? + ( + b'', + b'exp-all-known', + None, + _(b'show all known config option (EXPERIMENTAL)'), + ), (b'e', b'edit', None, _(b'edit user config')), (b'l', b'local', None, _(b'edit repository config')), (b'', b'source', None, _(b'show source of configuration value')), @@ -2336,8 +2351,10 @@ selentries = set(selentries) matched = False + all_known = opts[b'exp_all_known'] show_source = ui.debugflag or opts.get(b'source') - for section, name, value in ui.walkconfig(untrusted=untrusted): + entries = ui.walkconfig(untrusted=untrusted, all_known=all_known) + for section, name, value in entries: source = ui.configsource(section, name, untrusted) value = pycompat.bytestr(value) defaultvalue = ui.configdefault(section, name) diff -r 5fbac82a8780 -r b1b3127227be mercurial/ui.py --- a/mercurial/ui.py Sat Jun 12 00:51:34 2021 -0400 +++ b/mercurial/ui.py Fri Apr 09 17:04:39 2021 +0200 @@ -948,7 +948,48 @@ ) return items - def walkconfig(self, untrusted=False): + def walkconfig(self, untrusted=False, all_known=False): + defined = self._walk_config(untrusted) + if not all_known: + for d in defined: + yield d + return + known = self._walk_known() + current_defined = next(defined, None) + current_known = next(known, None) + while current_defined is not None or current_known is not None: + if current_defined is None: + yield current_known + current_known = next(known, None) + elif current_known is None: + yield current_defined + current_defined = next(defined, None) + elif current_known[0:2] == current_defined[0:2]: + yield current_defined + current_defined = next(defined, None) + current_known = next(known, None) + elif current_known[0:2] < current_defined[0:2]: + yield current_known + current_known = next(known, None) + else: + yield current_defined + current_defined = next(defined, None) + + def _walk_known(self): + for section, items in sorted(self._knownconfig.items()): + for k, i in sorted(items.items()): + # We don't have a way to display generic well, so skip them + if i.generic: + continue + if callable(i.default): + default = i.default() + elif i.default is configitems.dynamicdefault: + default = b'' + else: + default = i.default + yield section, i.name, default + + def _walk_config(self, untrusted): cfg = self._data(untrusted) for section in cfg.sections(): for name, value in self.configitems(section, untrusted): diff -r 5fbac82a8780 -r b1b3127227be tests/test-completion.t --- a/tests/test-completion.t Sat Jun 12 00:51:34 2021 -0400 +++ b/tests/test-completion.t Fri Apr 09 17:04:39 2021 +0200 @@ -262,7 +262,7 @@ cat: output, rev, decode, include, exclude, template clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure commit: addremove, close-branch, amend, secret, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos - config: untrusted, edit, local, source, shared, non-shared, global, template + config: untrusted, exp-all-known, edit, local, source, shared, non-shared, global, template continue: dry-run copy: forget, after, at-rev, force, include, exclude, dry-run debugancestor: diff -r 5fbac82a8780 -r b1b3127227be tests/test-config.t --- a/tests/test-config.t Sat Jun 12 00:51:34 2021 -0400 +++ b/tests/test-config.t Fri Apr 09 17:04:39 2021 +0200 @@ -408,6 +408,32 @@ $ HGRCPATH=configs hg config section.key 99 +Listing all config options +========================== + +The feature is experimental and behavior may varies. This test exists to make sure the code is run. We grep it to avoid too much variability in its current experimental state. + + $ hg config --exp-all-known | grep commit + commands.commit.interactive.git=False + commands.commit.interactive.ignoreblanklines=False + commands.commit.interactive.ignorews=False + commands.commit.interactive.ignorewsamount=False + commands.commit.interactive.ignorewseol=False + commands.commit.interactive.nobinary=False + commands.commit.interactive.nodates=False + commands.commit.interactive.noprefix=False + commands.commit.interactive.showfunc=False + commands.commit.interactive.unified=None + commands.commit.interactive.word-diff=False + commands.commit.post-status=False + convert.git.committeractions=[*'messagedifferent'] (glob) + convert.svn.dangerous-set-commit-dates=False + experimental.copytrace.sourcecommitlimit=100 + phases.new-commit=draft + ui.allowemptycommit=False + ui.commitsubrepos=False + + Configuration priority ======================