Author: | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
Organization: | Mercurial |
Manual section: | 5 |
Manual group: | Mercurial Manual |
The Mercurial system uses a set of configuration files to control aspects of its behavior.
The configuration files 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
The above entries will be referred to as ui.username and ui.verbose, respectively. See the Syntax section below.
Mercurial reads configuration data from several files, if they exist. These files do not exist by default and you will have to create the appropriate configuration files yourself: global configuration like the username setting is typically put into %USERPROFILE%\mercurial.ini or $HOME/.hgrc and local configuration is put into the per-repository <repo>/.hg/hgrc file.
The names of these files depend on the system on which Mercurial is installed. *.rc files from a single directory are read in alphabetical order, later ones overriding earlier ones. Where multiple paths are given below, settings from earlier paths override later ones.
On Unix, the following files are consulted:
On Windows, the following files are consulted:
Note
The registry key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mercurial is used when running 32-bit Python on 64-bit Windows.
On Plan9, the following files are consulted:
Per-repository configuration options only apply in a particular repository. This file is not version-controlled, and will not get transferred during a "clone" operation. Options in this file override options in all other configuration files. On Plan 9 and Unix, most of this file will be ignored if it doesn't belong to a trusted user or to a trusted group. See the documentation for the [trusted] section below for more details.
Per-user configuration file(s) are for the user running Mercurial. On Windows 9x, %HOME% is replaced by %APPDATA%. Options in these files apply to all Mercurial commands executed by this user in any directory. Options in these files override per-system and per-installation options.
Per-installation configuration files are searched for in the directory where Mercurial is installed. <install-root> is the parent directory of the hg executable (or symlink) being run. For example, if installed in /shared/tools/bin/hg, Mercurial will look in /shared/tools/etc/mercurial/hgrc. Options in these files apply to all Mercurial commands executed by any user in any directory.
Per-installation configuration files are for the system on which Mercurial is running. Options in these files apply to all Mercurial commands executed by any user in any directory. Registry keys contain PATH-like strings, every part of which must reference a Mercurial.ini file or be a directory where *.rc files will be read. Mercurial checks each of these locations in the specified order until one or more configuration files are detected.
Per-system configuration files are for the system on which Mercurial is running. Options in these files apply to all Mercurial commands executed by any user in any directory. Options in these files override per-installation options.
Mercurial comes with some default configuration. The default configuration files are installed with Mercurial and will be overwritten on upgrades. Default configuration files should never be edited by users or administrators but can be overridden in other configuration files. So far the directory only contains merge tool configuration but packagers can also put other default configuration there.
A configuration file consists of sections, led by a [section] header and followed by name = value entries (sometimes called configuration keys):
[spam] eggs=ham green= eggs
Each line contains one entry. If the lines that follow are indented, they are treated as continuations of that entry. Leading whitespace is removed from values. Empty lines are skipped. Lines beginning with # or ; are ignored and may be used to provide comments.
Configuration keys can be set multiple times, in which case Mercurial will use the value that was configured last. As an example:
[spam] eggs=large ham=serrano eggs=small
This would set the configuration key named eggs to small.
It is also possible to define a section multiple times. A section can be redefined on the same and/or on different configuration files. For example:
[foo] eggs=large ham=serrano eggs=small [bar] eggs=ham green= eggs [foo] ham=prosciutto eggs=medium bread=toasted
This would set the eggs, ham, and bread configuration keys of the foo section to medium, prosciutto, and toasted, respectively. As you can see there only thing that matters is the last value that was set for each of the configuration keys.
If a configuration key is set multiple times in different configuration files the final value will depend on the order in which the different configuration files are read, with settings from earlier paths overriding later ones as described on the Files section above.
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. Environment variables and ~user constructs are expanded in file. This lets you do something like:
%include ~/.hgrc.d/$HOST.rc
to include a different configuration file on each computer you use.
A line with %unset name will remove name from the current section, if it has been set previously.
The values are either free-form text strings, lists of text strings, or Boolean values. Boolean values can be set to true using any of "1", "yes", "true", or "on" and to false using "0", "no", "false", or "off" (all case insensitive).
List values are separated by whitespace or comma, except when values are placed in double quotation marks:
allow_read = "John Doe, PhD", brian, betty
Quotation marks can be escaped by prefixing them with a backslash. Only quotation marks at the beginning of a word is counted as a quotation (e.g., foo"bar baz is the list of foo"bar and baz).
This section describes the different sections that may appear in a Mercurial configuration file, the purpose of each section, its possible keys, and their possible values.
Defines command aliases. Aliases allow you to define your own commands in terms of other commands (or aliases), optionally including arguments. Positional arguments in the form of $1, $2, etc in the alias definition are expanded by Mercurial before execution. Positional arguments not already used by $N in the definition are put at the end of the command to be executed.
Alias definitions consist of lines of the form:
<alias> = <command> [<argument>]...
For example, this definition:
latest = log --limit 5
creates a new command latest that shows only the five most recent changesets. You can define subsequent aliases using earlier ones:
stable5 = latest -b stable
Note
It is possible to create aliases with the same names as existing commands, which will then override the original definitions. This is almost always a bad idea!
An alias can start with an exclamation point (!) to make it a shell alias. A shell alias is executed with the shell and will let you run arbitrary commands. As an example,
echo = !echo $@
will let you do hg echo foo to have foo printed in your terminal. A better example might be:
purge = !$HG status --no-status --unknown -0 | xargs -0 rm
which will make hg purge delete all unknown files in the repository in the same manner as the purge extension.
Positional arguments like $1, $2, etc. in the alias definition expand to the command arguments. Unmatched arguments are removed. $0 expands to the alias name and $@ expands to all arguments separated by a space. "$@" (with quotes) expands to all arguments quoted individually and separated by a space. These expansions happen before the command is passed to the shell.
Shell aliases are executed in an environment where $HG expands to the path of the Mercurial that was used to execute the alias. This is useful when you want to call further Mercurial commands in a shell alias, as was done above for the purge alias. In addition, $HG_ARGS expands to the arguments given to Mercurial. In the hg echo foo call above, $HG_ARGS would expand to echo foo.
Note
Some global configuration options such as -R are processed before shell aliases and will thus not be passed to aliases.
Settings used when displaying file annotations. All values are Booleans and default to False. See diff section for related options for the diff command.
Authentication credentials for HTTP authentication. This section allows you to store usernames and passwords for use when logging into HTTP servers. See the [web] configuration section if you want to configure who can login to your HTTP server.
Each line has the following format:
<name>.<argument> = <value>
where <name> is used to group arguments into authentication entries. Example:
foo.prefix = hg.intevation.org/mercurial foo.username = foo foo.password = bar foo.schemes = http https bar.prefix = secure.example.org bar.key = path/to/file.key bar.cert = path/to/file.cert bar.schemes = https
Supported arguments:
If no suitable authentication entry is found, the user is prompted for credentials as usual if required by the remote.
changeset configuration in this section is used as the template to customize the text shown in the editor when committing.
In addition to pre-defined template keywords, commit log specific one below can be used for customization:
For example, the template configuration below shows as same text as one shown by default:
[committemplate] changeset = {desc}\n\n HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: {extramsg} HG: -- HG: user: {author}\n{ifeq(p2rev, "-1", "", "HG: branch merge\n") }HG: branch '{branch}'\n{if(activebookmark, "HG: bookmark '{activebookmark}'\n") }{subrepos % "HG: subrepo {subrepo}\n" }{file_adds % "HG: added {file}\n" }{file_mods % "HG: changed {file}\n" }{file_dels % "HG: removed {file}\n" }{if(files, "", "HG: no files changed\n")}
Note
For some problematic encodings (see hg help win32mbcs for detail), this customization should be configured carefully, to avoid showing broken characters.
For example, if multibyte character ending with backslash (0x5c) is followed by ASCII character 'n' in the customized template, sequence of backslash and 'n' is treated as line-feed unexpectedly (and multibyte character is broken, too).
Customized template is used for commands below (--edit may be required):
Configuring items below instead of changeset allows showing customized message only for specific actions, or showing different messages for each action.
These dot-separated lists of names are treated as hierarchical ones. For example, changeset.tag.remove customizes the commit message only for hg tag --remove, but changeset.tag customizes the commit message for hg tag regardless of --remove option.
At the external editor invocation for committing, corresponding dot-separated list of names without changeset. prefix (e.g. commit.normal.normal) is in HGEDITFORM environment variable.
In this section, items other than changeset can be referred from others. For example, the configuration to list committed files up below can be referred as {listupfiles}:
[committemplate] listupfiles = {file_adds % "HG: added {file}\n" }{file_mods % "HG: changed {file}\n" }{file_dels % "HG: removed {file}\n" }{if(files, "", "HG: no files changed\n")}
Filters for transforming files on checkout/checkin. This would typically be used for newline processing or other localization/canonicalization of files.
Filters consist of a filter pattern followed by a filter command. Filter patterns are globs by default, rooted at the repository root. For example, to match any file ending in .txt in the root directory only, use the pattern *.txt. To match any file ending in .c anywhere in the repository, use the pattern **.c. For each file only the first matching filter applies.
The filter command can start with a specifier, either pipe: or tempfile:. If no specifier is given, pipe: is used by default.
A pipe: command must accept data on stdin and return the transformed data on stdout.
Pipe example:
[encode] # uncompress gzip files on checkin to improve delta compression # note: not necessarily a good idea, just an example *.gz = pipe: gunzip [decode] # recompress gzip files when writing them to the working dir (we # can safely omit "pipe:", because it's the default) *.gz = gzip
A tempfile: command is a template. The string INFILE is replaced with the name of a temporary file that contains the data to be filtered by the command. The string OUTFILE is replaced with the name of an empty temporary file, where the filtered data must be written by the command.
Note
The tempfile mechanism is recommended for Windows systems, where the standard shell I/O redirection operators often have strange effects and may corrupt the contents of your files.
This filter mechanism is used internally by the eol extension to translate line ending characters between Windows (CRLF) and Unix (LF) format. We suggest you use the eol extension for convenience.
(defaults are deprecated. Don't use them. Use aliases instead)
Use the [defaults] section to define command defaults, i.e. the default options/arguments to pass to the specified commands.
The following example makes hg log run in verbose mode, and hg status show only the modified files, by default:
[defaults] log = -v status = -m
The actual commands, instead of their aliases, must be used when defining command defaults. The command defaults will also be applied to the aliases of the commands defined.
Settings used when displaying diffs. Everything except for unified is a Boolean and defaults to False. See annotate section for related options for the annotate command.
Settings for extensions that send email messages.
Optional. Comma-separated list of character sets considered convenient for recipients. Addresses, headers, and parts not containing patches of outgoing messages will be encoded in the first character set to which conversion from local encoding ($HGENCODING, ui.fallbackencoding) succeeds. If correct conversion fails, the text in question is sent as is. Defaults to empty (explicit) list.
Order of outgoing email character sets:
Email example:
[email] from = Joseph User <joe.user@example.com> method = /usr/sbin/sendmail # charsets for western Europeans # us-ascii, utf-8 omitted, as they are tried first and last charsets = iso-8859-1, iso-8859-15, windows-1252
Mercurial has an extension mechanism for adding new features. To enable an extension, create an entry for it in this section.
If you know that the extension is already in Python's search path, you can give the name of the module, followed by =, with nothing after the =.
Otherwise, give a name that you choose, followed by =, followed by the path to the .py file (including the file name extension) that defines the extension.
To explicitly disable an extension that is enabled in an hgrc of broader scope, prepend its path with !, as in foo = !/ext/path or foo = ! when path is not supplied.
Example for ~/.hgrc:
[extensions] # (the color extension will get loaded from Mercurial's path) color = # (this extension will get loaded from the file specified) myfeature = ~/.hgext/myfeature.py
Web graph view configuration. This section let you change graph elements display properties by branches, for instance to make the default branch stand out.
Each line has the following format:
<branch>.<argument> = <value>
where <branch> is the name of the branch being customized. Example:
[graph] # 2px width default.width = 2 # red color default.color = FF0000
Supported arguments:
Commands or Python functions that get automatically executed by various actions such as starting or finishing a commit. Multiple hooks can be run for the same action by appending a suffix to the action. Overriding a site-wide hook can be done by changing its value or setting it to an empty string. Hooks can be prioritized by adding a prefix of priority to the hook name on a new line and setting the priority. The default priority is 0 if not specified.
Example .hg/hgrc:
[hooks] # update working directory after adding changesets changegroup.update = hg update # do not use the site-wide hook incoming = incoming.email = /my/email/hook incoming.autobuild = /my/build/hook # force autobuild hook to run before other incoming hooks priority.incoming.autobuild = 1
Most hooks are run with environment variables set that give useful additional information. For each hook below, the environment variables it is passed are listed with names of the form $HG_foo.
Note
It is generally better to use standard hooks rather than the generic pre- and post- command hooks as they are guaranteed to be called in the appropriate contexts for influencing transactions. Also, hooks like "commit" will be called in all contexts that generate a commit (e.g. tag) and not just the commit command.
Note
Environment variables with empty values may not be passed to hooks on platforms such as Windows. As an example, $HG_PARENT2 will have an empty value under Unix-like platforms for non-merge changesets, while it will not be available at all under Windows.
The syntax for Python hooks is as follows:
hookname = python:modulename.submodule.callable hookname = python:/path/to/python/module.py:callable
Python hooks are run within the Mercurial process. Each hook is called with at least three keyword arguments: a ui object (keyword ui), a repository object (keyword repo), and a hooktype keyword that tells what kind of hook is used. Arguments listed as environment variables above are passed as keyword arguments, with no HG_ prefix, and names in lower case.
If a Python hook returns a "true" value or raises an exception, this is treated as a failure.
Fingerprints of the certificates of known HTTPS servers. A HTTPS connection to a server with a fingerprint configured here will only succeed if the servers certificate matches the fingerprint. This is very similar to how ssh known hosts works. The fingerprint is the SHA-1 hash value of the DER encoded certificate. The CA chain and web.cacerts is not used for servers with a fingerprint.
For example:
[hostfingerprints] hg.intevation.org = fa:1f:d9:48:f1:e7:74:30:38:8d:d8:58:b6:94:b8:58:28:7d:8b:d0
This feature is only supported when using Python 2.6 or later.
Used to access web-based Mercurial repositories through a HTTP proxy.
This section specifies merge tools to associate with particular file patterns. Tools matched here will take precedence over the default merge tool. Patterns are globs by default, rooted at the repository root.
Example:
[merge-patterns] **.c = kdiff3 **.jpg = myimgmerge
This section configures external merge tools to use for file-level merges. This section has likely been preconfigured at install time. Use hg config merge-tools to check the existing configuration. Also see hg help merge-tools for more details.
Example ~/.hgrc:
[merge-tools] # Override stock tool location kdiff3.executable = ~/bin/kdiff3 # Specify command line kdiff3.args = $base $local $other -o $output # Give higher priority kdiff3.priority = 1 # Changing the priority of preconfigured tool vimdiff.priority = 0 # Define new tool myHtmlTool.args = -m $local $other $base $output myHtmlTool.regkey = Software\FooSoftware\HtmlMerge myHtmlTool.priority = 1
Supported arguments:
A list of merge success-checking options:
Settings used when applying patches, for instance through the 'import' command or with Mercurial Queues extension.
Assigns symbolic names to repositories. The left side is the symbolic name, and the right gives the directory or URL that is the location of the repository. Default paths can be declared by setting the following entries.
Custom paths can be defined by assigning the path to a name that later can be used from the command line. Example:
[paths] my_path = http://example.com/path
To push to the path defined in my_path run the command:
hg push my_path
Specifies default handling of phases. See hg help phases for more information about working with phases.
Specifies profiling type, format, and file output. Two profilers are supported: an instrumenting profiler (named ls), and a sampling profiler (named stat).
In this section description, 'profiling data' stands for the raw data collected during profiling, while 'profiling report' stands for a statistical text report generated from the profiling data. The profiling is done using lsprof.
The type of profiler to use. Default: ls.
Profiling format. Specific to the ls instrumenting profiler. Default: text.
Mercurial commands can draw progress bars that are as informative as possible. Some progress bars only offer indeterminate information, while others have a definite end point.
Format of the progress bar.
Valid entries for the format field are topic, bar, number, unit, estimate, speed, and item. item defaults to the last 20 characters of the item, but this can be changed by adding either -<num> which would take the last num characters, or +<num> for the first num characters.
(default: Topic bar number estimate)
Alias definitions for revsets. See hg help revsets for details.
Controls generic server settings.
Configuration for extensions that need to send email messages.
Subrepository source URLs can go stale if a remote server changes name or becomes temporarily unavailable. This section lets you define rewrite rules of the form:
<pattern> = <replacement>
where pattern is a regular expression matching a subrepository source URL and replacement is the replacement string used to rewrite it. Groups can be matched in pattern and referenced in replacements. For instance:
http://server/(.*)-hg/ = http://hg.server/\1/
rewrites http://server/foo-hg/ into http://hg.server/foo/.
Relative subrepository paths are first made absolute, and the rewrite rules are then applied on the full (absolute) path. The rules are applied in definition order.
Mercurial will not use the settings in the .hg/hgrc file from a repository if it doesn't belong to a trusted user or to a trusted group, as various hgrc features allow arbitrary commands to be run. This issue is often encountered when configuring hooks or extensions for shared repositories or servers. However, the web interface will use some safe settings from the [web] section.
This section specifies what users and groups are trusted. The current user is always trusted. To trust everybody, list a user or a group with name *. These settings must be placed in an already-trusted file to take effect, such as $HOME/.hgrc of the user or service running Mercurial.
User interface controls.
An optional external tool that hg import and some extensions will use for applying patches. By default Mercurial uses an internal patch utility. The external tool must work as the common Unix patch program. In particular, it must accept a -p argument to strip patch headers, a -d argument to specify the current directory, a file name to patch, and a patch file to take from stdin.
It is possible to specify a patch tool together with extra arguments. For example, setting this option to patch --merge will use the patch program with its 2-way merge option.
Web interface configuration. The settings in this section apply to both the builtin webserver (started by hg serve) and the script you run through a webserver (hgweb.cgi and the derivatives for FastCGI and WSGI).
The Mercurial webserver does no authentication (it does not prompt for usernames and passwords to validate who users are), but it does do authorization (it grants or denies access for authenticated users based on settings in this section). You must either configure your webserver to do authentication for you, or disable the authorization checks.
For a quick setup in a trusted environment, e.g., a private LAN, where you want it to accept pushes from anybody, you can use the following command line:
$ hg --config web.allow_push=* --config web.push_ssl=False serve
Note that this will allow anybody to push anything to the server and that this should not be used for public servers.
The full set of options is:
Path to file containing a list of PEM encoded certificate authority certificates. Environment variables and ~user constructs are expanded in the filename. If specified on the client, then it will verify the identity of remote HTTPS servers with these certificates.
This feature is only supported when using Python 2.6 or later. If you wish to use it with earlier versions of Python, install the backported version of the ssl library that is available from http://pypi.python.org.
To disable SSL verification temporarily, specify --insecure from command line.
You can use OpenSSL's CA certificate file if your platform has one. On most Linux systems this will be /etc/ssl/certs/ca-certificates.crt. Otherwise you will have to generate this file manually. The form must be as follows:
-----BEGIN CERTIFICATE----- ... (certificate in base64 PEM encoding) ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... (certificate in base64 PEM encoding) ... -----END CERTIFICATE-----
Web substitution filter definition. You can use this section to define a set of regular expression substitution patterns which let you automatically modify the hgweb server output.
The default hgweb templates only apply these substitution patterns on the revision description fields. You can apply them anywhere you want when you create your own templates by adding calls to the "websub" filter (usually after calling the "escape" filter).
This can be used, for example, to convert issue references to links to your issue tracker, or to convert "markdown-like" syntax into HTML (see the examples below).
Each entry in this section names a substitution filter. The value of each entry defines the substitution expression itself. The websub expressions follow the old interhg extension syntax, which in turn imitates the Unix sed replacement syntax:
patternname = s/SEARCH_REGEX/REPLACE_EXPRESSION/[i]
You can use any separator other than "/". The final "i" is optional and indicates that the search must be case insensitive.
Examples:
[websub] issues = s|issue(\d+)|<a href="http://bts.example.org/issue\1">issue\1</a>|i italic = s/\b_(\S+)_\b/<i>\1<\/i>/ bold = s/\*\b(\S+)\b\*/<b>\1<\/b>/
Parallel master/worker configuration. We currently perform working directory updates in parallel on Unix-like systems, which greatly helps performance.
Bryan O'Sullivan <bos@serpentine.com>.
Mercurial was written by Matt Mackall <mpm@selenic.com>.
This manual page is copyright 2005 Bryan O'Sullivan. Mercurial is copyright 2005-2015 Matt Mackall. Free use of this software is granted under the terms of the GNU General Public License version 2 or any later version.