Mercurial, also known as hg, is the source-control management (SCM) tool that we use for Eigen.
- 1 Installing Mercurial and finding documentation
- 2 Basic usage
- 2.1 Getting the source
- 2.2 Configuring Mercurial
- 2.3 Note to Windows users
- 2.4 Branches
- 2.5 Local commit
- 2.6 Undoing uncommitted changes
- 2.7 Undoing a local commit
- 2.8 Generating a patch
- 2.9 Pushing the local changes to the central repository
- 2.10 Merge changes from another repository
- 2.11 Resolving conflicts
- 2.12 Viewing history
- 3 Advanced usage
- 4 Receiving commit notification
- 5 Search and replace on whole directory
- 6 Make a new release
Installing Mercurial and finding documentation
- If you are using Windows or Mac, download it from [website].
- If you are using Unix/Linux, just install Mercurial from your package manager.
If you want a graphical user interface, install Tortoise-Hg, but below in this page we will only be referring to the command-line interface.
Below in this page we explain some usual commands, but Mercurial has lots of documentation available on the Web:
Getting the source
$ hg clone http://bitbucket.org/eigen/eigen
or if you have a write access to the repository you have two options:
$ hg clone ssh://email@example.com/eigen/eigen/ # See  to setup ssh $ hg clone https://firstname.lastname@example.org/eigen/eigen/ # password login
After that, to update your checkout (get the new changes made to the repository):
$ hg pull -u # hg pull brings the changes into your store, and -u updates # your working directory to the latest revision. # 'hg pull -u' is the same as 'hg pull && hg update'.
Before using Mercurial to make Eigen changes/patches, please make sure that you have configured it as described in this section. To do so, edit (or create) your mercurial config file.
- On Unix-like systems, the global config file is ~/.hgrc
- On Windows systems, the global config file is Mercurial.ini in your home directory
Note that if you need a different mercurial config for another project, you can also use a per-clone config file: .hg/hgrc inside the clone directory. We recommend using the global config file unless you really know what you are doing.
Put these lines in the Mercurial config file:
[diff] git = 1 showfunc = 1 unified = 8 [defaults] commit = -v [ui] username = Your Real Name <email@example.com> merge = internal:merge editor = YourFavoriteEditorExecutable
In the above config file sample, note that some lines are placeholders that you must replace with correct values:
- Enter your real name and email address. Will be used to credit you, and contact you in case of a problem.
- Enter your choice of text editor. Will be used to write commit messages.
Note to Windows users
In order to deal with Windows end-of-line encoding, please follow these instructions.
In the end you should be adding something like this to your config file:
[extensions] hgext.win32text= [encode] ** = cleverencode: [decode] ** = cleverdecode: [patch] eol = crlf [hooks] pretxncommit.crlf = python:hgext.win32text.forbidcrlf
By default, what you now see is the development branch, called the 'default branch'.
$ hg branch # show the name the current branch $ hg branches # show the list of branches $ hg up 2.0 # switch to 2.0 branch
First of all, make sure you have put any new files under revision control:
$ hg add <filename> # Put a file under revision control
Then you can examine before committing:
$ hg status # see what files are affected $ hg diff # show differences that are to be committed
To proceed with the local commit:
$ hg commit # take care, this will commit changes for the whole repository # even if you are in a sub-directory (this is not as SVN does) $ hg commit . # if you want to commit only the local directory
This will open the text editor that you specified in your config file. This will also use the identity that you specified in your config file.
Undoing uncommitted changes
You can undo all uncommitted changes by doing:
$ hg revert somefile # undo uncommitted changes to this file $ hg revert -a # undo all uncommitted changes to all files. Careful!
Undoing a local commit
In case you want to undo a local commit, e.g. to deal with typos in the commit log or similar, do:
$ hg rollback # roll back the last transaction
Notice that this will only undo the committing action. See previous section for undoing the changes to your working copy.
Only use this technique for local commits. Otherwise, it doesn't make sense, since it cannot be guaranteed that other users already pulled in public changes.
Generating a patch
Once you have made a local commit, you can generate a patch from it:
$ hg export tip > somefile
Here, 'tip' means the latest revision. Try "hg help export" to see other options. This generates a file that you can then attach to a bug report or to an e-mail to the Eigen mailing list. If you have properly configured your identity as above before committing, then importing your patch will properly credit you.
Pushing the local changes to the central repository
Once you have made a local commit, you can push it to the central repository.
$ hg out # to check what you are actually pushing $ hg push # push your commits. No need to give the repository if this is the one cloned
You may see this error message:
abort: push creates new remote heads! (did you forget to merge? use push -f to force)
This means that one of your modified files has been modified meanwhile in the repository. You need to merge before you can push: see next section. Do not use push -f as mentioned in that message, as there may be a conflict to resolve manually.
Merge changes from another repository
$ hg in <repo> # check what's coming in $ hg pull <repo> # pull changesets from <repo> $ hg merge # merge the new tip from <repo> into our working directory $ hg parents # see the revisions that have been merged into the working directory $ hg commit # commit the result of the merge
After 'hg merge', you may see this error message:
warning: conflicts during merge. merging <filename> failed! 0 files updated, 0 files merged, 0 files removed, x files unresolved
In that case, read the section "Resolving Conflicts" below.
This is very similar to SVN. After a 'hg merge' has found conflicts, the files are left with special markers at the locations of conflicts, like:
<<<<<<< local Hello Sir ======= Hello Madam >>>>>>> other
You have to edit these files manually to resolve the conflict. Once a file <filename> is fixed, do:
hg resolve -m <filename> # mark the file as resolved
Once all the files are marked as resolved, you can proceed with committing.
The basic command here is 'hg log'. If you want to see full information about a certain revision, you can do:
$ hg log --style changelog -r 1000 # examine revision 1000 $ hg log -u someuser # see all commits made by someuser
But you can also enable a couple of extensions that provide fancier views. Edit (or create) your global .hgrc file (in your home directory) and add these lines:
[extensions] hgk= hgext.graphlog =
You can now enjoy a graphical view of the commit history:
$ hgk # or try 'hg view' if that doesn't work
Or if you prefer a plain text output of the graph:
$ hg glog
Finally, if you want something more powerful, have a look at the following external programs: hgtk and hgview. Hgtk allows many things, like viewing only as specific branch, viewing only merges, etc. Do:
$ hgtk log
Hgview is simpler but still allows viewing a specific branch:
Porting a changeset to another branch
First of all, you should a separate local clone for each of the branches that you're interested in. If you want to transplant a changeset, say, from the default branch to the 2.0 branch, enter your clone of the 2.0 branch, make sure that you have pulled the changeset that you want to transplant, and do:
$ hg export REV | hg import -
There also is a transplant extension.
Pushing many local commits as a single one
If you want to do this, you want Mercurial Queues, see above. Specifically, the qfold command. If you're not very comfortable with Mercurial, don't bother.
Splitting a patch into smaller patches
The best way to do that is using the Crecord extension. It has an interactive interface to let you select line-by-line or hunk-by-hunk how to split your patch.
Warning: rebasing is not something trivial, and can break a repository. Typically, if you push changes, then do some rebasing, this is a very bad thing. The remote repository might get corrupted.
The most obvious way is to use 'hg rebase', or 'hg update --rebase'. See respective documentation.
If you are such a power user that you know how to use Mercurial Queus (MQ, see above), this is another way to do almost automatic rebasing. Once your changeset is a MQ patch, you can pop it, update your hg repository to another changeset, and push it again.
Receiving commit notification
The Bitbucket web interface offers RSS and Atom feeds.
If you prefer email notification, subscribe to the eigen-commits mailing list. Instructions are the same as for the eigen mailing list, just replace "eigen" by "eigen-commits" everywhere.
Search and replace on whole directory
If you do a search-and-replace operation on a whole directory, you probably do not want it to affect Mercurial's own internal files! So you must avoid all .hg directories. You can do:
$ find . -type f | grep -v \\.hg | xargs sed -i 's/oldstring/newstring/g'
Make a new release
These days it's very easy, as the docs are automatically generated and uploaded by Thomas' machine, and the tarballs are auto-generated by Bitbucket.
So here's what it takes to make a new release (a new minor version):
- Announce a week in advance on the eigen mailing list the upcoming release (give a precise date) so that people can test and/or speak up if they know of an issue. Of course, in case of an emergency, no need to do that :)
- Concert with other devs, and/or use CDash, and/or test yourself, to make sure that the test suite passes at the very least for:
- latest stable GCC
- some older GCC 4.x (ok, it's hard to check them all), try to cover the oldest GCC we're supposed to support (see main page)
- latest MSVC
- latest Clang
- Also do think to check "make install"! Remember how it spoiled the 2.0.7 release!
- Supreme refinement would be to check building the test suite against the installed Eigen.
- Update the version number (EIGEN_MINOR_VERSION, etc) in the file Eigen/src/Core/util/Macros.h.
- In the 2.0 branch, also update the version number in the root CMakeLists.txt. That doesn't apply to the default branch.
- commit that:
$ hg commit
- Make a tag:
$ hg tag 4.5.6-beta7
- recommended: check that everything is in order.
$ hg view
- push the release:
$ hg push
- For a minor version: make the full changelog. It's not just a dump of the commit messages: it must be readable and interesting for Eigen users. You can use "hg view" again, try to put the grave bug fixes first, try to group together what's related.
- Update the Main Page on the wiki, that is the announcement at the top and the Download section. Make sure that the tarball links point to the new release, and that any example of how to get the latest tag also refers to the new tag.
- To add a news, simply create a new page in the "News" namespace:
- enter "News:Title of my great announcement!" in the search box,
- press search, and click "create a new page",
- write your news as usual, preview, save...
- you might have to enforce the regeneration of the mainpage by editing/saving it (because of mediawiki's cache)