Author Archive

Accessing Git, Subversion and Mercurial from Bazaar

Thursday, October 29th, 2009

bzr-svn, bzr-git and bzr-hg are plugins for bzr that make Subversion, Git and Mercurial branches first class citizens in the Bazaar world by allowing you to access them in the same way that you would access native Bazaar branches.

Bazaar has supported multiple file formats from its early days. Both its model and its implementation allow this:

  • Revisions are not identified by the checksum of their layout on disk (as they are in systems like Git or Mercurial) but by a (pseudo-)random string. This means that copying data to a different file format does not affect the revision id.
  • Repositories are accessed through a well defined interface. Other parts of the codebase are ignorant about the structure of the files on disk.

This has made it easy to introduce better and experimental repository formats without having to break old repositories or render them unusable for previous versions of Bazaar by forcing upgrades. Initially new formats were introduced at a very high pace (perhaps even a too high pace?), but fortunately this has slowed down nowadays: the last default format change before the 2.0 release was in 2007.

Having grown interested in Bazaar through Martin‘s talk at Linux.Conf.Au 2005 and his blog posts I started looking into Bazaar in 2005. Since Samba (the main FOSS project I work on) had just switched to Subversion, I was interested in ways to interact with Subversion using Bazaar, in particular so I could do off-line commits. On the Bazaar wiki Aaron had suggested implementing the well defined interface for repository formats for other version control systems (such as Subversion) as well. This sounded very neat, so I decided to see how far I could get and looked into learning Python and becoming more familiar with the Bazaar API.

Now, four years later, 700 bug reports and about 4400 revisions later, we have released bzr-svn 1.0. The models of Subversion and Bazaar have significant differences, and bzr-svn has to take care of mapping between the semantics of both. Perhaps the best example of this is the fact that a Subversion repository is basically a versioned filesystem; there may be some directories that are commonly used as containers for branches or tags, but there are a lot of exceptions to this convention. In Bazaar on the other hand, a branch is a primary object.

In 2006 Rob and Aaron created a simple plugin for accessing local Git repositories in 2006 called bzr-git. Originally it was based on “stgit”, a tool which (among other things) exposed a Python wrapper around the git executables. Following a switch from Samba to Git I took over in 2008 and changed bzr-git to use a new native implementation of Git in Python, based on a project by James. bzr-git now supports accessing remote repositories, working trees and merging changes back into Git.

At the moment I am working on the bzr-hg plugin, again based on an initial proof of concept by Rob. Last month ago the first version (0.1) was released, providing sufficient support for cloning local and remote Mercurial repositories and accessing working trees. There are still some problems to work out — memory usage is excessive, commit and push do not yet work — but there should be a stable plugin in a few months.