Patchwork [6,of,9] dagop: factor out pfunc from revancestors() generator

login
register
mail settings
Submitter Yuya Nishihara
Date June 25, 2017, 3:26 a.m.
Message ID <9b603e7117c1718858eb.1498361175@mimosa>
Download mbox | patch
Permalink /patch/21687/
State Accepted
Headers show

Comments

Yuya Nishihara - June 25, 2017, 3:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1498314165 -32400
#      Sat Jun 24 23:22:45 2017 +0900
# Node ID 9b603e7117c1718858eb2b6df2c410e74403c6cf
# Parent  49f3b0640a146b5a6366d13c0f02d751d22ef8c0
dagop: factor out pfunc from revancestors() generator

This generator will be reused for tracking descendants with depth limit.

  # ancestors(tip) using hg repo
  0) 0.065868
  1) 0.068976

Patch

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -38,6 +38,11 @@  def _genrevancestors(repo, revs, followf
         raise error.ProgrammingError('negative stopdepth')
 
     cl = repo.changelog
+    def pfunc(rev):
+        try:
+            return cl.parentrevs(rev)[:cut]
+        except error.WdirUnsupported:
+            return (pctx.rev() for pctx in repo[rev].parents()[:cut])
 
     # load input revs lazily to heap so earlier revisions can be yielded
     # without fully computing the input revs
@@ -65,14 +70,9 @@  def _genrevancestors(repo, revs, followf
             yield currev
         pdepth = curdepth + 1
         if foundnew and pdepth < stopdepth:
-            try:
-                for prev in cl.parentrevs(currev)[:cut]:
-                    if prev != node.nullrev:
-                        heapq.heappush(pendingheap, (-prev, pdepth))
-            except error.WdirUnsupported:
-                for pctx in repo[currev].parents()[:cut]:
-                    if pctx.rev() != node.nullrev:
-                        heapq.heappush(pendingheap, (-pctx.rev(), pdepth))
+            for prev in pfunc(currev):
+                if prev != node.nullrev:
+                    heapq.heappush(pendingheap, (-prev, pdepth))
 
 def revancestors(repo, revs, followfirst, startdepth=None, stopdepth=None):
     """Like revlog.ancestors(), but supports additional options, includes