sapling/hgext3rd/configwarn.py
Jun Wu ba4766820a configwarn: new extension to warn about unsupported configs
We have seen issues caused by user config file (`~/.hgrc`) having
unsupported extensions enabled. This new extension would allow us to warn
users about those problematic configs.

Differential Revision: https://phab.mercurial-scm.org/D154
2017-08-07 13:16:09 -07:00

54 lines
1.5 KiB
Python

# configwarn.py - warn unsupported user configs
#
# Copyright 2017 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""warn unsupported user configs
Config::
[configwarn]
# Config names that are supposed to be set by system config and not
# overrided by user config.
systemconfigs = diff.git, extensions.hggit
"""
from __future__ import absolute_import
from mercurial.i18n import _
from mercurial import (
rcutil,
registrar,
)
configtable = {}
configitem = registrar.configitem(configtable)
configitem('configwarn', 'systemconfigs', default=[])
def reposetup(ui, repo):
# use reposetup, not uisetup to work better with chg and it checks reporc.
if not repo.local():
return
nonsystempaths = set(rcutil.userrcpath() + [repo.vfs.join('hgrc')])
systemconfigs = ui.configlist('configwarn', 'systemconfigs')
for configname in systemconfigs:
if '.' not in configname:
continue
section, name = configname.split('.', 1)
source = ui.configsource(section, name)
if ':' not in source:
continue
path, lineno = source.split(':', 1)
if path in nonsystempaths and lineno.isdigit():
ui.warn(_('warning: overriding config %s is unsupported (hint: '
'remove line %s from %s to resolve this issue)\n')
% (configname, lineno, path))