Comment 4 for bug 864435

Revision history for this message
Tom Prince (tom.prince) wrote :

I wrote the following code to generate a pretty printed diff from bzr. It just currently has hard-coded branch name and dumps to stdout. I was wondering if it would make more sense to generate the diff on commit, rather than generating them on demand.

#!/usr/bin/python

from bzrlib.branch import Branch
from bzrlib.diff import show_diff_trees
from bzrlib.revisiontree import RevisionTree

import StringIO

diff = StringIO.StringIO()

b = Branch.open("http://svn.twistedmatrix.com/bzr/Twisted/branches/check-zi-version-5935")
t = Branch.open("http://svn.twistedmatrix.com/bzr/Twisted/trunk")
b.lock_read()
t.lock_read()

try:
    rev_b = b.last_revision()
    rev_t = t.last_revision()
    graph = b.repository.get_graph(t.repository)
    rev_id = graph.find_unique_lca(rev_b, rev_t)

    revtree_b = b.basis_tree()
    revtree_a = RevisionTree(b.repository, rev_id)
    revtree_a = b.repository.revision_tree(rev_id)
    show_diff_trees(revtree_a, revtree_b, diff)

finally:
    b.unlock()
    t.unlock()

from pygments import highlight
from pygments.lexers import DiffLexer as PythonLexer
from pygments.formatters import HtmlFormatter

print highlight(diff.getvalue(), PythonLexer(), HtmlFormatter(full=True))