Mercurial
From MDC
Mercurial is the distributed version control software we're using for Mozilla 2 development. It will eventually replace CVS.
hg is the Mercurial command-line tool, Hg being the chemical symbol for the element mercury.
Contents |
[edit] How Mercurial is different
Mercurial vs. CVS:
- Mercurial checkins are atomic.
- In Mercurial, tagging is fast and O(1).
- Mercurial makes it easy for anyone to fork the central repository. (The command is
hg clone.)
- Mercurial makes branching quick and easy and keeps merging pretty much sane. (See Publishing Mercurial Clones.)
- With Mercurial, a complete, fully armed and operational clone of the entire Mozilla repository is on your local hard drive. You can do work locally and check it in without affecting anybody else. To push changes upstream, use
hg push.
- Mercurial queues can help you juggle patches. It's like Quilt. The idea behind Quilt is this:
The scripts allow to manage a series of patches by keeping track of the changes each patch makes. Patches can be applied, un-applied, refreshed, etc.
The key philosophical concept is that your primary output is patches. Not ".c" files, not ".h" files. But patches. So patches are the first-class object here.
- When CVS finds merge conflicts, it puts conflict markers in your file. When Mercurial finds merge conflicts, it launches a merge program. This is a pain in the neck.
- In a lot of places where CVS is per-file or per-directory, Mercurial is per-repository. For example, a single Mercurial changeset may contain changes to many files throughout the tree.
- We hope Mercurial will allow us to rethink the way we work. Teams and individuals should be able to branch and merge much more easily—without opening IT tickets. People outside the community who are powerhouse developers should be able to do surprising stuff with this. Companies maintaining forks of Mozilla should have an easier time too. It all sort of remains to be seen, though.
[edit] Basics
[edit] Installing Mercurial
If you use apt-get, emerge, port, or yum to install software, just do the usual. If not, the Mercurial binary packages are for you. Or see wikimo:Mercurial on Windows.
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.
The Windows version of Mercurial does not automatically convert line endings between Windows and Unix styles. All our repositories use Unix line endings. We need a story for Windows, but right now I have no ideas. (How about a pre-commit hook that rejects pushes containing CR with a suitably informative error message? We possibly want to make exceptions for certain types of files (at least binary files of course), but we can tweak the hook as necessary as these crop up. Mercurial 1.0 adds a standard hook for this in the win32text extension that we could use/adapt. --jwatt)
[edit] Checking out
The Mozilla 2 trunk is located at http://hg.mozilla.org/mozilla-central/ .
You need Python 2.4 or later just to check everything out. This is because we're using Python to do some checkout-related stuff that client.mk used to do—blame bsmedberg ;)
hg clone http://hg.mozilla.org/mozilla-central/ mozilla cd mozilla python client.py checkout # <--- *** don't forget this ***
After that you can just get yourself a .mozconfig file and build as you normally would.
You will need to have autoconf-2.13 installed. If you don't already, please go here to find out how to get it for your platform.
If you get the error message "No module named subprocess", that's because you didn't install Python 2.4 or later. Go back two paragraphs.
For an up-to-date copy of CVS trunk via hg (rather than the Mozilla 2 trunk), see http://hg.mozilla.org/cvs-trunk-mirror/. In order to build, you'll need to run the same client.py script, which is not provided in cvs-trunk-mirror. You need to get that from mozilla-central, then copy it into the source directory and run.
[edit] Editing and updating
You can randomly edit files, just like CVS.
To update a tree, run
python client.py checkout
(just as you did as the last step of pulling it originally). If you just use hg pull -u, you risk not getting updates to NSPR, NSS, or tamarin-central that are required to build.
It is not possible to update only one directory; you have to update the entire tree.
[edit] Diffing and patching
-
hg diffdiffs the entire tree by default. Usehg diff .(note the dot) to diff only the current directory.
- When applying a patch generated by Mercurial, use
patch -p1, notpatch -p0. (This is due to a quirk of Mercurial diff output—it refers to fictional "a" and "b" directories. Don't ask.)
hg has no exact equivalent of cvs diff -u8p. The simplest thing is hg diff, which provides 3 lines of context.
To get 8 lines of context, enable the hg extdiff command (by editing your ~/.hgrc file). If you agree this is super lame, please leave a polite comment at http://www.selenic.com/mercurial/bts/issue654 .
[edit] Checking in
To commit your changes to your local repository:
hg commit
To push those changes upstream to the central repository:
hg push
For that to work, you have to have committer access, and you must edit the file (your-local-hg-root)/.hg/hgrc to add this line:
[paths] default = http://hg.mozilla.org/mozilla-central/ default-push = ssh://hg.mozilla.org/mozilla-central/
You also have to tell ssh what username to use when connecting to hg.mozilla.org. This should be the username associated with your Mozilla LDAP account. You can do this either by making the default-push path above more complicated (user@host.name@hg.mozilla.org) or by adding lines to your ~/.ssh/config :
Host hg.mozilla.org User user@host.domain
You'll get a bogus error message each time you push:
remote: Could not chdir to home directory : No such file or directory
Just ignore it.
[edit] Things that have changed
- Bonsai is replaced by the Hg web viewer, see [1]. This lacks some bonsai features that would be nice, including mark, line-number anchors, and graphs. There are some terminology differences:
bonsai blame == hg annotate
bonsai log == hg revisions
also you can browse the repository using the "manifest" link.
- MXR for mozilla-central is now available.
- There's no Bugzilla integration for Mercurial.
[edit] See also
The hg book is the definitive Mercurial user guide.
Category:Mercurial lists the Mercurial-related articles on MDC.
And on wiki.mozilla.org, these helpful pages:
