##// END OF EJS Templates
discovery: move children computation in its own method...
marmoute -
r42050:d5e6ae6e default
parent child Browse files
Show More
@@ -171,6 +171,32 b' class partialdiscovery(object):'
171 return getrev(r)[5:6]
171 return getrev(r)[5:6]
172 return getparents
172 return getparents
173
173
174 def _childrengetter(self, revs):
175
176 # _updatesample() essentially does interaction over revisions to look
177 # up their children. This lookup is expensive and doing it in a loop is
178 # quadratic. We precompute the children for all relevant revisions and
179 # make the lookup in _updatesample() a simple dict lookup.
180 #
181 # Because this function can be called multiple times during discovery,
182 # we may still perform redundant work and there is room to optimize
183 # this by keeping a persistent cache of children across invocations.
184 children = {}
185
186 parentrevs = self._parentsgetter()
187
188 for rev in sorted(revs):
189 # Always ensure revision has an entry so we don't need to worry
190 # about missing keys.
191 children[rev] = []
192 for prev in parentrevs(rev):
193 if prev == nullrev:
194 continue
195 c = children.get(prev)
196 if c is not None:
197 c.append(rev)
198 return children.__getitem__
199
174 def takequicksample(self, headrevs, size):
200 def takequicksample(self, headrevs, size):
175 """takes a quick sample of size <size>
201 """takes a quick sample of size <size>
176
202
@@ -206,28 +232,9 b' class partialdiscovery(object):'
206 # update from roots
232 # update from roots
207 revsroots = set(repo.revs('roots(%ld)', revs))
233 revsroots = set(repo.revs('roots(%ld)', revs))
208
234
209 # _updatesample() essentially does interaction over revisions to look
235 childrenrevs = self._childrengetter(revs)
210 # up their children. This lookup is expensive and doing it in a loop is
211 # quadratic. We precompute the children for all relevant revisions and
212 # make the lookup in _updatesample() a simple dict lookup.
213 #
214 # Because this function can be called multiple times during discovery,
215 # we may still perform redundant work and there is room to optimize
216 # this by keeping a persistent cache of children across invocations.
217 children = {}
218
236
219 for rev in sorted(revs):
237 _updatesample(revs, revsroots, sample, childrenrevs)
220 # Always ensure revision has an entry so we don't need to worry
221 # about missing keys.
222 children[rev] = []
223 for prev in parentrevs(rev):
224 if prev == nullrev:
225 continue
226 c = children.get(prev)
227 if c is not None:
228 c.append(rev)
229
230 _updatesample(revs, revsroots, sample, children.__getitem__)
231 assert sample
238 assert sample
232 sample = _limitsample(sample, size)
239 sample = _limitsample(sample, size)
233 if len(sample) < size:
240 if len(sample) < size:
General Comments 0
You need to be logged in to leave comments. Login now