Mercurial 加载多个.hgrc文件-例如,一些具有特定于机器的设置?

Mercurial 加载多个.hgrc文件-例如,一些具有特定于机器的设置?,mercurial,hgrc,Mercurial,Hgrc,我想保留两个~/.hgrc文件:~/.hgrc和~/.hgrc.local–一个具有“标准”设置(例如,username),另一个具有特定于机器的设置(例如,设置图形合并工具) 我怎样才能用hg做到这一点 例如,我使用Vim就是这样做的: # ~/.vimrc syntax enable source ~/.vimrc.local 然后: Mercurial将在几个不同的位置查找hgrc文件,如果存在,将加载它们。对于系统范围的配置,标准(在UNIX上)是使用/etc/mercurial/hg

我想保留两个~/.hgrc文件:~/.hgrc和~/.hgrc.local–一个具有“标准”设置(例如,
username
),另一个具有特定于机器的设置(例如,设置图形合并工具)

我怎样才能用hg做到这一点

例如,我使用Vim就是这样做的:

# ~/.vimrc
syntax enable
source ~/.vimrc.local
然后:


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


有关更多信息,请参阅。

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

你应该可以走了。

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

mercurial检查具有特定优先级的多个配置文件。这样,您就可以拥有全局、特定于用户和特定于存储库的设置。 Mercurial version>=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帮助配置
配置文件
Mercurial从多个文件(如果存在)中读取配置数据。下面我们首先列出最具体的文件。
在Windows上,将读取以下配置文件:
-“\.hg\hgrc”
-%USERPROFILE%\.hgrc
-%USERPROFILE%\Mercurial.ini
-“%HOME%\.hgrc”
-%HOME%\Mercurial.ini
-“C:\Mercurial\Mercurial.ini”
-“HKEY\U本地\U机器\SOFTWARE\Mercurial”
-“\Mercurial.ini”
在Unix上,将读取以下文件:
-“/.hg/hgrc”
-“$HOME/.hgrc”
-“/etc/mercurial/hgrc”
-“/etc/mercurial/hgrc.d/*.rc”
-“/etc/mercurial/hgrc”
-“/etc/mercurial/hgrc.d/*.rc”
Mercurial的配置文件使用简单的ini文件格式。配置文件由节组成,以“[section]”标题开头,后跟
“名称=值”条目:
[用户界面]
用户名=Firstname Lastname
详细=正确
上述条目将分别称为“ui.username”和“ui.verbose”。请参阅hgrc手册页,以了解可能出现的问题的完整描述
配置值:
-在类Unix系统上:“man hgrc”
-在线:http://www.selenic.com/mercurial/hgrc.5.html

您可以使用
hg showconfig

列出当前设置。它看起来在几个不同的地方…但我需要在~,因为我的所有机器上都没有根目录。不赞成在不添加真实信息的情况下改写手册。你可以做得更好:)太棒了,太棒了——这正是我想要的。谢谢。哇,我不知道那是真的。Nice.Hrm,所以这真的很酷…但它不适用于hg 1.3.1或1.4.1…并且为“%import”对hg源代码树(1.4.1+7-4ddfad7ebd98)进行灰显不会出现任何结果。那么…您在哪里找到的?如果您还没有捕获到它,那么命令是“%include”,而不是“%import”。它第一次在mercurial.config.py类config.parse()中引用,关于第79行,在第102行实现。这是mercurial 1.3.1.嗯。。。我担心环境变量的替换只在某些时候起作用:-(也就是说,它在
[extensions]
部分起作用,在
ui中起作用。忽略
设置。但是我们还没有在
%中扩展变量,包括
路径,在
[paths]
部分也稍微中断了(它只适用于相对路径)。我会研究它!啊,这是一个好主意。谢谢!不幸的是,我看到了…它没有回答问题。同意答案没有100%回答你的问题。但是否决票?来吧。
$ 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