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
1=== modified file 'breezy/bzr/inventorytree.py'
2--- breezy/bzr/inventorytree.py 2018-03-02 00:38:34 +0000
3+++ breezy/bzr/inventorytree.py 2018-03-18 13:40:22 +0000
4@@ -77,7 +77,8 @@
5 adjusted to account for existing elements that match case
6 insensitively.
7 """
8- return list(self._yield_canonical_inventory_paths(paths))
9+ with self.lock_read():
10+ return list(self._yield_canonical_inventory_paths(paths))
11
12 def get_canonical_inventory_path(self, path):
13 """Returns the first inventory item that case-insensitively matches path.
14@@ -97,7 +98,8 @@
15 :return: The input path adjusted to account for existing elements
16 that match case insensitively.
17 """
18- return next(self._yield_canonical_inventory_paths([path]))
19+ with self.lock_read():
20+ return next(self._yield_canonical_inventory_paths([path]))
21
22 def _yield_canonical_inventory_paths(self, paths):
23 for path in paths:
24@@ -112,31 +114,34 @@
25 for elt in bit_iter:
26 lelt = elt.lower()
27 new_path = None
28- for child in self.iter_children(cur_id):
29- try:
30- # XXX: it seem like if the child is known to be in the
31- # tree, we shouldn't need to go from its id back to
32- # its path -- mbp 2010-02-11
33- #
34- # XXX: it seems like we could be more efficient
35- # by just directly looking up the original name and
36- # only then searching all children; also by not
37- # chopping paths so much. -- mbp 2010-02-11
38- child_base = os.path.basename(self.id2path(child))
39- if (child_base == elt):
40- # if we found an exact match, we can stop now; if
41- # we found an approximate match we need to keep
42- # searching because there might be an exact match
43- # later.
44- cur_id = child
45- new_path = osutils.pathjoin(cur_path, child_base)
46- break
47- elif child_base.lower() == lelt:
48- cur_id = child
49- new_path = osutils.pathjoin(cur_path, child_base)
50- except errors.NoSuchId:
51- # before a change is committed we can see this error...
52- continue
53+ try:
54+ for child in self.iter_child_entries(self.id2path(cur_id), cur_id):
55+ try:
56+ # XXX: it seem like if the child is known to be in the
57+ # tree, we shouldn't need to go from its id back to
58+ # its path -- mbp 2010-02-11
59+ #
60+ # XXX: it seems like we could be more efficient
61+ # by just directly looking up the original name and
62+ # only then searching all children; also by not
63+ # chopping paths so much. -- mbp 2010-02-11
64+ child_base = os.path.basename(self.id2path(child.file_id))
65+ if (child_base == elt):
66+ # if we found an exact match, we can stop now; if
67+ # we found an approximate match we need to keep
68+ # searching because there might be an exact match
69+ # later.
70+ cur_id = child.file_id
71+ new_path = osutils.pathjoin(cur_path, child_base)
72+ break
73+ elif child_base.lower() == lelt:
74+ cur_id = child.file_id
75+ new_path = osutils.pathjoin(cur_path, child_base)
76+ except errors.NoSuchId:
77+ # before a change is committed we can see this error...
78+ continue
79+ except errors.NotADirectory:
80+ pass
81 if new_path:
82 cur_path = new_path
83 else:
84@@ -248,15 +253,13 @@
85 with self.lock_read():
86 inv, inv_file_id = self._path2inv_file_id(path, file_id)
87 try:
88- return iter(viewvalues(inv[inv_file_id].children))
89+ ie = inv[inv_file_id]
90 except errors.NoSuchId:
91 raise errors.NoSuchFile(path)
92-
93- def iter_children(self, file_id, path=None):
94- """See Tree.iter_children."""
95- entry = self.iter_entries_by_dir([file_id]).next()[1]
96- for child in viewvalues(getattr(entry, 'children', {})):
97- yield child.file_id
98+ else:
99+ if ie.kind != 'directory':
100+ raise errors.NotADirectory(path)
101+ return iter(viewvalues(ie.children))
102
103 def _get_plan_merge_data(self, file_id, other, base):
104 from . import versionedfile
105
106=== modified file 'breezy/transform.py'
107--- breezy/transform.py 2018-03-02 00:50:50 +0000
108+++ breezy/transform.py 2018-03-18 13:40:22 +0000
109@@ -2123,7 +2123,7 @@
110 self._all_children_cache[trans_id] = children
111 return children
112
113- def iter_children(self, file_id):
114+ def _iter_children(self, file_id):
115 trans_id = self._transform.trans_id_file_id(file_id)
116 for child_trans_id in self._all_children(trans_id):
117 yield self._transform.final_file_id(child_trans_id)
118@@ -2197,7 +2197,7 @@
119 """Return path, entry for items in a directory without recursing down."""
120 dir_file_id = self.path2id(dir_path)
121 ordered_ids = []
122- for file_id in self.iter_children(dir_file_id):
123+ for file_id in self._iter_children(dir_file_id):
124 trans_id = self._transform.trans_id_file_id(file_id)
125 ordered_ids.append((trans_id, file_id))
126 for entry, trans_id in self._make_inv_entries(ordered_ids):
127
128=== modified file 'breezy/tree.py'
129--- breezy/tree.py 2018-03-02 00:38:34 +0000
130+++ breezy/tree.py 2018-03-18 13:40:22 +0000
131@@ -537,14 +537,6 @@
132 """
133 return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
134
135- def iter_children(self, file_id):
136- """Iterate over the file ids of the children of an entry.
137-
138- :param file_id: File id of the entry
139- :return: Iterator over child file ids.
140- """
141- raise NotImplementedError(self.iter_children)
142-
143 def lock_read(self):
144 """Lock this tree for multiple read only operations.
145
146@@ -746,13 +738,18 @@
147 # we loop so that we handle all children of each id in both trees
148 while len(pending) > 0:
149 new_pending = set()
150- for file_id in pending:
151- for tree in trees:
152- if not tree.has_or_had_id(file_id):
153+ for tree in trees:
154+ for file_id in pending:
155+ try:
156+ path = tree.id2path(file_id)
157+ except errors.NoSuchId:
158 continue
159- for child_id in tree.iter_children(file_id):
160- if child_id not in interesting_ids:
161- new_pending.add(child_id)
162+ try:
163+ for child in tree.iter_child_entries(path, file_id):
164+ if child.file_id not in interesting_ids:
165+ new_pending.add(child.file_id)
166+ except errors.NotADirectory:
167+ pass
168 interesting_ids.update(new_pending)
169 pending = new_pending
170 return interesting_ids
171@@ -1148,7 +1145,8 @@
172 # Reusing a discarded change.
173 old_entry = self._get_entry(self.source, file_id)
174 precise_file_ids.update(
175- self.source.iter_children(file_id))
176+ child.file_id
177+ for child in self.source.iter_child_entries(result[1][0]))
178 changed_file_ids.add(result[0])
179 yield result
180

Subscribers

People subscribed via source and target branches