Mercurial > hg
changeset 32997:b9e2269aeff8
dagop: unnest inner generator of revancestors()
This just moves iterate() to module-level function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Jun 2017 22:33:23 +0900 |
parents | 1c97df5e3b46 |
children | c7da57bbae96 |
files | mercurial/dagop.py |
diffstat | 1 files changed, 29 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dagop.py Wed Jun 21 17:17:17 2017 +0200 +++ b/mercurial/dagop.py Sat Jun 17 22:33:23 2017 +0900 @@ -20,43 +20,43 @@ baseset = smartset.baseset generatorset = smartset.generatorset -def revancestors(repo, revs, followfirst): - """Like revlog.ancestors(), but supports followfirst.""" +def _genrevancestors(repo, revs, followfirst): if followfirst: cut = 1 else: cut = None cl = repo.changelog + revs.sort(reverse=True) + irevs = iter(revs) + h = [] - def iterate(): - revs.sort(reverse=True) - irevs = iter(revs) - h = [] - - inputrev = next(irevs, None) - if inputrev is not None: - heapq.heappush(h, -inputrev) + inputrev = next(irevs, None) + if inputrev is not None: + heapq.heappush(h, -inputrev) - seen = set() - while h: - current = -heapq.heappop(h) - if current == inputrev: - inputrev = next(irevs, None) - if inputrev is not None: - heapq.heappush(h, -inputrev) - if current not in seen: - seen.add(current) - yield current - try: - for parent in cl.parentrevs(current)[:cut]: - if parent != node.nullrev: - heapq.heappush(h, -parent) - except error.WdirUnsupported: - for parent in repo[current].parents()[:cut]: - if parent.rev() != node.nullrev: - heapq.heappush(h, -parent.rev()) + seen = set() + while h: + current = -heapq.heappop(h) + if current == inputrev: + inputrev = next(irevs, None) + if inputrev is not None: + heapq.heappush(h, -inputrev) + if current not in seen: + seen.add(current) + yield current + try: + for parent in cl.parentrevs(current)[:cut]: + if parent != node.nullrev: + heapq.heappush(h, -parent) + except error.WdirUnsupported: + for parent in repo[current].parents()[:cut]: + if parent.rev() != node.nullrev: + heapq.heappush(h, -parent.rev()) - return generatorset(iterate(), iterasc=False) +def revancestors(repo, revs, followfirst): + """Like revlog.ancestors(), but supports followfirst.""" + gen = _genrevancestors(repo, revs, followfirst) + return generatorset(gen, iterasc=False) def revdescendants(repo, revs, followfirst): """Like revlog.descendants() but supports followfirst."""