Sharing code during a sprint with Twisted and Bazaar-NG

From a recent experience working on a sprint (many thanks to Robert Kern for introducing me to these tricks), I suggest the following mechanism for efficiently sharing code amongst multiple people working simultaneously on a given project. We can adjust as needed, but unless someone knows a better solution, I found this to work fairly well.

The basic idea is to ensure that for the duration of the sprint, everybody configures their laptop with a static IP address, so we can easily track who is who for pulling code updates. We can quickly make a little hosts file with these numbers that everybody can grab, so you know easily how to get code from someone else. With this in place, we will use twisted to quickly expose a local directory over http on the local subnet, regardless of the OS at each end of the connection (beats configuring Samba/NFS/whatever by a very long shot).

Then, Bazaar-NG allows us to turn any directory quickly into a version control 'server' that others can pull updates from. This way, any group working on a project can send updates to one another rapidly (and anyone in the room can get them as well if they want to experiment with something). If you've ever used SVN, you're good to go with Bazaar-NG; their interfaces are extremely similar (for tasks they can both perform).

On to the instructions. Those who can, please do at least step 0 before Monday, so we're all ready to go. If you can, experiment with the rest on a local subnet. I've only done this once in my life, so there may be errors here, feel free to correct them as needed.

Step 0: Prerequisites

Install Bazaar NG and Twisted. For Twisted, 2.0 or better is enough; for Bazaar, grab 0.7.0 or better.

Creating the HTTP server

Let's suppose that I am trying to expose the tvtk directory:

maqroll[python]> d -d tvtk
/home/fperez/code/python
drwxr-xr-x  2 fperez 4096 Feb 13 22:15 tvtk/

I would then position myself at /home/fperez/code/python and type at the system prompt:

mktap web --path=tvtk

The mktap utility is part of Twisted, you can find more details here and here. For our purposes, suffice it to say that it creates a the necessary configuration to expose the path you gave it over HTTP.

Next, we actually activate the server with

twistd -f web.tap

Having done this, now the tvtk directory will be available to others as

http://my.host.name:8080/tvtk

This is why it will be useful to have fixed IPs, so we can easily and reliably find each other's code.

To stop the Twisted server, simply issue

kill `cat twistd.pid`

The twistd.pid file is automatically created when the server starts and is left in the directory where you ran the twistd command.

Exposing a Bazaar branch

The above instructions will expose any directory over HTTP, but what we want is automatic synchronization of the kind that a source control system provides. SVN isn't very well suited for this, because it requires a central server, authentication, etc. Bazaar-NG is a distributed version control system, with which this problem is very easy to address.

Let's look at the contents of the directory we want to expose:

maqroll[tvtk]> d
/home/fperez/code/python/tvtk
total 24
-rw-r--r--  1 fperez 5448 2006-02-13 00:24 envisage.log
-rw-r--r--  1 fperez 1151 2006-02-13 00:24 tvtkcrash.tgz
-rw-r--r--  1 fperez 2153 2006-02-13 00:24 tvtkerr
-rwxr-xr-x  1 fperez  362 2006-02-13 22:15 tvtktest.py*
-rwxr-xr-x  1 fperez  346 2006-02-13 00:20 tvtktest.py~*

The first step is to start up bzr in this directory:

maqroll[tvtk]> pwd
/home/fperez/code/python/tvtk
maqroll[tvtk]> bzr init

Notice how this creates a .bzr/ directory, where Bazaar-NG stores its information (similar to the .svn/ ones used by Subversion):

maqroll[tvtk]> d -a
/home/fperez/code/python/tvtk
total 36
drwxr-xr-x   3 fperez 4096 2006-02-13 23:11 ./
drwxr-xr-x  19 fperez 4096 2006-02-13 02:33 ../
drwxr-xr-x   4 fperez 4096 2006-02-13 23:11 .bzr/
-rw-r--r--   1 fperez 5448 2006-02-13 00:24 envisage.log
-rw-r--r--   1 fperez 1151 2006-02-13 00:24 tvtkcrash.tgz
-rw-r--r--   1 fperez 2153 2006-02-13 00:24 tvtkerr
-rwxr-xr-x   1 fperez  362 2006-02-13 22:15 tvtktest.py*
-rwxr-xr-x   1 fperez  346 2006-02-13 00:20 tvtktest.py~*

Now, all we need to do is actually add the files we want in version control into the project (let's say I only want the log and the python scripts):

maqroll[tvtk]> bzr add envisage.log tvtktest.py
added envisage.log
added tvtktest.py

And finally, we must commit these changes so others can see them:

maqroll[tvtk]> bzr commit -m"initial commit for sprint"
Committed revision 1.

At this point, our directory can be seen by others (since Twisted is running) and they can pull changes from us.

Getting someone else's Bazaar branch

Once I've exposed my branch, let's suppose Matthew wants to get it. All he needs to do is first get it using

bzr branch http://my.host.name:8080/tvtk

This will give him a local copy, to which he can start making changes, and committing. If I have made updates which he wants to get, there are two possibilities:

a. Matthew has not made any commits to his branch. In this case, the pull command is all he needs:

bzr pull

b. Matthew has committed changes, so our branches are said to have diverged. In this case, the merge command will merge my changes with his:

bzr merge

That should be it. For more details, please see the Bazaar-NG tutorial. Also remember that for any command in Bazaar, you can get info by simply typing

bzr help command-name

while

bzr help commands

gives a summary of all the commands understood by bzr.