diff -r 6fa245f80b6f -r 9fcb6df413c9 mercurial/ui.py --- a/mercurial/ui.py Thu Jun 15 15:13:18 2017 -0700 +++ b/mercurial/ui.py Wed Jun 14 20:56:34 2017 -0400 @@ -43,6 +43,20 @@ _keepalnum = ''.join(c for c in map(pycompat.bytechr, range(256)) if not c.isalnum()) +# The config knobs that will be altered (if unset) by ui.tweakdefaults. +tweakrc = """ +[ui] +# The rollback command is dangerous. As a rule, don't use it. +rollback = False + +[commands] +# Make `hg status` emit cwd-relative paths by default. +status.relative = yes + +[diff] +git = 1 +""" + samplehgrcs = { 'user': """# example user config (see 'hg help config' for more info) @@ -182,6 +196,7 @@ self.fin = src.fin self.pageractive = src.pageractive self._disablepager = src._disablepager + self._tweaked = src._tweaked self._tcfg = src._tcfg.copy() self._ucfg = src._ucfg.copy() @@ -205,6 +220,7 @@ self.fin = util.stdin self.pageractive = False self._disablepager = False + self._tweaked = False # shared read-only environment self.environ = encoding.environ @@ -241,8 +257,29 @@ u.fixconfig(section=section) else: raise error.ProgrammingError('unknown rctype: %s' % t) + u._maybetweakdefaults() return u + def _maybetweakdefaults(self): + if not self.configbool('ui', 'tweakdefaults'): + return + if self._tweaked or self.plain('tweakdefaults'): + return + + # Note: it is SUPER IMPORTANT that you set self._tweaked to + # True *before* any calls to setconfig(), otherwise you'll get + # infinite recursion between setconfig and this method. + # + # TODO: We should extract an inner method in setconfig() to + # avoid this weirdness. + self._tweaked = True + tmpcfg = config.config() + tmpcfg.parse('', tweakrc) + for section in tmpcfg: + for name, value in tmpcfg.items(section): + if not self.hasconfig(section, name): + self.setconfig(section, name, value, "") + def copy(self): return self.__class__(self) @@ -387,6 +424,7 @@ for cfg in (self._ocfg, self._tcfg, self._ucfg): cfg.set(section, name, value, source) self.fixconfig(section=section) + self._maybetweakdefaults() def _data(self, untrusted): return untrusted and self._ucfg or self._tcfg