newbie question: using bzrlib api

James Westby jw+debian at jameswestby.net
Thu Mar 6 13:58:29 GMT 2008


On Thu, 2008-03-06 at 18:19 +0530, Rohit Nayak wrote:
> I am integrating bazaar into a python web application. This is what I
> am using currently to add a file:

Hi,

It doesn't sound like you are a newbie if you are already at the
stage of integrating it :)

> 
> from bzrlib import workingtree
> class bzrVCS:
>     def __init__(self, dir):
>         self.wt = workingtree.WorkingTree.open(REPODIR)
>     def add(self, path):
>         fileList = [path]
>         self.wt.add(fileList)
>     def commit(self, path, label=""):
>         fileList = [path]
>         self.wt.commit(message=label, specific_files=fileList)
> 
> This works fine.
> 
> However I am unable to figure out what the api is to
>       * get the list of previous versions (and related metadata: time
> of commit, label)

There are two steps for this. First you get the list of revision ids.
You get this from a branch, rather than a tree.

  branch = self.wt
  revisions = branch.revision_history()

now revisions[0] is the first commit, and revs[-1] is the most recent.

Now to get the information you want you need a Revision object. You
need to ask the repository for it.

  rev_id = revisions[-2]
  repo = branch.repository
  revision = repo.get_revision(rev_id)

Now you have revision.message, revision.timestamp, revision.timezone
etc.

>       * get the contents of one of the previous versions
> 

This information is stored within a revision tree. Again you ask the
repository for this using the revision_id

  tree = repo.revision_tree(rev_id)

The RevisionTree object is a little harder to use than the Revision.
What exactly are you looking to achieve? If you give some more detail
we can probably help you to do that.

A couple of things that are interesting

  tree.changes_from(other_tree)

gives you a TreeDelta which you is a form of diff.

I believe list_files() and get_file_lines() will allow you to get at the
state of the tree in that revision.

> The bzr version is 1.2.0.
> 
> Any help or pointers to relevant posts/docs would be appreciated!

Please ask for more information if I missed anything above.

Thanks,

James





More information about the bazaar mailing list