Using Mercurial locally with CVS

Revision as of 21:32, 31 July 2007 by VladVukicevic (talk | contribs)

This page is an introduction on how to use Mercurial locally with CVS. That is, code is still checked out/committed to the Mozilla repository using CVS, but all local work is done using Mercurial.

You will manually pull updates from CVS, and you won't get any changeset information (that is, everyone's commits since the last time you updated from CVS will come in as one big blob), but your own commits will be kept as separate changesets.

Prerequisites

  • Mercurial 0.9.4 (or newer -- though release versions are preferred)

Goal

At the end of this document, you'll end up with two hg repositories:

  • a CVS repository, which is where the hg <-> cvs interaction takes place
  • a clone of the above repository, which is where all your work takes place (you can have more than one of these; but you can only have one CVS repository)

Each chunk of commands will assume that you're starting in some toplevel directory; the CVS repository will end up in cvssrc/mozilla; feel free to replace cvssrc with something else.

Note that there are other ways of setting this up, such as using named branches, or doing all your work in one repository, but this is the way that works for me, and I think is also the easiest way to avoid getting very confused.

Initializing the CVS repository

First, pull a mozilla checkout into a clean dir.

% mkdir cvssrc
% cd cvssrc
% cvs -d :ext:yourcvsusername@cvs.mozilla.org:/cvsroot co mozilla/client.mk
% cd mozilla
% MOZ_CO_PROJECT=browser make -f client.mk pull_all

Now, check that tree into a mercurial repository.

% cd cvssrc/mozilla
% hg init
% vi .hgignore     see below
% hg addremove
% hg commit -m "cvs sync"

Here are the contents of my .hgignore file; they can probably be optimized, but this works for me (please edit this if you end up with a better one!)..

.*~$
^CVS
.*/CVS
.*/CVS/.*
.*/NONE
#\.\#.*$
^Makefile$
^config.log$
^config.cache$
^config.status$
^.client-defs.mk$
^config-defs.h$
^.mozconfig$
^.mozconfig.mk$
^.mozconfig.out$
^a.out$
^unallmakefiles$
^nss$
^mozilla-config.h$
.flc$
.orig$
.pyc$

hg addremove marks any files in the working dir that aren't present in the repository for addition, and marks any missing files as missing. The hg commit will create your initial commit.

Cloning the CVS repository

Do not do any work inside the CVS repository! Instead, create a clone:

% hg clone cvssrc/mozilla mozilla

And do your work inside the mozilla repository.

Doing work

Perform any changes inside the cloned mozilla repository. You may use any combination of hg extensions, including mq, transplant, etc. to manage your changes in this repository.

Once you are ready to commit your work back to CVS, you'll need to make sure that a hg changeset exists for your patch(es). In the simplest way, this will just mean running hg commit.

Committing your work to CVS

Let's say you just made a change:

% cd mozilla
% echo "Hello World" >> README.txt
% hg commit -m "Add mystery message to README.txt"
% hg log -l 2
256[tip]   603e507ddf25   2007-07-31 13:41 -0700   vladimir
  Add mystery message to README.txt

255   a4a7678829ff   2007-07-31 13:31 -0700   vladimir
  cvs sync