# HG changeset patch # User David Demelier # Date 1486485215 -3600 # Node ID 354020079723e02ad6db68f58ef26eb7ebd005a8 # Parent c8081ea6359123ee74a8172db6100d843015c010 hg: allow usage of XDG_CONFIG_HOME/hg/hgrc Modern applications must use the following paths to store configuration files: - $XDG_CONFIG_HOME/hg/hgrc, - $HOME/.config/hg/hgrc (if XDG_CONFIG_HOME is unset or not absolute). For backward compatibility, ~/.hgrc is still created if no hgrc exist using hg config --edit. See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html diff -r c8081ea63591 -r 354020079723 mercurial/help/config.txt --- a/mercurial/help/config.txt Wed Feb 01 17:47:35 2017 +0100 +++ b/mercurial/help/config.txt Tue Feb 07 17:33:35 2017 +0100 @@ -56,6 +56,7 @@ - ``/.hg/hgrc`` (per-repository) - ``$HOME/.hgrc`` (per-user) + - ``${XDG_CONFIG_HOME:-$HOME/.config}/hg/hgrc`` (per-user) - ``/etc/mercurial/hgrc`` (per-installation) - ``/etc/mercurial/hgrc.d/*.rc`` (per-installation) - ``/etc/mercurial/hgrc`` (per-system) diff -r c8081ea63591 -r 354020079723 mercurial/scmposix.py --- a/mercurial/scmposix.py Wed Feb 01 17:47:35 2017 +0100 +++ b/mercurial/scmposix.py Tue Feb 07 17:33:35 2017 +0100 @@ -40,8 +40,15 @@ def userrcpath(): if pycompat.sysplatform == 'plan9': return [encoding.environ['home'] + '/lib/hgrc'] + elif pycompat.sysplatform == 'darwin': + return [os.path.expanduser('~/.hgrc')] else: - return [os.path.expanduser('~/.hgrc')] + confighome = encoding.environ.get('XDG_CONFIG_HOME') + if confighome is None or not os.path.isabs(confighome): + confighome = os.path.expanduser('~/.config') + + return [os.path.expanduser('~/.hgrc'), + os.path.join(confighome, 'hg', 'hgrc')] def termsize(ui): try: diff -r c8081ea63591 -r 354020079723 tests/test-xdg.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-xdg.t Tue Feb 07 17:33:35 2017 +0100 @@ -0,0 +1,11 @@ +#if no-windows no-osx + + $ mkdir -p xdgconf/hg + $ echo '[ui]' > xdgconf/hg/hgrc + $ echo 'username = foobar' >> xdgconf/hg/hgrc + $ XDG_CONFIG_HOME="`pwd`/xdgconf" ; export XDG_CONFIG_HOME + $ unset HGRCPATH + $ hg config ui.username + foobar + +#endif