Merge lp:~jelmer/brz/iter-children into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/iter-children
Merge into: lp:brz
Diff against target: 179 lines (+52/-51)
3 files modified
breezy/bzr/inventorytree.py (+37/-34)
breezy/transform.py (+2/-2)
breezy/tree.py (+13/-15)
To merge this branch: bzr merge lp:~jelmer/brz/iter-children
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+341576@code.launchpad.net

Commit message

Remove Tree.iter_children in favor of Tree.iter_child_entries.

Description of the change

Remove Tree.iter_children in favor of Tree.iter_child_entries.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/bzr/inventorytree.py'
--- breezy/bzr/inventorytree.py 2018-03-02 00:38:34 +0000
+++ breezy/bzr/inventorytree.py 2018-03-18 13:40:22 +0000
@@ -77,7 +77,8 @@
77 adjusted to account for existing elements that match case77 adjusted to account for existing elements that match case
78 insensitively.78 insensitively.
79 """79 """
80 return list(self._yield_canonical_inventory_paths(paths))80 with self.lock_read():
81 return list(self._yield_canonical_inventory_paths(paths))
8182
82 def get_canonical_inventory_path(self, path):83 def get_canonical_inventory_path(self, path):
83 """Returns the first inventory item that case-insensitively matches path.84 """Returns the first inventory item that case-insensitively matches path.
@@ -97,7 +98,8 @@
97 :return: The input path adjusted to account for existing elements98 :return: The input path adjusted to account for existing elements
98 that match case insensitively.99 that match case insensitively.
99 """100 """
100 return next(self._yield_canonical_inventory_paths([path]))101 with self.lock_read():
102 return next(self._yield_canonical_inventory_paths([path]))
101103
102 def _yield_canonical_inventory_paths(self, paths):104 def _yield_canonical_inventory_paths(self, paths):
103 for path in paths:105 for path in paths:
@@ -112,31 +114,34 @@
112 for elt in bit_iter:114 for elt in bit_iter:
113 lelt = elt.lower()115 lelt = elt.lower()
114 new_path = None116 new_path = None
115 for child in self.iter_children(cur_id):117 try:
116 try:118 for child in self.iter_child_entries(self.id2path(cur_id), cur_id):
117 # XXX: it seem like if the child is known to be in the119 try:
118 # tree, we shouldn't need to go from its id back to120 # XXX: it seem like if the child is known to be in the
119 # its path -- mbp 2010-02-11121 # tree, we shouldn't need to go from its id back to
120 #122 # its path -- mbp 2010-02-11
121 # XXX: it seems like we could be more efficient123 #
122 # by just directly looking up the original name and124 # XXX: it seems like we could be more efficient
123 # only then searching all children; also by not125 # by just directly looking up the original name and
124 # chopping paths so much. -- mbp 2010-02-11126 # only then searching all children; also by not
125 child_base = os.path.basename(self.id2path(child))127 # chopping paths so much. -- mbp 2010-02-11
126 if (child_base == elt):128 child_base = os.path.basename(self.id2path(child.file_id))
127 # if we found an exact match, we can stop now; if129 if (child_base == elt):
128 # we found an approximate match we need to keep130 # if we found an exact match, we can stop now; if
129 # searching because there might be an exact match131 # we found an approximate match we need to keep
130 # later. 132 # searching because there might be an exact match
131 cur_id = child133 # later.
132 new_path = osutils.pathjoin(cur_path, child_base)134 cur_id = child.file_id
133 break135 new_path = osutils.pathjoin(cur_path, child_base)
134 elif child_base.lower() == lelt:136 break
135 cur_id = child137 elif child_base.lower() == lelt:
136 new_path = osutils.pathjoin(cur_path, child_base)138 cur_id = child.file_id
137 except errors.NoSuchId:139 new_path = osutils.pathjoin(cur_path, child_base)
138 # before a change is committed we can see this error...140 except errors.NoSuchId:
139 continue141 # before a change is committed we can see this error...
142 continue
143 except errors.NotADirectory:
144 pass
140 if new_path:145 if new_path:
141 cur_path = new_path146 cur_path = new_path
142 else:147 else:
@@ -248,15 +253,13 @@
248 with self.lock_read():253 with self.lock_read():
249 inv, inv_file_id = self._path2inv_file_id(path, file_id)254 inv, inv_file_id = self._path2inv_file_id(path, file_id)
250 try:255 try:
251 return iter(viewvalues(inv[inv_file_id].children))256 ie = inv[inv_file_id]
252 except errors.NoSuchId:257 except errors.NoSuchId:
253 raise errors.NoSuchFile(path)258 raise errors.NoSuchFile(path)
254259 else:
255 def iter_children(self, file_id, path=None):260 if ie.kind != 'directory':
256 """See Tree.iter_children."""261 raise errors.NotADirectory(path)
257 entry = self.iter_entries_by_dir([file_id]).next()[1]262 return iter(viewvalues(ie.children))
258 for child in viewvalues(getattr(entry, 'children', {})):
259 yield child.file_id
260263
261 def _get_plan_merge_data(self, file_id, other, base):264 def _get_plan_merge_data(self, file_id, other, base):
262 from . import versionedfile265 from . import versionedfile
263266
=== modified file 'breezy/transform.py'
--- breezy/transform.py 2018-03-02 00:50:50 +0000
+++ breezy/transform.py 2018-03-18 13:40:22 +0000
@@ -2123,7 +2123,7 @@
2123 self._all_children_cache[trans_id] = children2123 self._all_children_cache[trans_id] = children
2124 return children2124 return children
21252125
2126 def iter_children(self, file_id):2126 def _iter_children(self, file_id):
2127 trans_id = self._transform.trans_id_file_id(file_id)2127 trans_id = self._transform.trans_id_file_id(file_id)
2128 for child_trans_id in self._all_children(trans_id):2128 for child_trans_id in self._all_children(trans_id):
2129 yield self._transform.final_file_id(child_trans_id)2129 yield self._transform.final_file_id(child_trans_id)
@@ -2197,7 +2197,7 @@
2197 """Return path, entry for items in a directory without recursing down."""2197 """Return path, entry for items in a directory without recursing down."""
2198 dir_file_id = self.path2id(dir_path)2198 dir_file_id = self.path2id(dir_path)
2199 ordered_ids = []2199 ordered_ids = []
2200 for file_id in self.iter_children(dir_file_id):2200 for file_id in self._iter_children(dir_file_id):
2201 trans_id = self._transform.trans_id_file_id(file_id)2201 trans_id = self._transform.trans_id_file_id(file_id)
2202 ordered_ids.append((trans_id, file_id))2202 ordered_ids.append((trans_id, file_id))
2203 for entry, trans_id in self._make_inv_entries(ordered_ids):2203 for entry, trans_id in self._make_inv_entries(ordered_ids):
22042204
=== modified file 'breezy/tree.py'
--- breezy/tree.py 2018-03-02 00:38:34 +0000
+++ breezy/tree.py 2018-03-18 13:40:22 +0000
@@ -537,14 +537,6 @@
537 """537 """
538 return find_ids_across_trees(paths, [self] + list(trees), require_versioned)538 return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
539539
540 def iter_children(self, file_id):
541 """Iterate over the file ids of the children of an entry.
542
543 :param file_id: File id of the entry
544 :return: Iterator over child file ids.
545 """
546 raise NotImplementedError(self.iter_children)
547
548 def lock_read(self):540 def lock_read(self):
549 """Lock this tree for multiple read only operations.541 """Lock this tree for multiple read only operations.
550542
@@ -746,13 +738,18 @@
746 # we loop so that we handle all children of each id in both trees738 # we loop so that we handle all children of each id in both trees
747 while len(pending) > 0:739 while len(pending) > 0:
748 new_pending = set()740 new_pending = set()
749 for file_id in pending:741 for tree in trees:
750 for tree in trees:742 for file_id in pending:
751 if not tree.has_or_had_id(file_id):743 try:
744 path = tree.id2path(file_id)
745 except errors.NoSuchId:
752 continue746 continue
753 for child_id in tree.iter_children(file_id):747 try:
754 if child_id not in interesting_ids:748 for child in tree.iter_child_entries(path, file_id):
755 new_pending.add(child_id)749 if child.file_id not in interesting_ids:
750 new_pending.add(child.file_id)
751 except errors.NotADirectory:
752 pass
756 interesting_ids.update(new_pending)753 interesting_ids.update(new_pending)
757 pending = new_pending754 pending = new_pending
758 return interesting_ids755 return interesting_ids
@@ -1148,7 +1145,8 @@
1148 # Reusing a discarded change.1145 # Reusing a discarded change.
1149 old_entry = self._get_entry(self.source, file_id)1146 old_entry = self._get_entry(self.source, file_id)
1150 precise_file_ids.update(1147 precise_file_ids.update(
1151 self.source.iter_children(file_id))1148 child.file_id
1149 for child in self.source.iter_child_entries(result[1][0]))
1152 changed_file_ids.add(result[0])1150 changed_file_ids.add(result[0])
1153 yield result1151 yield result
11541152

Subscribers

People subscribed via source and target branches