[RFC] Tree.iter_changes

Aaron Bentley aaron.bentley at utoronto.ca
Tue Sep 19 18:07:59 BST 2006


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

Hi all,

So, I decided to stop grousing about how we constantly reimplement tree
comparison, and do something about it.  I'm looking for feedback,
especially from Robert, since he's working on dirstate.

This API is intended to be a performant, universal, tree comparison routine.

Tree.iter_changes(from_tree, include_unchanged=False,
                  specific_file_ids=None)

I think the parameters are fairly clear.  I should mention that
providing specific_file_ids means that other file ids will not have any
comparison performed.  (No system calls.)

The return values is a tuple of (file_id, path, changed_content,
versioned, parent, name, kind, executable)

Path is the path in the self.

Changed_content is a boolean, describing whether the file content has
changed (including deletions, kind changes and symlink target changes).
 A value is always calculated, but this seems sensible for every use
case.  For RevisionTrees, we can always determin the sha1 cheaply.  For
WorkingTrees, if the stat matches the hashcache, we can determine the
sha1 cheaply.  If not, and the file length has changed, we know that the
file has changed.

If the file has been modified without changing its length, we'll open
the file to do a sha1, and the caller will likely also open the file.
However, this is a rare case, and it simplifies the API to accept some
inefficiency in this rare case.

The remaining values are tuples of (old, new).  versioned is a boolean
tuple that indicates whether the file is versioned in each tree.
versioned may not be equal to (False, False).

Kind indicates the file kind in each tree.  A file kind of None
indicates the file was not present.  It is legal for kind[x] to be None,
while versioned[x] is True, or vice-versa.

Parent is the parent_id of the file in each tree.  Name is the name of
the file in each tree.

Executable indicates whether the file is executable or not.  It is False
for directories and symlinks.

The attached implementation focuses on replacing the implementation of
delta._compare_trees.  Note that it is actually shorter than the
original implementation.  I anticipate some adjustment to replace
current implementations of revert and commit.

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

iD8DBQFFECPv0F+nu1YWqI0RArhGAJ9cV6g0qsFl7k7k9QRwQgHmnpV6PgCfQFxM
/MUnDfYM9F9uLU8rEva8tsw=
=fNY2
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iter_changes.patch
Type: text/x-patch
Size: 23261 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060919/b6adb3f7/attachment.bin 


More information about the bazaar mailing list