6

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.

1 Answer 1

4

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
2
  • 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> Jan 10, 2011 at 17:43
  • @Vadi -- yow. Why don't you add that to your question anyway, so you can format it with <code> tags? :)
    – belacqua
    Jan 29, 2011 at 4:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .