11

我想保留两个 ~/.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

4 回答 4

20

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

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

你应该很高兴。

于 2009-12-08T18:27:52.827 回答
5

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

于 2009-12-12T21:59:03.690 回答
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

于 2009-12-16T10:40:23.343 回答
0

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

有关更多信息,请参见hgrc 手册页的文件部分

于 2009-12-08T14:22:24.383 回答