Merge lp:~bzr/bzr/iter-entries-norecurse into lp:~bzr/bzr/trunk-old

Proposed by Ian Clatworthy
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bzr/bzr/iter-entries-norecurse
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 84 lines
To merge this branch: bzr merge lp:~bzr/bzr/iter-entries-norecurse
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+6663@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

This patch extends Inventory.iter_entries() with a parameter making recursing down optional. This is used by my patches-under-development that speed up selective file commit and the ls command. As such, I'd appreciate a review soon so I can complete the follow-on patches.

Revision history for this message
John A Meinel (jameinel) wrote :

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

Ian Clatworthy wrote:
> Ian Clatworthy has proposed merging lp:~bzr/bzr/iter-entries-norecurse into lp:bzr.
>
> Requested reviews:
> Bazaar Developers (bzr)
>
> This patch extends Inventory.iter_entries() with a parameter making recursing down optional. This is used by my patches-under-development that speed up selective file commit and the ls command. As such, I'd appreciate a review soon so I can complete the follow-on patches.
>

I'll note that if you use 'iter_entries_by_dir()' you don't have to
worry about passing 'no_recurse=True', you can just stop iterating once
you find you are no longer in that directory. Just a thought.

  Review:comment

John
=:->

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

iEYEARECAAYFAkoQ358ACgkQJdeBCYSNAANa0QCgvqwr+1PDmVd42KWoNJC0nq88
ickAoKGT0c6FEdx4GZyZ5hXCuDHUEmhh
=xf+w
-----END PGP SIGNATURE-----

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

> I'll note that if you use 'iter_entries_by_dir()' you don't have to
> worry about passing 'no_recurse=True', you can just stop iterating once
> you find you are no longer in that directory. Just a thought.

That's true but it seems more fragile to me. (I'm not confident that all implementations of iter_entries_by_dir() will strictly implement the ordering in the future.) By making it a parameter, the behaviour is more explicit and easier to test IMO.

Revision history for this message
John A Meinel (jameinel) wrote :

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

Ian Clatworthy wrote:
>> I'll note that if you use 'iter_entries_by_dir()' you don't have to
>> worry about passing 'no_recurse=True', you can just stop iterating once
>> you find you are no longer in that directory. Just a thought.
>
> That's true but it seems more fragile to me. (I'm not confident that all implementations of iter_entries_by_dir() will strictly implement the ordering in the future.) By making it a parameter, the behaviour is more explicit and easier to test IMO.

iter_entries_by_dir has strictly enforced ordering so that you can walk
iterators side-by-side. The ordering *is* part of the api.

That said, a flag certainly seems a bit more obvious.

John
=:->

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

iEYEARECAAYFAkoRcDIACgkQJdeBCYSNAAO0IQCeIrf3ZdqZxV92gtyU+VoDSjxh
XP4An0TuM9IpJceLtusMBFa/RaJGay6K
=NRKc
-----END PGP SIGNATURE-----

Revision history for this message
Robert Collins (lifeless) wrote :

On Mon, 2009-05-18 at 03:20 +0000, Ian Clatworthy wrote:
> Ian Clatworthy has proposed merging lp:~bzr/bzr/iter-entries-norecurse into lp:bzr.
>
> Requested reviews:
> Bazaar Developers (bzr)
>
> This patch extends Inventory.iter_entries() with a parameter making
> recursing down optional. This is used by my patches-under-development
> that speed up selective file commit and the ls command. As such, I'd
> appreciate a review soon so I can complete the follow-on patches.

I haven't read the code [yet]. A few comments:
 - with respect to commit and so on, I was actually suggesting doing
this under the hood: we _really_ don't want to exit out of iter_changes
and back into it. Doing so will lose state calculated about what we've
seen, and may lead to race conditions updating the hash cache.
 - This is a fine feature to have in its own right

-Rob

Revision history for this message
John A Meinel (jameinel) wrote :

I would probably say that we should use "iter_entries_by_dir" whenever possible, as that is the optimal order for walking directories, etc.

