Archive for June, 2009

Using Bazaar Like Git + ‘repoalias’ Plugin

Sunday, June 28th, 2009

Continuing my exploration of distributed version control systems, I decided to take a quick look at the Git:

Managing Branches

A single git repository can maintain multiple branches of development. To create a new branch named “experimental”, use:

$ git branch experimental

If you now run

$ git branch

you’ll get a list of all existing branches:

  experimental
* master

That’s strange, I thought. Bazaar does it a bit differently. In Bazaar, the branches are often stored in a shared repository, which is just a special folder that contains the branches in it as subdirectories, but unlike Git, the repository is typically a “normal” folder that contains branches which are stored as subdirectories in plain sight to the developer.

Here’s an example from the Bazaar User Guide:

repository/       # Overall repository
 +- trunk/        # The mainline of development
 +- branches/     # A container directory
 |   +- foo/      # Branch for developing feature foo
 |     ...
 +- tags/         # Container directory
     +- release-X # A branch specific to mark a given release version
        ...

Hmm… I actually like how Git does it. Git “already works” with the way I have my existing projects setup. I don’t want to move my projects to match the directory structure shown above. Is there any way to use Bazaar in a Git-like manner? Well, I suppose you already know the answer to that, as I wouldn’t have much of a blog post to write if there wasn’t! :-)

Setting up a Git-like workflow with Bazaar

Being completely new to Bazaar, and to DVCS’ in general, I decided to ask the folks over at #bzr. They were very helpful, and fairly quickly ‘mzz’ had an answer:

First, we cd into our project, which is already setup as a bazaar branch:

cd path/to/myproject

Next, we run the following command:

bzr init-repo --no-trees .bzr-repo

That creates a hidden shared repository inside the project folder called .bzr-repo. We add the --no-trees option to tell Bazaar not to create unnecessary copies of the working tree.

Note that this is quite different from how repositories in Bazaar are normally used, usually they’re the parent directory.

bzr ignore .bzr-repo

We add the repository itself to the ignore list so that it’s not tracked.

Next, we commit the changes and create the main branch, called “trunk”:

bzr commit -m "added .bzr-repo to ignore list"
bzr branch . .bzr-repo/trunk

At this point we have two branches, the one in .bzr-repo/trunk and the branch we started with. This is no good, we want to be deal with only one branch at a time—the one we’re currently working with, and we want that branch to be one of the ones in .bzr-repo.

Thus enters the concept of a lightweight checkout. A checkout is very similar in concept to its SVN counterpart, you have a folder were you can make changes to files, and when you commit them they are sent off to some central location. One of the main differences between checkouts in Bazaar and checkouts in SVN is that in Bazaar the revision history is stored locally within the checkout itself. But in our setup, we don’t want that since each branch is stored locally anyway. Having two copies of it wouldn’t offer any advantage and would just take up space. A lightweight checkout lets us have a checkout without a revision history.

We can tell Bazaar to change the current branch into a checkout that points to .bzr-repo/trunk by using the reconfigure command:

bzr reconfigure --lightweight-checkout --bind-to .bzr-repo/trunk .

That’s it! :-)

Now we can continue our work as usual. Let’s test this out by adding a new file to the project:

$ echo "Version 1.0" > CHANGES
$ bzr add CHANGES
adding CHANGES $ bzr commit -m "added CHANGES" Committing to: /Users/gslepak/myproject/.bzr-repo/trunk/ added CHANGES Committed revision 2.

Everything seems in order. We can now use Bazaar like Git:

$ bzr branch . .bzr-repo/experimental
Branched 2 revision(s).
$ bzr switch .bzr-repo/experimental
Tree is up to date at revision 2.
Switched to branch: /Users/gslepak/myproject/.bzr-repo/experimental/

Since Bazaar doesn’t have an equivalent to the args-less git branch to list the available branches, we just use plain-old ‘ls’:

$ ls .bzr-repo/
experimental/ trunk/

At this point you might be wondering if there’s a way to get around having to type out the path to the repository each time you use bzr branch and bzr switch

Introducing the ‘repoalias’ Plugin

I asked that question on #bzr and mzz snapped into action, within a few minutes he had a working plugin ready that did just that. Needless to say my head was reeling from his Python kung-fu. :-)

Repoalias allows you to reference the branch’s repository like so:

bzr branch . repo:experimental
bzr switch repo:experimental
... do work ...
bzr switch repo:trunk
bzr merge repo:experimental
... etc ...

Getting the plugin is simple:

mkdir -p ~/.bazaar/plugins    # create the plugins folder if it doesn't exist
cd ~/.bazaar/plugins
bzr branch lp:~marienz/+junk/repoalias

That’s it! Many thanks to mzz and the folks at #bzr for helping me understand this stuff!

Cloak contest ends soon!

Wednesday, June 24th, 2009

