hidden: add a function returning ancestors of revs within a domain
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 21 May 2017 15:21:46 +0200
changeset 37688 1d70ec85ae0071a1a8389e962e56c4a35f14b84d
parent 37687 c2b7fb580794ccbe21fa8c47f493eff6e9431fee
child 37689 e5e31b0fc924479ce20f630400c451185cd680ab
push id525
push usergszorc@mozilla.com
push dateFri, 09 Jun 2017 06:37:32 +0000
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.
mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -87,16 +87,53 @@ def _getstatichidden(repo):
                 # - Avoid adding the same revision twice
                 # - Skip nodes which are public (guaranteed to not be hidden)
                 pre = len(seen)
                 seen.add(parent)
                 if pre < len(seen) and getphase(repo, rev):
                     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'
 
 def cachehash(repo, hideable):
     """return sha1 hash of repository data to identify a valid cache.
 
     We calculate a sha1 of repo heads and the content of the obsstore and write
     it to the cache. Upon reading we can easily validate by checking the hash