I recently converted most of the Debian packaging for Telepathy and related projects from bzr to git, while changing the repository contents from just the debian/ directory to the whole source tree. Here's the recipe, using the latest one to be converted (pymsn) as an example.

Create a repository

mkdir pymsn
cd pymsn
git init

Mass tarball import

  • download all the tarballs into ../tarballs

  • rename all the tarballs to *.orig.tar.gz:

      rename 's/^pymsn-/pymsn_/' *.tar.gz
      rename 's/\.tar\.gz$/.orig.tar.gz/' *.tar.gz
    
  • use git-import-orig to import them:

      cd ../pymsn
      ls ../tarballs/pymsn_*.orig.tar.gz
      for v in 0.2 0.2.1 0.2.2 0.3.0 0.3.1 0.3.2 0.3.3; do \
      git-import-orig --no-merge --no-dch --pristine-tar \
          -u $v ../tarballs/pymsn_$v.orig.tar.gz; done
    
  • throw away the resulting master branch in favour of using one we convert from bzr later:

      git checkout upstream
      git branch -D master
    

Converting the Debian packaging

This has the slight complication that in some (but not all) of the bzr commits, the repository contained only the contents of the debian directory, in the root of the repository. So, I needed to rewrite history, with this script:

#!/bin/sh
# index-filter.sh
if git ls-files -s | grep debian; then
    :
else
    git ls-files -s |
        sed -e "s-\t-&debian/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
fi
  • Download unstable and experimental packaging into ../pymsn-experimental and ../pymsn-unstable

  • Use bzr-fast-export and git-fast-import to import the two branches:

      ~/.bazaar/plugins/fastimport/exporters/bzr-fast-export.py \
          ../pymsn-unstable | git fast-import
    
      git branch -m master debian-lenny
    
      ~/.bazaar/plugins/fastimport/exporters/bzr-fast-export.py \
          ../pymsn-experimental | git fast-import
    
      git branch -m master debian
    
      git branch -D tmp
    
  • Rewrite history so changelog, control etc. are consistently inside a debian directory, with the script shown above:

      git filter-branch --index-filter $(pwd)/../index-filter.sh debian-lenny
      rm -r .git/refs/original
    
      git filter-branch --index-filter $(pwd)/../index-filter.sh debian
      rm -r .git/refs/original
    
  • Merge the appropriate upstream versions into each branch:

      git checkout debian
      git merge upstream/0.3.3
      vim debian/control        # and change Vcs-Bzr to Vcs-Git
      dch "Move packaging to git"
      debcommit -a
    
      git checkout debian-lenny
      git merge upstream/0.3.1
      vim debian/control        # and change Vcs-Bzr to Vcs-Git
      dch "Move packaging to git"
      debcommit -a
    
  • Rescue Debian patches and put them on a debian-patches branch, which is rebased with each upstream release. For pymsn, there aren't any patches in the debian branch at the moment:

      git branch debian-patches upstream/0.3.3
    

    but there is one in the debian-lenny branch:

      git branch debian-lenny-patches upstream/0.3.1
      git checkout debian-lenny
      cp debian/patches/00-fix-dns-resolution.diff ..
      git checkout debian-lenny-patches
      patch -p1 < ../00-fix-dns-resolution.diff
      git commit -a
    
  • Make a repository on alioth:

      cd /git/pkg-telepathy
      GIT_DIR=pymsn.git git init --bare --shared
      GIT_DIR=pymsn.git git config hooks.mailinglist ...
      vim pymsn.git/description
    
  • Push to the repository:

      git gc --aggressive
      git remote add origin git+ssh://git.debian.org/git/pkg-telepathy/pymsn.git
      git push --all
    
  • On alioth, do some more setup after the initial push:

      cat > pymsn.git/hooks/post-receive <<EOF
      #!/bin/sh
      exec /usr/local/bin/git-commit-notice
      EOF
      chmod +x pymsn.git/hooks/post-receive
      GIT_DIR=pymsn.git git symbolic-ref HEAD refs/heads/debian
    
  • Mark the old repositories as no longer used:

      cd ../pymsn-unstable
      dch $'This repository is no longer used, instead please use git:\n'\
      "git://git.debian.org/git/pkg-telepathy/pymsn.git" -c changelog
      debcommit -c changelog
      bzr push
      cd ../pymsn-experimental
      dch $'This repository is no longer used, instead please use git:\n'\
      "git://git.debian.org/git/pkg-telepathy/pymsn.git" -c changelog
      debcommit -c changelog
      bzr push
      cd ../pymsn