加载多个.hgrc文件 - 即一些具有机器特定的设置?

时间:2009-12-08 14:15:31

标签: mercurial hgrc

我想保留两个〜/ .hgrc文件:〜/ .hgrc和〜/ .hgrc.local - 一个带有“标准”设置(例如username),另一个带有机器专用设置(例如,设置图形合并工具)。

我怎么能用hg做这个?

例如,这就是我用Vim做的方式:

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

然后:

# ~/.vimrc.local
let work_code = 'code/work/.*'
if expand('%:p:h') =~ work_code ... fi

4 个答案:

答案 0 :(得分:20)

在mercurial 1.3及更高版本中有一个不经常使用的%include指令:

来自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.

所以请继续:

   %include ~/.hgrc.local

你应该好好去。

答案 1 :(得分:5)

我以类似的方式为所有“点文件”解决了这个问题。在登录时,我的shell检查文件列表(hgrc,vimrc,....)并检查它们中的任何一个是否早于${that_name}.global${that_name}.local。如果是 - cat ${that_name}.{global,local} > ${that_name}。简单,到目前为止工作得很好。虽然有一种“更好”的方式(使用%include),但有时手动处理配置文件具有优势 - 例如它可以在mercurial 1.3之前使用。

答案 2 :(得分:4)

Mercurial会检查具有特定优先级的许多配置文件。这样,您可以拥有全局,特定于用户和存储库的设置。 Mercurial版本> = 1.4有一个hg help config命令,它在一个很好的概述中描述了这个:

$ 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 <firstname.lastname@example.net>
      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

您可以使用hg showconfig列出当前设置。

答案 3 :(得分:0)

Mercurial会查看hgrc个文件的几个不同位置,如果存在则会加载它们。对于系统范围的配置,标准(在UNIX上)将使用/etc/mercurial/hgrc

有关详细信息,请参阅files section of the hgrc man page