Patchwork [6,of,8] dagop: change visit dict of filectxancestors() indexed solely by rev

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 6, 2017, 3:05 p.m.
Message ID <e1a0780894ccd68c5a6c.1512572750@mimosa>
Download mbox | patch
Permalink /patch/25975/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 6, 2017, 3:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1474535497 -32400
#      Thu Sep 22 18:11:37 2016 +0900
# Node ID e1a0780894ccd68c5a6c09e7d61401bd0d37c73f
# Parent  1977b7f3214c612d62e099f6984fae086adcc69c
dagop: change visit dict of filectxancestors() indexed solely by rev

In future patches, a max heap will be used to compute the next revision
to visit.

Patch

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -78,6 +78,12 @@  def _walkrevtree(pfunc, revs, startdepth
 def filectxancestors(fctx, followfirst=False):
     """Like filectx.ancestors(), but includes the given fctx itself"""
     visit = {}
+    def addvisit(fctx):
+        rev = fctx.rev()
+        if rev not in visit:
+            visit[rev] = set()
+        visit[rev].add(fctx)
+
     c = fctx
     if followfirst:
         cut = 1
@@ -87,10 +93,13 @@  def filectxancestors(fctx, followfirst=F
     yield c
     while True:
         for parent in c.parents()[:cut]:
-            visit[(parent.rev(), parent.filenode())] = parent
+            addvisit(parent)
         if not visit:
             break
-        c = visit.pop(max(visit))
+        rev = max(visit)
+        c = visit[rev].pop()
+        if not visit[rev]:
+            del visit[rev]
         yield c
 
 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth, cutfunc):