IAmTheRockstar

Yes. Yes I am.
More Advanced Bazaar Concepts
January 23 2009

So I had this idea for yet another Bazaar post about some more advanced topics, and concepts that my workflow has eventually evolved to incorporate. Among these concepts are shared repositories, lightweight checkouts, and branches with no working trees. I'll do my best to explain these concepts, and why I find them to be of benefit, but if there are questions, please feel free to leave a comment and I'll do my best to answer those questions.

Shared repositories

If you work on a project on a regular basis, you really need to create a shared repository for your project. The basic idea of a shared repository is that you keep all your revisions in a pool together. For instance, you have a local mirror of trunk, and since you share those revisions among your branches, when you create a branch from that local mirror, there's very little overhead to creating the branch, since the revisions don't need to be copied.

I keep my various shared repositories in a folder called ~/Projects/repos with each project having its own folders there. When I want to hack on a new project, like, say, Loggerhead, I have the following process:

$ mkdir ~/Projects/repos/loggerhead
$ cd ~/Projects/repos/loggerhead
$ bzr init-repo --no-trees .
$ bzr branch lp:loggerhead

Now, every time I branch from ~/Projects/repos/loggerhead/loggerhead into ~/Projects/repos/loggerhead/, I don't actually get any new revisions, just a new branch using the old revisions. I don't think this really saves on space too much, but it makes the overhead of branching much cheaper.

But wait! Why --no-trees? How the heck do you work if you don't have a working tree? Ah, so now we move on to my next point.

Lightweight checkouts

So I have two branches in ~/Projects/repos/loggerhead, the mirror of trunk, and a feature branch we just created. Neither that feature branch nor the local trunk have anything in them except the .bzr folder. No working tree. So let's back up a dir to ~/Projects where I keep my working trees. So now I'm going to create a folder to house my Loggerhead working trees.

$ mkdir ~/Projects/loggerhead
$ cd ~/Projects/loggerhead
$ bzr checkout --lightweight ~/Projects/repos/loggerhead/loggerhead
$ bzr checkout --lightweight ~/Projects/repos/loggerhead/feature-branch

Now I have working trees to work with. When I commit, those committed revisions go back to my branch, and in effect, to my shared repository. Now my working tree is completely separate from the branch itself. I can easily delete the working tree when I'm done with it without losing the branch, and when I decide to delete the branch, I still have those revisions hanging around (in most cases, they've also been merged into trunk).

I can also treat that lightweight checkout of the trunk mirror to branch from, merge, commit, etc. as if it was the branch itself, but now there is a clear separation between where I work and where I store my revision data.

Using cbranch

So we've got two bzr commands to type, the branch command and the lightweight checkout command. If you use bzrtools you can do this in one easy step by setting a few bzr settings in your ~/.bazaar/locations.conf This is what I have set for my directory structure/layout:

[/home/rockstar/Projects]
cbranch_target = /home/rockstar/Projects/repos
cbranch_target:policy = appendpath

I also want to set an alias in ~/.bazaar/bazaar.conf to give me lightweight checkouts.

[ALIASES]
cbranch = cbranch --lightweight

Now, when I'm ~/Projects/loggerhead I can just bzr cbranch loggerhead new-feature-branch and bzr will automatically create a branch in ~/Projects/repos/loggerhead and then create the lightweight checkout in ~/Projects/loggerhead bound to that branch.

All opinions expressed here constitute my personal opinion, and do not necessarily represent the opinion of any other organization or person, including, but not limited to, my fellow employees, my employer, its clients or their agents.