Mercurial > hg
comparison mercurial/dagop.py @ 39999:0b24fcd88066
dagop: extract descendants() from revlog module
This method needs to be implemented in other storage backends and is
generic if we parameterize the functions for retrieving revision
numbers and parent revision numbers.
Let's extract it to dagop so backends don't need to reinvent the
wheel.
I'm not too worried about performance overhead of the extra function
call because I don't expect anyone to be calling descendants() in a
tight loop.
Differential Revision: https://phab.mercurial-scm.org/D4794
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 28 Sep 2018 10:03:32 -0700 |
parents | 5362c96f2feb |
children | 8af835af0a85 |
comparison
equal
deleted
inserted
replaced
39998:44c98cbc665f | 39999:0b24fcd88066 |
---|---|
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import heapq | 10 import heapq |
11 | 11 |
12 from .node import ( | |
13 nullrev, | |
14 ) | |
12 from .thirdparty import ( | 15 from .thirdparty import ( |
13 attr, | 16 attr, |
14 ) | 17 ) |
15 from . import ( | 18 from . import ( |
16 error, | 19 error, |
222 gen = _genrevdescendants(repo, revs, followfirst) | 225 gen = _genrevdescendants(repo, revs, followfirst) |
223 else: | 226 else: |
224 gen = _genrevdescendantsofdepth(repo, revs, followfirst, | 227 gen = _genrevdescendantsofdepth(repo, revs, followfirst, |
225 startdepth, stopdepth) | 228 startdepth, stopdepth) |
226 return generatorset(gen, iterasc=True) | 229 return generatorset(gen, iterasc=True) |
230 | |
231 def descendantrevs(revs, revsfn, parentrevsfn): | |
232 """Generate revision number descendants in revision order. | |
233 | |
234 Yields revision numbers starting with a child of some rev in | |
235 ``revs``. Results are ordered by revision number and are | |
236 therefore topological. Each revision is not considered a descendant | |
237 of itself. | |
238 | |
239 ``revsfn`` is a callable that with no argument iterates over all | |
240 revision numbers and with a ``start`` argument iterates over revision | |
241 numbers beginning with that value. | |
242 | |
243 ``parentrevsfn`` is a callable that receives a revision number and | |
244 returns an iterable of parent revision numbers, whose values may include | |
245 nullrev. | |
246 """ | |
247 first = min(revs) | |
248 | |
249 if first == nullrev: | |
250 for rev in revsfn(): | |
251 yield rev | |
252 return | |
253 | |
254 seen = set(revs) | |
255 for rev in revsfn(start=first + 1): | |
256 for prev in parentrevsfn(rev): | |
257 if prev != nullrev and prev in seen: | |
258 seen.add(rev) | |
259 yield rev | |
260 break | |
227 | 261 |
228 def _reachablerootspure(repo, minroot, roots, heads, includepath): | 262 def _reachablerootspure(repo, minroot, roots, heads, includepath): |
229 """return (heads(::<roots> and ::<heads>)) | 263 """return (heads(::<roots> and ::<heads>)) |
230 | 264 |
231 If includepath is True, return (<roots>::<heads>).""" | 265 If includepath is True, return (<roots>::<heads>).""" |