Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a file that is tracked using bzr, and I'd like to script the creation of a diff between it's current (current as in current, not latest commited), and latest commited version that is tagged.

Does anyone know how to accomplish this? Not much of a bzr scripting or a Python expert.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Something like this should do the trick:

#!/usr/bin/env python

import commands
import sys
import os

# Get the revision number of the most recent tagged commit.
tags = commands.getoutput("bzr tags --sort=time")
latest = tags.split()[-1]

target = sys.argv[-1]
if not os.path.isfile(target):
    print "Error, no such file: '"+target+"'"

print commands.getoutput("bzr diff "+target+" -r "+latest)


 python diff-from-tagged.py test


=== modified file 'test'
--- test    2011-01-08 19:20:31 +0000
+++ test    2011-01-08 20:00:12 +0000
@@ -1,1 +1,2 @@
+The quick brown fox
share|improve this answer
Thanks much. Here's also the Lua version I came up with (but forgot to update the question. More helps) <code> local f = assert(io.popen("bzr tags --sort=time | tail -1", 'r')) local s = assert(f:read('*a')) f:close() tagname = string.match(s, "^([^ ]+)") assert(tagname) os.execute(string.format([[bzr diff -r tag:%s "myfile" > 'changes']], tagname))</code> –  Vadi Jan 10 '11 at 17:43
@Vadi -- yow. Why don't you add that to your question anyway, so you can format it with <code> tags? :) –  belacq Jan 29 '11 at 4:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.