Generate a Diff from a plugin
John Arbash Meinel
john at arbash-meinel.com
Thu Jun 18 16:33:26 BST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Patrick Dobbs wrote:
> Hi,
>
> We're using BZR with the "Decentralized with shared mainline" workflow.
> We want to integrate with our bug tracker (http://www.rap-x.com), but we
> need to be able to work offline. So we've created a Push plugin that
> loops through revisions in the current push, checks each revision for a
> bug id, and then posts this bug through a soap call:
>
> def post_push_hook(push_result):
> current_rev_no = push_result.old_revno
> source = push_result.source_branch
> while current_rev_no <= push_result.new_revno:
> current_rev_id = source.get_rev_id(current_rev_no)
> message = source.repository.get_revision(current_rev_id).message
> bug_message = re.search("[\s|^](\#)(\d+)",message)
> if bug_message:
> bug_id = bug_message.group(2)
> do_bugtracking_stuff(message,bug_id)
>
> However, we'd like to be able to get a diff for each revision at the
> same time (the DIFF will be added to the bug tracker comment). I've dug
> a bit into bzrlib but have got confused with
> branches/trees/repositories/deltas and was hoping that someone more au
> fait with the api could advise me.
>
> So, in summary, can anyone on this list advise me how, given a Branch
> object and two revision numbers, it is best to generate a diff (as a
> string)?
>
> Thanks for any suggestions.
>
> Patrick
There are easier and harder ways.
I'm pretty sure the easiest way is:
import cStringIO
from bzrlib import branch, diff
b = branch.Branch.open(path)
b.lock_read()
# Convert the revnos to revision ids
rev_id1 = b.revision_id_to_revno(revno1)
rev_id2 = b.revision_id_to_revno(revno2)
tree1, tree2 = b.repository.revision_trees([rev_id1, rev_id2])
out = cStringIO.StringIO()
diff.show_diff_trees(tree1, tree2, out, old_label='', new_label='')
out_as_str = out.getvalue()
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAko6XkYACgkQJdeBCYSNAAOKOQCgmq6pdBJDmAA7EarKgX5tYlBh
TisAnAqBh07QbNrfvSt1TWEos1GtLqMm
=0hHc
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list