Please refer to Mercurial For Mozillians at ReadTheDocs for current best-practices around Mercurial, including many helpful extra tools and guidelines that make using Mercurial fast and easy.
Installing
See Installing Mercurial from the Mozilla Version Control Guide.
Basic configuration
You should configure Mercurial before submitting patches to Mozilla.
If you will be pulling the Firefox source code or one of the derived repositories, the easiest way to configure Mercurial is to run the mercurial-setup mach command:
./mach mercurial-setup
This command starts an interactive wizard that will help ensure your Mercurial is configured with the latest recommended settings. This command will not change any files on your machine without your consent.
If you don't have the Firefox source code available, you should edit your Mercurial configuration file to look like the following:
[ui] username = Your Real Name <user@example.com> merge = your-merge-program (or internal:merge) [diff] git = 1 showfunc = 1 unified = 8 [defaults] commit = -v
On Windows, these settings can be added to $HOME\.hgrc
or $HOME\Mercurial.ini
, or, if you'd like global settings, C:\mozilla-build\hg\Mercurial.ini
or C:\Program Files\Mercurial\Mercurial.ini
. On UNIX-like systems, they should be in your $HOME/.hgrc
file.
You can configure the editor to use for commit messages using the editor
option in the [ui]
section or by setting the EDITOR
environment variable.
If you are trying to access the repository through a proxy server, see these instructions.
Other configuration tips
Merge program
After installing, choose a merge program. Seriously. Do it now. If you don't, Mercurial will choose one for you and spring it on you when you least expect it.
A reasonable thing to do is to set ui.merge=internal:merge
in the Mercurial configuration file (see below), which makes Mercurial try to merge changes and add the conflict markers (a la CVS) to the files that couldn't be merged.
Under Ubuntu, you can install meld package, then in in the Mercurial configuration file (see below) set ui.merge=meld
You can see the list of merge conflicts by looking for "merging ... failed!" in the update output.
Configuring kdiff3 as a merge tool
If you're on Linux and you have kdiff3 installed, you probably want to configure kdiff3 as a merge tool. (It's better than meld because it will actually resolve a bunch of the conflicts without prompting you, generally quite accurately.) You can do this by adding the following lines (which come from contrib/mergetools.hgrc
in the Mercurial distribution):
[merge-tools] kdiff3.args=--auto -L1 base --L2 local --L3 other $base $local $other -o $output kdiff3.regkey=Software\KDiff3 kdiff3.regappend=\kdiff3.exe kdiff3.fixeol=True kdiff3.gui=True
Extensions
There's a number of extensions you can enable. See http://mercurial.selenic.com/wiki/UsingExtensions. Almost everyone should probably enable the following:
- color - Colorize terminal output
- histedit - Provides git rebase --interactive behavior.
- pager - Feed command output into a pager (like less)
- progress - Draw progress bars on long-running operations.
- rebase - Ability to easily rebase patches on top of other heads.
- transplant - Easily move patches between repositories, branches, etc.
These can all be turned on by just adding this to your .hgrc file:
[extensions] color = rebase = histedit = progress = transplant = pager =
In addition, there are some 3rd party extensions that are incredibly useful for basic development:
- mozext
- Mozilla-specific functionality to aid in developing Firefox/Gecko.
- trychooser
- Automatically creates a try commit message and then pushes changes to Mozilla's Try infrastructure. Just run:
hg trychooser
- qimportbz
- Import patches from Bugzilla. Creates a filename and commit message for you based on the bug's metadata.
hg qimport bz://1234567
- bzexport
- Export patches to Bugzilla. There are quite a few optional arguments here to create new or update existing bugs with the attment, as well as auto matically request reviews. Type hg help bzexport for a full list but the basic syntax is:
hg bzexport -i 1234567
Installing these is fairly easy. You'll just need to find a place on your system to store the extensions, and clone the extension repos into it:
hg clone https://bitbucket.org/edgimar/crecord hg clone https://bitbucket.org/sfink/mqext hg clone https://hg.mozilla.org/users/robarnold_cmu.edu/qimportbz git clone https://github.com/pbiggar/trychooser
And then add then to your .hgrc file
[extensions] qcrecord = /path/to/crecord/crecord mqext = path/to/mqext qimportbz = path/to/qimportbz trychooser = path/to/trychooser/trychooser
Configuring the try repository
If you have access to the try server you may want to configure Mercurial so you can refer to it simply as "try", since it can be useful from all your trees. This can be done by adding this to your ~/.hgrc (or Mercurial.ini):
[paths] try = ssh://hg.mozilla.org/try/
You can also configure short names like this that are specific to a particular repository by adding a [paths] section to the .hg/hgrc file within a repository. There are two magic names, "default" and "default-push", which are used as the default push/pull targets. (If "default" is specified and "default-push" is not, "default" is used for both.)
Alternatively, you can install the trychooser extension (older version).