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

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


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

On 12-03-16 11:41 AM, Alexander Belchenko wrote:
> To fix the bug https://bugs.launchpad.net/bzr-explorer/+bug/956268 
> 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 = mod_branch.Branch.open(branch.get_parent())
# 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(),
                            old_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.

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

iEYEARECAAYFAk9jf2EACgkQ0F+nu1YWqI1+pQCePAkp7JYkunCzRAMzAzOav59V
wp8Anj19zsRFul7eug6dBUUaWy5DJfX/
=nqK9
-----END PGP SIGNATURE-----



More information about the bazaar mailing list