Jeb Wilkins

Coding and climbing in Cumbria.

TextMate Bundle for Bazaar Integration

Download Bazaar.tmbundle

I’ve been playing around with Bazaar NG lately, and really quite like it, the only problem is I’m a TextMate user so am used to pretty good subversion integration. After a poke around I found a TextMate bundle on the Bazaar website created by John Whitley, this works for the local use case, eg adding, removing, diffing files with only one flaw - no Commit function - so I decided to add one. First rule was I wanted to be able to choose which files I actually commit, much like the existing Subversion bundle, second rule was I wanted to use the bzr library, rather than calling the bzr command line - I figured it was the ‘right way’ to do it and I’d learn more.

After a week of poking at the Subversion bundle, the bzrlib source and some daft questions to the really helpful guys on the bzr list I’d just about worked out how to get status information (to generate the list of files in the commit window), how to show the commit window, and how to subsequently do the commit based on the response. This turns out to be easier than expected - once you know how, theres not really any docs on this yet though I might try and add a page to their wiki.

First up you need to grab a working tree object

from bzrlib import workingtree wt = workingtree.WorkingTree.open('/home/jebw/bzrtest')

From this object you can add/remove files, and perform commits - it represents your working tree you’ve been busy editing. Its functions are spread over the WorkingTree object (from workingtree.py), MutableTree (from mutabletree.py) and Tree (from tree.py)

Next up we want to grab our list of changed files - we do this by creating a Delta object of the changes between trees - in this case the difference between our WorkingTree and the Tree it was derived from

from bzrlib import delta changes = wt.changes_from(wt.basis_tree())

changes is a delta object with various lists for different types of changed files - eg changes.added is a list of files which have been added and changes.removed is a list of files which have been removed.

From this I built up a list of the files I was interested in. CommitWindow.app, which shows the commit window in the Subversion bundle, takes a list of files, and returns a string for use with ‘svn ci’ - eg “-m ‘my commit message’ ‘fileA.txt’ ‘fileB.txt’”

parsing this output gives me my commit message and the files I want to commit, which is done from our WorkingTree object, eg

wt.commit(message='my commit message', specified_files=list_of_files_to_commit)

Hopefully over the next couple of months I’ll flesh out the functions for the local use case of bzr, and maybe add the ability to branch/push/pull.