changeset 32475:1d70ec85ae00

hidden: add a function returning ancestors of revs within a domain See documentation for details. This will be used to improve the hidden computation algorithm. See new changesets for usage.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 21 May 2017 15:21:46 +0200
parents c2b7fb580794
children e5e31b0fc924
files mercurial/repoview.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/repoview.py	Fri May 26 14:52:54 2017 -0700
+++ b/mercurial/repoview.py	Sun May 21 15:21:46 2017 +0200
@@ -92,6 +92,43 @@
                     heappush(heap, -parent)
     return hidden
 
+def _domainancestors(pfunc, revs, domain):
+    """return ancestors of 'revs' within 'domain'
+
+    - pfunc(r): a funtion returning parent of 'r',
+    - revs: iterable of revnum,
+    - domain: consistent set of revnum.
+
+    The domain must be consistent: no connected subset are the ancestors of
+    another connected subset. In other words, if the parents of a revision are
+    not in the domains, no other ancestors of that revision. For example, with
+    the following graph:
+
+        F
+        |
+        E
+        | D
+        | |
+        | C
+        |/
+        B
+        |
+        A
+
+    If C, D, E and F are in the domain but B is not, A cannot be ((A) is an
+    ancestors disconnected subset disconnected of (C+D)).
+
+    (Ancestors are returned inclusively)
+    """
+    stack = list(revs)
+    ancestors = set(stack)
+    while stack:
+        for p in pfunc(stack.pop()):
+            if p != nullrev and p in domain and p not in ancestors:
+                ancestors.add(p)
+                stack.append(p)
+    return ancestors
+
 cacheversion = 1
 cachefile = 'cache/hidden'