Mercurial notes

Using Subversion as source control for personal files, I was finding it difficult to maintain contact with a single repository URL. Mercurial solves that problem nicely, and even plays well with Subversion.

Mercurial commands are almost identical to Subversion, when the functionality is the same.

Git solves the same problem, with more options but more complexity [ Git_notes.html ] . Mercurial is easy to use safely in a very short time.

Projects using Mercurial include Mozilla, OpenSolaris, OpenJDK, Netbeans, and Pidgin.

Mercurial is implemented in python, with some C for binary diffs. It is available on all platforms.

This example shows the most important new functionality:

http://www.selenic.com/mercurial/wiki/index.cgi/UnderstandingMercurial

See the main website here: http://www.selenic.com/mercurial/wiki/

§    My install

I got the source and installed with make:
tar zxvf mercurial-1.1.2.tar.gz
cd mercurial-1.1.2
sudo make install

This installed /usr/local/bin/hg but did not put the python module in my path. Typing hg returned the error ImportError: No module named mercurial

So to my login environment I added (for two different machines):
PYTHONPATH="/usr/local/lib/python2.4/site-packages:${PYTHONPATH}"
PYTHONPATH="/usr/local/lib64/python2.4/site-packages:${PYTHONPATH}"

§    Making a Subversion working copy into an Hg respository

First check out a working copy of Subversion, and create a new Mercurial repository that shares the working copy:
svn co URL/trunk svnHgRepo
cd svnHgRepo
hg init
cat > .hgignore <<EOF
\.svn/
\.hgignore$
EOF
hg status
hg add
hg status
hg ci -A -m "imported from svn"
hg log

Then I can make a copy of this repository to a detachable disk.
cd /media/USBDISK
hg clone $HOME/svnHgRepo hgOnly

Here's a sample remote path:
hg clone ssh://host//full/path/svnHgRepo hgOnly
hg clone ssh://host/svnHgRepo hgOnly  # from home directory

Assume that copy is modified offsite.
cd /media/USBDISK/hgOnly
echo foo > testfile
hg add testfile
hg ci -m test
hg log

Later that detachable disk is reconnected and you want the changes merged with the latest version of the SVN repository.

First update the original SVN working copy, and save the changes into that Hg repository.
cd $HOME/svnHgRepo
svn up
hg ci -m "updated from SVN"

Then merge those SVN changes into the offsite Hg copy:
cd /media/USBDISK/hgOnly
hg pull $HOME/svnHgRepo
hg update

# If the update fails, then you need a merge
hg merge
hg ci -m "merged SVN updates"

Finally, pull the offsite changes into the SVN working copy and check in:
cd $HOME/svnHgRepo
hg pull /media/USBDISK/hgOnly
hg update
svn ci -m "updated from Hg"

You can also reverse the direction and push changes from one copy to another, as if you were checking into a central respository.

Bill Harlan, January, 2009


Return to parent directory.