I don't have a specific problem with this change, as it does make the request explicit.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/inventory.py'
--- bzrlib/inventory.py 2009-05-26 10:08:17 +0000
+++ bzrlib/inventory.py 2009-06-02 19:37:38 +0000
@@ -747,8 +747,13 @@
747 [parent.name for parent in747 [parent.name for parent in
748 self._iter_file_id_parents(file_id)][:-1]))748 self._iter_file_id_parents(file_id)][:-1]))
749749
750 def iter_entries(self, from_dir=None):750 def iter_entries(self, from_dir=None, recursive=True):
751 """Return (path, entry) pairs, in order by name."""751 """Return (path, entry) pairs, in order by name.
752
753 :param from_dir: if None, start from the root,
754 otherwise start from this directory (either file-id or entry)
755 :param recursive: recurse into directories or not
756 """
752 if from_dir is None:757 if from_dir is None:
753 if self.root is None:758 if self.root is None:
754 return759 return
@@ -761,6 +766,10 @@
761 # 440ms/663ms (inline/total) to 116ms/116ms766 # 440ms/663ms (inline/total) to 116ms/116ms
762 children = from_dir.children.items()767 children = from_dir.children.items()
763 children.sort()768 children.sort()
769 if not recursive:
770 for name, ie in children:
771 yield name, ie
772 return
764 children = collections.deque(children)773 children = collections.deque(children)
765 stack = [(u'', children)]774 stack = [(u'', children)]
766 while stack:775 while stack:
767776
=== modified file 'bzrlib/tests/inventory_implementations/basics.py'
--- bzrlib/tests/inventory_implementations/basics.py 2009-04-09 20:23:07 +0000
+++ bzrlib/tests/inventory_implementations/basics.py 2009-06-02 19:37:38 +0000
@@ -211,8 +211,12 @@
211 ('doc', 'directory', 'doc-id'),211 ('doc', 'directory', 'doc-id'),
212 ('src/hello.c', 'file', 'hello-id'),212 ('src/hello.c', 'file', 'hello-id'),
213 ('src/bye.c', 'file', 'bye-id'),213 ('src/bye.c', 'file', 'bye-id'),
214 ('src/sub', 'directory', 'sub-id'),
215 ('src/sub/a', 'file', 'a-id'),
214 ('Makefile', 'file', 'makefile-id')]:216 ('Makefile', 'file', 'makefile-id')]:
215 inv.add_path(*args)217 inv.add_path(*args)
218
219 # Test all entries
216 self.assertEqual([220 self.assertEqual([
217 ('', 'tree-root'),221 ('', 'tree-root'),
218 ('Makefile', 'makefile-id'),222 ('Makefile', 'makefile-id'),
@@ -220,8 +224,36 @@
220 ('src', 'src-id'),224 ('src', 'src-id'),
221 ('src/bye.c', 'bye-id'),225 ('src/bye.c', 'bye-id'),
222 ('src/hello.c', 'hello-id'),226 ('src/hello.c', 'hello-id'),
227 ('src/sub', 'sub-id'),
228 ('src/sub/a', 'a-id'),
223 ], [(path, ie.file_id) for path, ie in inv.iter_entries()])229 ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
224230
231 # Test a subdirectory
232 self.assertEqual([
233 ('bye.c', 'bye-id'),
234 ('hello.c', 'hello-id'),
235 ('sub', 'sub-id'),
236 ('sub/a', 'a-id'),
237 ], [(path, ie.file_id) for path, ie in inv.iter_entries(
238 from_dir='src-id')])
239
240 # Test not recursing at the root level
241 self.assertEqual([
242 ('', 'tree-root'),
243 ('Makefile', 'makefile-id'),
244 ('doc', 'doc-id'),
245 ('src', 'src-id'),
246 ], [(path, ie.file_id) for path, ie in inv.iter_entries(
247 recursive=False)])
248
249 # Test not recursing at a subdirectory level
250 self.assertEqual([
251 ('bye.c', 'bye-id'),
252 ('hello.c', 'hello-id'),
253 ('sub', 'sub-id'),
254 ], [(path, ie.file_id) for path, ie in inv.iter_entries(
255 from_dir='src-id', recursive=False)])
256
225 def test_iter_just_entries(self):257 def test_iter_just_entries(self):
226 inv = self.make_inventory('tree-root')258 inv = self.make_inventory('tree-root')
227 for args in [('src', 'directory', 'src-id'),259 for args in [('src', 'directory', 'src-id'),