Ubuntu – How to create a diff of a file between it’s current and the latest tagged version in bzr

bazaarpython

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.

Best Answer

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+"'"
    sys.exit(1)

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

Usage:

 python diff-from-tagged.py test

Output:

=== modified file 'test'
--- test    2011-01-08 19:20:31 +0000
+++ test    2011-01-08 20:00:12 +0000
@@ -1,1 +1,2 @@
 dfsafd
+The quick brown fox
Related Question