Convert repositories with fast-{export,import}

Those days I faced the need of moving a set of Bazaar branches into a set of Git repository, and althought I already knew about Tailor, but I wanted a one-shot conversion and Tailor is more, ahem, tailored for periodic synchronization. So I decided to try git fast-import, because I already knew about bzr fast-import plugin which is inspired by the Git version of the thing. The Bazaar plugin includes a bzr-fast-export script which can be used to feed input data to git fast-import.

First, we need to install the Bazaar plugin. This one is easy:

mkdir -p ~/.bazaar/plugins
cd ~/.bazaar/plugins
bzr get lp:bzr-fastimport fastimport

I will be importing three branches into a Git repository, so we need to create a Git repository:

mkdir ~/myproject.git
cd ~/myproject.git
git --bare init

I suppose you have three related Bazaar branches:

  • ~/myproject is the main branch of the project. It will be imported as master branch in Git.
  • ~/myproject.branch-a and ~/myproject.branch-b are two branched whose parent is the first one.
alias bzrexp="~/.bazaar/plugins/fastimport/exporters/bzr-fast-export"
bzrexp --export-marks=../marks.bzr ../myproject \
   | git fast-import --export-marks=../marks.git
bzrexp --marks=../marks.bzr --git-branch=branch-a \
   ../myproject.branch-a | git-fast-import \
   --import-marks=../marks.git --export-marks=../marks.git
bzrexp --marks=../marks.bzr --git-branch=branch-b \
   ../myproject.branch-b | git-fast-import \
  --import-marks=../marks.git --export-marks=../marks.git

VoilĂ ! It will run in a snap, the limit will be your disk speed, as both the exporter and the importer are very fast.

One comment

  1. Now, the plugin provides a fast-export command so you can run:

    bzr fast-export

    (forget about the alias).

Leave a comment