[PATCH] hg: allow usage of XDG_CONFIG_HOME and $HOME/.config/hgrc

David Demelier demelier.david at gmail.com
Wed Feb 8 04:22:55 EST 2017


Le 07/02/2017 à 17:52, David Demelier a écrit :
> # HG changeset patch
> # User David Demelier <demelier.david at gmail.com>
> # Date 1486485215 -3600
> #      Tue Feb 07 17:33:35 2017 +0100
> # Node ID 699fb7d08bdf2329fdb64df56e72d6c07cd91285
> # Parent  1f51b4658f21bbb797e922d155c1046eddccf91d
> hg: allow usage of XDG_CONFIG_HOME and $HOME/.config/hgrc
>
> Modern applications must use the following paths to store configuration files:
>
>   - $XDG_CONFIG_HOME/hgrc
>   - $HOME/.config/hgrc (if XDG_CONFIG_HOME is not set)
>
> For convenience, these paths are now evaluated first and the old $HOME/.hgrc is
> used as a fallback.
>
> See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
>
> diff -r 1f51b4658f21 -r 699fb7d08bdf 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
> @@ -55,6 +55,8 @@
>    On Unix, the following files are consulted:
>
>    - ``<repo>/.hg/hgrc`` (per-repository)
> +  - ``$XDG_CONFIG_HOME/hgrc`` (per-user)
> +  - ``$HOME/.config/hgrc`` (per-user)
>    - ``$HOME/.hgrc`` (per-user)
>    - ``<install-root>/etc/mercurial/hgrc`` (per-installation)
>    - ``<install-root>/etc/mercurial/hgrc.d/*.rc`` (per-installation)
> diff -r 1f51b4658f21 -r 699fb7d08bdf 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
> @@ -41,7 +41,15 @@
>      if pycompat.sysplatform == 'plan9':
>          return [encoding.environ['home'] + '/lib/hgrc']
>      else:
> -        return [os.path.expanduser('~/.hgrc')]
> +        xdg = encoding.environ.get("XDG_CONFIG_HOME")
> +        if xdg is not None:
> +            return [os.path.join(xdg, "hgrc")]
> +        else:
> +            cfg = os.path.expanduser("~/.config/hgrc")
> +            if os.path.isfile(cfg):
> +                return [cfg]
> +            else:
> +                return [os.path.expanduser('~/.hgrc')]
>
>  def termsize(ui):
>      try:
>

I wanted to add the following tests but could not get it to work:

$ cat tests/test-xdg.t
   $ mkdir xdgconf
   $ echo '[ui]' > xdgconf/hgrc
   $ echo 'username = foobar' >> xdgconf/hgrc
   $ XDG_CONFIG_HOME=xdgconf; export XDG_CONFIG_HOME
   $ hg config ui.username
   foobar

I've tried the following:

make PYTHON=python2.7 local
cd tests
python2.7 run-tests.py --local test-xdg.t

--- /home/markand/hg/tests/test-xdg.t
+++ /home/markand/hg/tests/test-xdg.t.err
@@ -3,4 +3,4 @@
    $ echo 'username = foobar' >> xdgconf/hgrc
    $ XDG_CONFIG_HOME=xdgconf; export XDG_CONFIG_HOME
    $ hg config ui.username
-  foobar
+  [1]

ERROR: test-xdg.t output changed
!
Failed test-xdg.t: output changed
# Ran 1 tests, 0 skipped, 0 warned, 1 failed.
python hash seed: 3897982799

But once installed; it works.


More information about the Mercurial-devel mailing list