How to open branch object equivalent of -r ancestor::parent

Aaron Bentley aaron at
Fri Mar 16 17:58:57 UTC 2012

Hash: SHA1

On 12-03-16 11:41 AM, Alexander Belchenko wrote:
> To fix the bug 
> I need to open ancestor related to parent branch instead of tip of 
> parent branch itself.
> Current code does today:
> old_branch =
> mod_branch.Branch.open_containing(branch.get_parent())[0]
> Which is equivalent of -r branch::parent
> I need this to be changed to be equivalent -r ancestor::parent
> Any suggestions or code snippets will help.

What you ask is technically possible, but the difference between -r
branch::parent and -r ancestor::parent is the *revision* they select,
not the branch they open.

We'll need the revision anyhow, so let's start there.  To get the
revision used by ancestor::parent, you'll need to

# Ensure you have both branches open
old_branch =
# Get a graph, so you can find the common ancestor (LCA)
graph = old_branch.repository.get_graph(branch.repository)
# Find the LCA of the revisions
lca = graph.find_unique_lca(branch.last_revision(),

That should give you the revision you need to diff against.

If you really need to specify a branch, not a revision, then I guess
you can make a memory branch, stacked on either of the other branches,
and call Branch.set_last_revision_info(1, lca) on it.  But I recommend
avoiding this if at all possible.

Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla -


More information about the bazaar mailing list