comparison mercurial/commands.py @ 29950:80fef5251099

config: add template support V2: - Limit escaping to plain formatting only - Use the formatter consistently (no more ui.debug) - Always include 'name' and 'value' V3: - Always convert 'value' to string (this also makes sure we handle functions) - Keep real debug message as ui.debug for now - Add additional tests. Note: I'm not quite sure about the best approach to handling the 'print the full config' case. For me, it printed the 'ui.promptecho' key at the end. I went with globs there as that at least tests the json display reliably. Example output: [ { "name": "ui.username", "source": "/home/mathias/.hgrc:2", "value": "Mathias De Maré <mathias.demare@gmail.com>" } ]
author Mathias De Maré <mathias.demare@gmail.com>
date Mon, 29 Aug 2016 07:07:15 +0200
parents e7cacb45c4be
children b3100653bafd
comparison
equal deleted inserted replaced
29949:e7cacb45c4be 29950:80fef5251099
1786 1786
1787 @command('config|showconfig|debugconfig', 1787 @command('config|showconfig|debugconfig',
1788 [('u', 'untrusted', None, _('show untrusted configuration options')), 1788 [('u', 'untrusted', None, _('show untrusted configuration options')),
1789 ('e', 'edit', None, _('edit user config')), 1789 ('e', 'edit', None, _('edit user config')),
1790 ('l', 'local', None, _('edit repository config')), 1790 ('l', 'local', None, _('edit repository config')),
1791 ('g', 'global', None, _('edit global config'))], 1791 ('g', 'global', None, _('edit global config'))] + formatteropts,
1792 _('[-u] [NAME]...'), 1792 _('[-u] [NAME]...'),
1793 optionalrepo=True) 1793 optionalrepo=True)
1794 def config(ui, repo, *values, **opts): 1794 def config(ui, repo, *values, **opts):
1795 """show combined config settings from all hgrc files 1795 """show combined config settings from all hgrc files
1796 1796
1847 editor = ui.geteditor() 1847 editor = ui.geteditor()
1848 ui.system("%s \"%s\"" % (editor, f), 1848 ui.system("%s \"%s\"" % (editor, f),
1849 onerr=error.Abort, errprefix=_("edit failed")) 1849 onerr=error.Abort, errprefix=_("edit failed"))
1850 return 1850 return
1851 1851
1852 fm = ui.formatter('config', opts)
1852 for f in scmutil.rcpath(): 1853 for f in scmutil.rcpath():
1853 ui.debug('read config from: %s\n' % f) 1854 ui.debug('read config from: %s\n' % f)
1854 untrusted = bool(opts.get('untrusted')) 1855 untrusted = bool(opts.get('untrusted'))
1855 if values: 1856 if values:
1856 sections = [v for v in values if '.' not in v] 1857 sections = [v for v in values if '.' not in v]
1857 items = [v for v in values if '.' in v] 1858 items = [v for v in values if '.' in v]
1858 if len(items) > 1 or items and sections: 1859 if len(items) > 1 or items and sections:
1859 raise error.Abort(_('only one config item permitted')) 1860 raise error.Abort(_('only one config item permitted'))
1860 matched = False 1861 matched = False
1861 for section, name, value in ui.walkconfig(untrusted=untrusted): 1862 for section, name, value in ui.walkconfig(untrusted=untrusted):
1862 value = str(value).replace('\n', '\\n') 1863 value = str(value)
1863 sectname = section + '.' + name 1864 if fm.isplain():
1865 value = value.replace('\n', '\\n')
1866 entryname = section + '.' + name
1864 if values: 1867 if values:
1865 for v in values: 1868 for v in values:
1866 if v == section: 1869 if v == section:
1867 ui.debug('%s: ' % 1870 fm.startitem()
1868 ui.configsource(section, name, untrusted)) 1871 fm.condwrite(ui.debugflag, 'source', '%s: ',
1869 ui.write('%s=%s\n' % (sectname, value)) 1872 ui.configsource(section, name, untrusted))
1873 fm.write('name value', '%s=%s\n', entryname, value)
1870 matched = True 1874 matched = True
1871 elif v == sectname: 1875 elif v == entryname:
1872 ui.debug('%s: ' % 1876 fm.startitem()
1873 ui.configsource(section, name, untrusted)) 1877 fm.condwrite(ui.debugflag, 'source', '%s: ',
1874 ui.write(value, '\n') 1878 ui.configsource(section, name, untrusted))
1879 fm.write('value', '%s\n', value)
1880 fm.data(name=entryname)
1875 matched = True 1881 matched = True
1876 else: 1882 else:
1877 ui.debug('%s: ' % 1883 fm.startitem()
1878 ui.configsource(section, name, untrusted)) 1884 fm.condwrite(ui.debugflag, 'source', '%s: ',
1879 ui.write('%s=%s\n' % (sectname, value)) 1885 ui.configsource(section, name, untrusted))
1886 fm.write('name value', '%s=%s\n', entryname, value)
1880 matched = True 1887 matched = True
1888 fm.end()
1881 if matched: 1889 if matched:
1882 return 0 1890 return 0
1883 return 1 1891 return 1
1884 1892
1885 @command('copy|cp', 1893 @command('copy|cp',