Load multiple .hgrc files - ie, some with machine-specific settings?
Asked Answered
T

4

12

I'd like to keep two ~/.hgrc files: ~/.hgrc and ~/.hgrc.local – one with "standard" settings (eg, username), the other with machine-specific settings (eg, setting a graphical merge tool).

How can I do this with hg?

For example, this is how I do it with Vim:

# ~/.vimrc
syntax enable
source ~/.vimrc.local

Then:

# ~/.vimrc.local
let work_code = 'code/work/.*'
if expand('%:p:h') =~ work_code ... fi
Thine answered 8/12, 2009 at 14:15 Comment(0)
B
20

There's a not-often used %include directive in mercurial 1.3 and later:

From man hgrc:

   A  line  of  the  form %include file will include file into the current
   configuration file.  The  inclusion  is  recursive,  which  means  that
   included  files  can include other files. Filenames are relative to the
   configuration file in which the %include directive is found.

so go with:

   %include ~/.hgrc.local

and you should be good to go.

Beata answered 8/12, 2009 at 18:27 Comment(5)
Wow, I had no idea that existed. Nice.Benoit
Hrm, so that would be really cool… But it doesn't work with hg 1.3.1 or 1.4.1… And grepping the hg source tree (1.4.1+7-4ddfad7ebd98) for '%import' doesn't turn anything up. So… Where'd you find that?Thine
In case you haven't already caught it, the command is '%include', not '%import'. It's first referenced in mercurial.config.py, class config.parse(), about line 79 and implemented at about line 102. This is in mercurial 1.3.1.Monomania
Ehm... I'm afraid substitution of environment variables only work some times :-( That is, it works in the [extensions] section and it works for the ui.ignore setting. But we're not yet expanding variables in %include paths and it's also slightly broken in the [paths] section (it only works with a relative path). I'll look into it!Amalia
... well, to say I feel like an idiot would be an understatement. Thanks for being gentle in pointing out my ignorance (I hadn't noticed that it's %include not %import)Thine
U
5

I solve this problem for all my "dot files" in a similar way. On login my shell checks a list of files (hgrc, vimrc, ....) and checks if any of them is older than ${that_name}.global or ${that_name}.local. If it is - cat ${that_name}.{global,local} > ${that_name}. Simple and works great so far. While there's a "better" way (using %include) sometimes processing the config files manually has advantages - for example it will work with mercurial pre-1.3.

Uncivilized answered 12/12, 2009 at 21:59 Comment(0)
D
4

Mercurial checks for a number of configuration files with a specific priority. This way you can have global, user-specific and repository-specific settings. Mercurial version >= 1.4 has a hg help config command which describes this in a nice overview:

$ hg help config
Configuration Files

    Mercurial reads configuration data from several files, if they exist. Below we list the most specific file first.

    On Windows, these configuration files are read:

    - "<repo>\.hg\hgrc"
    - "%USERPROFILE%\.hgrc"
    - "%USERPROFILE%\Mercurial.ini"
    - "%HOME%\.hgrc"
    - "%HOME%\Mercurial.ini"
    - "C:\Mercurial\Mercurial.ini"
    - "HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial"
    - "<install-dir>\Mercurial.ini"

    On Unix, these files are read:

    - "<repo>/.hg/hgrc"
    - "$HOME/.hgrc"
    - "/etc/mercurial/hgrc"
    - "/etc/mercurial/hgrc.d/*.rc"
    - "<install-root>/etc/mercurial/hgrc"
    - "<install-root>/etc/mercurial/hgrc.d/*.rc"

    The configuration files for Mercurial use a simple ini-file format. A configuration file consists of sections, led by a "[section]" header and followed by
    "name = value" entries:

      [ui]
      username = Firstname Lastname <[email protected]>
      verbose = True

    This above entries will be referred to as "ui.username" and "ui.verbose", respectively. Please see the hgrc man page for a full description of the possible
    configuration values:

    - on Unix-like systems: "man hgrc"
    - online: http://www.selenic.com/mercurial/hgrc.5.html

You can list your current settings with hg showconfig.

Dibble answered 16/12, 2009 at 10:40 Comment(2)
Unfortunately I've seen that… And it doesn't answer the question.Thine
Agreed that the answer does not 100% answer your question. But a down vote? Come on.Dibble
B
0

Mercurial will look in several different locations for hgrc files and will load them if present. For system-wide configuration the standard (on UNIX) would be to use /etc/mercurial/hgrc.

See the files section of the hgrc man page for more information.

Benoit answered 8/12, 2009 at 14:22 Comment(2)
It looks in a few different places… But I need to have both config files in ~, because I don't don't have root on all my machines.Thine
downvoted for paraphrasing the manual without adding real information. You can do better :)Hexapartite

© 2022 - 2024 — McMap. All rights reserved.