3 months ago

Save time and disk space by using Bazaar's repositories.

Starting from scratch

Create a new repository and create a branch within it. I'm going to use MAAS here, but you should use whichever project you're interested in here, provided it manages its code with Bazaar.

$ bzr init-repo maas
Shared repository with trees (format: 2a)
Location:
  shared repository: maas
$ cd maas
$ bzr branch lp:maas trunk
Branched 5593 revisions.

It doesn't matter what you call that branch, or what branch you start with. The essence of why this is useful is because the history of every branch created within the repository directory is shared with all the other branches. This means that starting a new branch is quick — just a copy of the working tree, with a little additional disk space used for branch history:

$ du -sh .bzr */.bzr
116M    .bzr
604K    trunk/.bzr
$ bzr branch trunk new-feature
Branched 5593 revisions.
$ du -sh .bzr */.bzr
116M    .bzr
604K    new-feature/.bzr
604K    trunk/.bzr

Migrating

If you have a number of branches already, you'll want to migrate.

For example:

$ du -sh .bzr */.bzr
du: cannot access '.bzr': No such file or directory
117M    old-feature/.bzr
117M    trunk/.bzr

Create the repository in the parent directory, then reconfigure the branches:

$ bzr init-repo .
Shared repository with trees (format: 2a)
Location:
  shared repository: .
$ bzr reconfigure trunk --use-shared
$ bzr reconfigure old-feature --use-shared

Repeat that for the rest of your branches. The first reconfigure will take some time but the second and subsequent will be quick.

That's it.

$ du -sh .bzr */.bzr                                                
116M    .bzr
604K    old-feature/.bzr
604K    trunk/.bzr

In other respects these branches / working-trees behave the same as their standalone cousins.

← Python: explicit versus implicit boolean conditions