Contribute > Development > DVCS Workflows > Mercurial

  1. For Twisted contributors
    1. Using Mercurial Queues
      1. Initial Setup
      2. Work on your patch
      3. Keeping up-to-date
    2. Improvements and Further Reading
      1. hgsubversion

For Twisted contributors

If you want to develop a patch for Twisted (as described in the BasicGuideToContributingCode) but prefer to use Mercurial rather than SVN, this is the section for you.

There are no official Mercurial mirrors at this time; however, since creating a new patch doesn't require the complete repo history, one recommended workflow is to use Mercurial Queues.

Using Mercurial Queues

Using the MQ extension allows you to work on an svn checkout and keep your changes versioned separate from the underlying repo.
This is not a tutorial on the MQ extension, for that, see the Mercurial documentation

Initial Setup

  1. Checkout Twisted trunk
    svn co svn:// twisted-hg
  1. Enable the MQ extension in your .hgrc or Mercurial.ini
    mq =
  1. Initialize the hg repo
    cd twisted-hg
    hg init
  1. Create an .hgignore file to prevent hg from adding temporary files, testing artifacts
  1. Add files and create an initial commit to mark the SVN revision
    hg addremove
    hg commit -m "sync SVN @ `svn info | grep -0 Revision | cut -d ' ' -f 2`"

Work on your patch

The MQ extension provides a handy way to manage a queue of patches on top of the underlying repo.

Create a new mercurial patch in the queue

# Name the patch after the ticket# you are working on
hg qnew -m "Working on new feature" feature-1234

(hack hack hack)

# Make sure the test suite passes
trial twisted

# Generate an svn diff to attach to the ticket
svn diff > feature-1234.patch

Keeping up-to-date

Once you've submitted your patch for review, it may take some time before you get feedback. You'll want to synchronize with SVN and make sure your patch applies cleanly or deal with any conflicts

# Pop all MQ patches off the queue. You're now back at the previous SVN checkout
hg qrefresh
hg qpop -a

# Update the repo and sync a Mercurial commit
svn up
hg addremove -s 75
hg commit -m "sync SVN @ `svn info | grep -0 Revision | cut -d ' ' -f 2`"

# Re-apply your patch and deal with any conflicts using Mercurial's tools
hg qpush feature-1234

(hack hack hack)

trial twisted

# Generate a new svn diff to update the ticket
svn diff > feature-1234-2.patch

Improvements and Further Reading

The synchronization steps above could be automated:

hg qrefresh
hg qpop -a
svn up
hg addremove -s 75
hg commit -m "sync SVN @ `svn info | grep -0 Revision | cut -d ' ' -f 2`"

Patch queue versioning
You may want to independently version your MQ patches, leaving your primary Mercurial repo commits dedicated solely to logging SVN updates:

hg qinit -c
hg commit --mq


hgsubversion is a 3rd party tool dedicated to Subversion interoperability.

Pending resolution of this issue, it's likely that hgsubversion could be used to allow for a more natural workflow.

Last modified 4 months ago Last modified on 03/17/2014 12:39:33 PM