The chance to win a license to Espionage (or equivalent value) is fast approaching, and thanks to the obscurity of the contest your chances of winning are great! :-) If you have the skills to improve upon Cloak’s icon, go for it!

Contest ends next Tuesday, June 30th.

Installing Bazaar 1.16 on OS X [Updated]

Monday, June 22nd, 2009

Recently I decided to bite the bullet and move away from Xcode’s Snapshots to using a DVCS. After checking out Git, Mercurial, and Bazaar I finally settled on the latter, for now at least.

Bazaar is a great, it has excellent documentation on a very well designed website, it’s incredibly easy to use (one of its design goals) so you can focus on what’s important (coding), it has support for both distributed and centralized workflows, it supports pushing and pulling from SFTP servers that do not have bazaar installations, and it uses revision numbers (instead of hashes), and it does so in a very intelligent way.

Unfortunately the latest version doesn’t seem to come in a tidy OS X Installer package, nor is it available via MacPorts (yet), so here are some tips to install it from source.

If you’ve previously installed Bazaar using the package installer you’ll probably want to clear out some of the files it installed prior to installing the new version:

cd /Library/Python/2.5/site-packages
sudo rm -rf bzr*
sudo rm -rf Loom-1.4.0dev0-py2.5.egg-info
sudo rm -rf subvertpy*
sudo rm -rf Extmerge-r10-py2.5.egg-info
sudo rm -rf qbzr-0.9.9-py2.5.egg-info
# we'll install the latest versions of these in a bit
sudo rm -rf BzrTools-1.14.0-py2.5.egg-info
sudo rm -rf pycrypto-2.0.1-py2.5.egg-info
sudo rm -rf paramiko*

We do that to avoid conflicts and because we want to install these plugins ourselves, so that we can use the latest versions.

Installing Dependencies

As mentioned in the note above, and on the InstallationFaq, there are 3 things that come with the package installer that you should install: Paramiko and pyCrypto (for SFTP support), and BzrTools.

Because of the way we’re installing Bazaar, you should install BzrTools *after* installing Bazaar 1.16 (detailed below). Installing Paramiko and pyCrypto is simple though, as you only need to download Paramiko (its installer will grab pyCrypto for you):

  1. Grab the latest version of Paramiko, as of this writing it’s 1.7.2:
  2. Extract the contents of the archive and ‘cd’ into the directory
  3. To build and install run these commands:
    python setup.py build
    sudo python setup.py install

Optionally, the InstallationFaq suggests installing Pyrex to speed things up.

Installing Bazaar 1.16

Download the source for 1.16 (direct link). After you’ve extracted it run these commands from the source dir:

python setup.py build
sudo python setup.py install --home /usr/local
sudo mv /usr/local/lib/python/bzr* /Library/Python/2.5/site-packages/

Note: On Snow Leopard the default Python install is 2.6, not 2.5.

Installing Bazaar Plugins on OS X

This too isn’t very clear from the Bazaar Plugins page. To install a plugin follow these steps:

  1. Pick a plugin from the plugins page and grab its branch URL, for example the URL for Rebase is:
  2. In some directory run:
    bzr branch [branch-URL]
  3. That will download the plugin source. ‘cd’ into the directory, in the above example it’s “trunk”.
  4. Build and install the plugin using the same commands as you used to install the dependencies.

That should do it. One note is that a lot of the plugins are hosted on launchpad, in which case grabbing them is simple (using ‘bzr-search’ as an example):

bzr branch lp:bzr-search

Now you can enjoy the benefits of running the latest version. :-)

Snow Leopard support coming soon.

Monday, June 15th, 2009

Right now we are hard at work improving Espionage’s stability and support for Snow Leopard. If you have a developer seed of Snow Leopard installed please know that currently Espionage will not run properly on it, so keep that in mind before installing it on a your primary machine.

Precluding any unforeseen difficulties Snow Leopard support should arrive before it’s released.

Cloak 1.1! + Artists: Win an Espionage license!

Tuesday, June 2nd, 2009

Cloak has been updated to 1.1 (download) and this brings two much needed improvements: Mac OS X 10.4 support, and an icon!

Yes, the new icon looks like it’s out of a video game.. I swear I’m a much better coder than I am an artist! Unfortunately John has too much on his plate right now and therefore cannot give Cloak a proper icon, which is why I’m holding a contest:

Win an Espionage license! (Or $24.95)

Cloak needs a nice 512×512 icon of a cloaked figure with glowing eyes. If you think you can do a better job we welcome you to try, just post a link to your icon in the comments below.

The winner will get to choose his or her prize: a free license to Espionage or $24.95 via PayPal. Additionally, your name will be placed in Cloak’s about box with an optional link to your site.

Please remember to enter a real email address when posting a comment so that we know where to reach you.

The winner (if there is one), will be announced at the end of the month, June 30th, 2009.

Enjoy! :-)