Ketan's Musings

Where he blogs about his eclipse musings

Using Mercurial with Eclipse CVS

with 4 comments

Continuous Integration is a practice where developers frequently integrate their work with others, sometimes multiple times a day. In order to do this, developers do an update-merge-resolve conflict-compile-test-commit, and repeat for best results.

However there are times when you’re making major changes and the ‘commit’ phase in the cycle could break everybody else’s work, but you still need to check in! Here’s how mercurial (or even git) can help:

Checkout the initial sources from CVS(or svn) using eclipse.
$ cvs -d :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse co -P "pde/ui"

Navigate to the directory containing the workspace and initialize the mercurial repository:
$ cd ~eclipse
$ hg init
# see below for .hgignore
$ vi .hgignore

Commit what you just checked out of cvs:
$ hg addremove
$ hg commit -m "initial import from cvs"

Here’s a .hgignore that worked for me:

CVS
.*/bin
.DS_Store
.cvsignore
.metadata

Clone the initial import

We will not work in this checked out copy, instead we will clone it. The checked out copy will always track upstream CVS and will contain CVS metadata:
$ hg clone ~eclipse ../eclipse-working-copy

Now we switch workspace to ../eclipse-working-copy (both in eclipse and the command line) and keep checking in as and when needed:
$ cd ../eclipse-working-copy
$ echo "Hello World" >>| org.eclipse.pde/README.txt
$ hg addremove
$ hg commit -m 'minor changes towards adding foo-bar support'

We’ve now checked in a few changes into our working copy, time to push them into the CVS copy:
$ hg push

This pushed the changes in the upstream repository, but the working copy in upstream does not contain the local changes:
$ cd ~eclipse
$ hg update
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg log
changeset: 1:373d70bd13d6
tag: tip
user: ketanpadegaonkar@storm.corporte.thoughtworks.com
date: Sat Jan 24 10:53:27 2009 +0530
summary: minor changes towards adding foo-bar support

changeset: 0:ef6bc5b6d1db
user: ketanpadegaonkar@storm.corporte.thoughtworks.com
date: Sat Jan 24 10:24:20 2009 +0530
summary: initial import from cvs

Create a patch and send to bugzilla:
$ hg diff -r 0 > patch

Pulling from CVS into your eclipse-working copy is also similar, you do:
$ cd ~eclipse
$ cvs up
$ hg addremove
$ hg commit -m 'synced from cvs'
# goto the working copy, pull changes and apply them to the working copy
$ cd ../eclipse-working-copy
$ hg pull
$ hg update

Written by Ketan

January 24th, 2009 at 11:15 am

Posted in General

Tagged with , ,

4 Responses to 'Using Mercurial with Eclipse CVS'

Subscribe to comments with RSS or TrackBack to 'Using Mercurial with Eclipse CVS'.

  1. This was exceedingly helpful and worked without a hitch! Thank you!!!
    Mark

    Mark Bower

    30 Jan 09 at 8:55 am

  2. Hi,
    I followed this up to the hg clone …, but when I switch my eclipse (3.5M2) workspace to the eclipse-working-copy, eclipse does not show any of the projects.

    Any idea why that might be?

    Thanks,
    Channing

    Channing Walton

    7 Feb 09 at 4:09 am

  3. @Channing,

    You need to import the projects into the new workspace, eclipse does not know what projects belong to the workspace unless you import them.

    – Ketan

    Ketan

    7 Feb 09 at 9:51 am

  4. Thanks Ketan, I’ll do that.

    Channing Walton

    8 Feb 09 at 1:35 am

Leave a Reply

IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

What is 7 + 12 ?
Please leave these two fields as-is: