Telling if two trees are different

John Arbash Meinel john at arbash-meinel.com
Thu Oct 23 19:25:44 BST 2008


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

James Westby wrote:
> Hi all,
> 
> For the Ubuntu bzr importer I need to be able to tell, given two
> trees, whether they differ in contents. I'd like to do
> this in the most elegant/efficient way possible, and so I come
> here to ask what that would be.
> 
> The use case is given the current tip of a branch and a 
> new source package that was uploaded, does the source package
> match what was in the branch?
> 
> The source package won't actually be in a branch, but it could
> easily be turned in to a revision tree, which I suspect will be
> needed.
> 
> My guess would be iter_changes between the two trees.
> 
> Does the best API to use depend on whether the branches are local
> or remote, or anything similar to that?
> 
> Thanks,
> 
> James
> 

In general you should be able to do:

for change in tree1.iter_changes(tree2):
  has_change = True
  break
else:
  has_change = False


I don't believe it will matter (yet) if the RevisionTrees are in
different repositories, etc. As they will have loaded their full
Inventory objects to do the comparison.

When Robert's inventory work lands, then things might be a bit
different. Also, if one is a working tree, and the other is the basis
tree, we have an optimized path for 'iter_changes'.

It sounds like you will just have 2 RevisionTrees, though so nothing to
worry about there.

By using the for loop and a break, you don't really need to waste time
finding all changes, you just care about existence. I suppose another
way would be:

try:
  tree1.iter_changes(tree2).next()
  has_change = True
except StopIteration:
  has_change = False

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkAwagACgkQJdeBCYSNAAOfMQCfSzDANtVguMLSIBqz4ZABYZIM
WkkAn2akiYyEvRzU/K2YH7k/LARtTQJQ
=8UBW
-----END PGP SIGNATURE-----



More information about the bazaar mailing list