[PATCH 3 of 3] localrepo: look at .hg/hgrc.d/*.rc after .hg/hgrc
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Tue Mar 11 01:57:28 CDT 2008
Matt, any chance of this making it into 1.0?
-peo
On Fri, Mar 7, 2008 at 8:50 AM, Peter Arrenbrecht
<peter.arrenbrecht at gmail.com> wrote:
> # HG changeset patch
> # User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
> # Date 1204872860 -3600
> # Node ID 32e4f0e1d53a8efba16efd8430ba1fe315e699ab
> # Parent 910b4e47de40bff1a9101bac984b1874d99723c8
> localrepo: look at .hg/hgrc.d/*.rc after .hg/hgrc
>
> This mimicks /etc/mercurial/hgrc.d/*.rc for .hg/hgrc.d/*.rc
> and allows one to use symlinks to factor out common config:
>
> /var/hg/repos/
> hgrc-clonable
> main/
> .hg/
> hgrc #contains description, contact
> hgrc.d/
> clonable.rc -> ../../../hgrc-clonable
>
> diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt
> --- a/doc/hgrc.5.txt
> +++ b/doc/hgrc.5.txt
> @@ -62,12 +62,13 @@ earlier ones.
> by this user in any directory. Options in thes files override
> per-installation and per-system options.
>
> +(Unix, Windows) <repo>/.hg/hgrc.d/*.rc::
> (Unix, Windows) <repo>/.hg/hgrc::
> Per-repository configuration options that only apply in a
> - particular repository. This file is not version-controlled, and
> + particular repository. These files are not version-controlled, and
> will not get transferred during a "clone" operation. Options in
> - this file override options in all other configuration files.
> - On Unix, most of this file will be ignored if it doesn't belong
> + these files override options in all other configuration files.
> + On Unix, most of these files will be ignored if they do not belong
> to a trusted user or to a trusted group. See the documentation
> for the trusted section below for more details.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -259,7 +259,7 @@ def _dispatch(ui, args):
> if path:
> try:
> lui = _ui.ui(parentui=ui)
> - lui.readconfig(os.path.join(path, ".hg", "hgrc"))
> + lui.readconfig(util.localrepo_rcpath(os.path.join(path, ".hg")), path)
> except IOError:
> pass
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -86,7 +86,7 @@ class localrepository(repo.repository):
>
> self.ui = ui.ui(parentui=parentui)
> try:
> - self.ui.readconfig(self.join("hgrc"), self.root)
> + self.ui.readconfig(util.localrepo_rcpath(self.path), self.root)
> extensions.loadall(self.ui)
> except IOError:
> pass
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -904,6 +904,21 @@ def lookup_reg(key, name=None, scope=Non
> def lookup_reg(key, name=None, scope=None):
> return None
>
> +def rcfiles(path):
> + rcs = []
> + rcdir = os.path.join(path, 'hgrc.d')
> + try:
> + rcs.extend([os.path.join(rcdir, f)
> + for f, kind in osutil.listdir(rcdir)
> + if f.endswith(".rc")])
> + except OSError:
> + pass
> + rcs.append(os.path.join(path, 'hgrc'))
> + return rcs
> +
> +def localrepo_rcpath(reporoot):
> + return rcfiles(reporoot)
> +
> # Platform specific variants
> if os.name == 'nt':
> import msvcrt
> @@ -1096,18 +1111,6 @@ if os.name == 'nt':
>
> else:
> nulldev = '/dev/null'
> -
> - def rcfiles(path):
> - rcs = []
> - rcdir = os.path.join(path, 'hgrc.d')
> - try:
> - rcs.extend([os.path.join(rcdir, f)
> - for f, kind in osutil.listdir(rcdir)
> - if f.endswith(".rc")])
> - except OSError:
> - pass
> - rcs.append(os.path.join(path, 'hgrc'))
> - return rcs
>
> def system_rcpath():
> path = []
> diff --git a/tests/test-hgrc b/tests/test-hgrc
> --- a/tests/test-hgrc
> +++ b/tests/test-hgrc
> @@ -1,7 +1,32 @@
> #!/bin/sh
>
> +echo "---- invalid config"
> mkdir t
> cd t
> hg init
> echo "invalid" > .hg/hgrc
> hg status 2>&1 |sed -e "s:/.*\(/t/.*\):...\1:"
> +cd ..
> +
> +echo "---- hgrc plus hgrc.d; hgrc has precedence; *.rc sorting later has precedence"
> +hg init r
> +cd r
> +echo "[alias]" > .hg/hgrc
> +echo "one = log" >> .hg/hgrc
> +
> +mkdir .hg/hgrc.d
> +
> +echo "[alias]" > .hg/hgrc.d/2.rc
> +echo "one = id" >> .hg/hgrc.d/2.rc
> +echo "two = id" >> .hg/hgrc.d/2.rc
> +echo "three = id" >> .hg/hgrc.d/2.rc
> +echo "four = id" >> .hg/hgrc.d/2.rc
> +
> +echo "[alias]" > .hg/hgrc.d/1.rc
> +echo "three = incoming" >> .hg/hgrc.d/1.rc
> +
> +echo "[alias]" > .hg/hgrc.d/3.rc
> +echo "four = outgoing" >> .hg/hgrc.d/3.rc
> +
> +hg showconfig | grep alias
> +cd ..
> diff --git a/tests/test-hgrc.out b/tests/test-hgrc.out
> --- a/tests/test-hgrc.out
> +++ b/tests/test-hgrc.out
> @@ -1,4 +1,10 @@ abort: Failed to parse .../t/.hg/hgrc
> +---- invalid config
> abort: Failed to parse .../t/.hg/hgrc
> File contains no section headers.
> file: .../t/.hg/hgrc, line: 1
> 'invalid\n'
> +---- hgrc plus hgrc.d; hgrc has precedence; *.rc sorting later has precedence
> +alias.four=outgoing
> +alias.one=log
> +alias.three=id
> +alias.two=id
>
More information about the Mercurial-devel
mailing list