Submitter | David Demelier |
---|---|
Date | Feb. 14, 2017, 2:59 p.m. |
Message ID | <6d0ac5283a0dfa1dc52b.1487084373@localhost.localdomain> |
Download | mbox | patch |
Permalink | /patch/18470/ |
State | Accepted |
Headers | show |
Comments
On Tue, Feb 14, 2017 at 03:59:33PM +0100, David Demelier wrote: > # HG changeset patch > # User David Demelier <demelier.david@gmail.com> > # Date 1486485215 -3600 > # Tue Feb 07 17:33:35 2017 +0100 > # Node ID 6d0ac5283a0dfa1dc52b7a29342f73e0a0bf77b4 > # Parent 1f51b4658f21bbb797e922d155c1046eddccf91d > hg: allow usage of XDG_CONFIG_HOME/hg/hgrc Queued, thanks for working through the backwards compatibility concerns and sticking with it. Congratulations on your first Mercurial patch! > > 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 1f51b4658f21 -r 6d0ac5283a0d mercurial/help/config.txt > --- a/mercurial/help/config.txt Thu Feb 02 14:19:48 2017 +0100 > +++ b/mercurial/help/config.txt Tue Feb 07 17:33:35 2017 +0100 > @@ -56,6 +56,7 @@ > > - ``<repo>/.hg/hgrc`` (per-repository) > - ``$HOME/.hgrc`` (per-user) > + - ``${XDG_CONFIG_HOME:-$HOME/.config}/hg/hgrc`` (per-user) > - ``<install-root>/etc/mercurial/hgrc`` (per-installation) > - ``<install-root>/etc/mercurial/hgrc.d/*.rc`` (per-installation) > - ``/etc/mercurial/hgrc`` (per-system) > diff -r 1f51b4658f21 -r 6d0ac5283a0d mercurial/scmposix.py > --- a/mercurial/scmposix.py Thu Feb 02 14:19:48 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 1f51b4658f21 -r 6d0ac5283a0d 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 > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Patch
diff -r 1f51b4658f21 -r 6d0ac5283a0d mercurial/help/config.txt --- a/mercurial/help/config.txt Thu Feb 02 14:19:48 2017 +0100 +++ b/mercurial/help/config.txt Tue Feb 07 17:33:35 2017 +0100 @@ -56,6 +56,7 @@ - ``<repo>/.hg/hgrc`` (per-repository) - ``$HOME/.hgrc`` (per-user) + - ``${XDG_CONFIG_HOME:-$HOME/.config}/hg/hgrc`` (per-user) - ``<install-root>/etc/mercurial/hgrc`` (per-installation) - ``<install-root>/etc/mercurial/hgrc.d/*.rc`` (per-installation) - ``/etc/mercurial/hgrc`` (per-system) diff -r 1f51b4658f21 -r 6d0ac5283a0d mercurial/scmposix.py --- a/mercurial/scmposix.py Thu Feb 02 14:19:48 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 1f51b4658f21 -r 6d0ac5283a0d 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