Help needed with implementing annotate

Aaron Bentley aaron.bentley at utoronto.ca
Thu Nov 29 20:41:53 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeremy Wilkins wrote:
> Hi All,
> 
> I've been doing some work on the TextMate integration with Bazaar.
> I've been trying to implement annotate support, the approach is to
> iterate over each line in the file and spit out a HTML table, which
> TextMate can render with an embedded webkit window.
> 
> The code I've got at the minute, only works if the file your trying to
> annotate had changes in the most recent commit, this is using
> annotate._annotate_file

annotate._annotate_file is private (see the leading underscore?), so you
shouldn't be using it.

It's also flawed because it doesn't provide annotation of the current
text, just the last-committed text.  That said, the problem is you're
supplying the last_revision for the tree, when you should be supplying
the last_committed_revision for the file.  This is something like:

WorkingTree.branch.basis_tree().inventory[file_id].revision.

> the other approach I've been playing with is below, using
> workingtree.annotate_iter

This is the right way, and how gannotate does it.

> tree, relpath = workingtree.WorkingTree.open_containing('filea.txt')
> fileid = tree.path2id('filea.txt')

^^ this should be tree.path2id(relpath)

> annotation = tree.annotate_iter(fileid)
> 
> for (revno_str, text) in annotation :

^^ this should be "for (revision_id, text) in annotation:"

> This seems more reliable but only gives a long string containing what
> I presume is a unique identified for the file.

It's the unique identifier of the revision that modified that line.

> Is there anyway to get
> author and rev no information from this identifier?

Yes.  For the author,

workingtree.branch.repository.get_revision(revision_id).get_apparent_author()

get_revision returns an object with lots of information about the
revision, including the branch nick and commit message.  Since you will
be retrieving many revisions, it's probably best to use get_revisions()
instead.

For the revno:

'.'.join(str(i) for i in
         workingtree.branch.get_revision_id_to_revno_map()[revision_id])

Note that get_revision_id_to_revno_map() returns a dict that you can
reuse, so only call it once.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHTyQR0F+nu1YWqI0RAsmGAJ4iXvaM5RFcS2GklVHQgb418AZxygCfbJ0x
R7uR7Fj6pQ4UxfVUneI8U4U=
=j1uJ
-----END PGP SIGNATURE-----



More information about the bazaar mailing list