comparison mercurial/ancestor.py @ 39537:ca9983c35d89

ancestor: rename local aliases of heapq functions in _lazyancestorsiter() The original names no longer look pretty. Just call them as heap*() instead.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 11 Sep 2018 22:36:51 +0900
parents bdb177923291
children 238a1480d7ad
comparison
equal deleted inserted replaced
39536:bdb177923291 39537:ca9983c35d89
260 return missing 260 return missing
261 261
262 # Extracted from lazyancestors.__iter__ to avoid a reference cycle 262 # Extracted from lazyancestors.__iter__ to avoid a reference cycle
263 def _lazyancestorsiter(parentrevs, initrevs, stoprev, inclusive): 263 def _lazyancestorsiter(parentrevs, initrevs, stoprev, inclusive):
264 seen = {nullrev} 264 seen = {nullrev}
265 schedule = heapq.heappush 265 heappush = heapq.heappush
266 nextitem = heapq.heappop 266 heappop = heapq.heappop
267 see = seen.add 267 see = seen.add
268 268
269 if inclusive: 269 if inclusive:
270 visit = [-r for r in initrevs] 270 visit = [-r for r in initrevs]
271 seen.update(initrevs) 271 seen.update(initrevs)
274 visit = [] 274 visit = []
275 heapq.heapify(visit) 275 heapq.heapify(visit)
276 for r in initrevs: 276 for r in initrevs:
277 p1, p2 = parentrevs(r) 277 p1, p2 = parentrevs(r)
278 if p1 not in seen: 278 if p1 not in seen:
279 schedule(visit, -p1) 279 heappush(visit, -p1)
280 see(p1) 280 see(p1)
281 if p2 not in seen: 281 if p2 not in seen:
282 schedule(visit, -p2) 282 heappush(visit, -p2)
283 see(p2) 283 see(p2)
284 284
285 while visit: 285 while visit:
286 current = -visit[0] 286 current = -visit[0]
287 if current < stoprev: 287 if current < stoprev:
292 p1, p2 = parentrevs(current) 292 p1, p2 = parentrevs(current)
293 if p1 not in seen: 293 if p1 not in seen:
294 if current - p1 == 1: 294 if current - p1 == 1:
295 visit[0] = -p1 295 visit[0] = -p1
296 else: 296 else:
297 nextitem(visit) 297 heappop(visit)
298 schedule(visit, -p1) 298 heappush(visit, -p1)
299 see(p1) 299 see(p1)
300 else: 300 else:
301 nextitem(visit) 301 heappop(visit)
302 if p2 not in seen: 302 if p2 not in seen:
303 schedule(visit, -p2) 303 heappush(visit, -p2)
304 see(p2) 304 see(p2)
305 305
306 class lazyancestors(object): 306 class lazyancestors(object):
307 def __init__(self, pfunc, revs, stoprev=0, inclusive=False): 307 def __init__(self, pfunc, revs, stoprev=0, inclusive=False):
308 """Create a new object generating ancestors for the given revs. Does 308 """Create a new object generating ancestors for the given revs. Does