changeset 29817:82e8c86cdd6d

outgoing: add a 'missingroots' argument This argument can be used instead of 'commonheads' to determine the 'outgoing' set. We remove the outgoingbetween function as its role can now be handled by 'outgoing' itself. I've thought of using an external function instead of making the constructor more complicated. However, there is low hanging fruit to improve the current code flow by storing some side products of the processing of 'missingroots'. So in my opinion it make senses to add all this to the class.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 09 Aug 2016 22:31:38 +0200
parents f09d0004481c
children d4e026341e16
files mercurial/changegroup.py mercurial/discovery.py
diffstat 2 files changed, 17 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Tue Aug 09 15:55:44 2016 +0200
+++ b/mercurial/changegroup.py	Tue Aug 09 22:31:38 2016 +0200
@@ -942,7 +942,7 @@
     Another wrinkle is doing the reverse, figuring out which changeset in
     the changegroup a particular filenode or manifestnode belongs to.
     """
-    outgoing = discovery.outgoingbetween(repo, roots, heads)
+    outgoing = discovery.outgoing(repo, missingroots=roots, missingheads=heads)
     bundler = getbundler(version, repo)
     return getsubset(repo, outgoing, bundler, source)
 
--- a/mercurial/discovery.py	Tue Aug 09 15:55:44 2016 +0200
+++ b/mercurial/discovery.py	Tue Aug 09 22:31:38 2016 +0200
@@ -76,11 +76,25 @@
     The sets are computed on demand from the heads, unless provided upfront
     by discovery.'''
 
-    def __init__(self, repo, commonheads=None, missingheads=None):
+    def __init__(self, repo, commonheads=None, missingheads=None,
+                 missingroots=None):
+        # at least one of them must not be set
+        assert None in (commonheads, missingroots)
         cl = repo.changelog
         if not missingheads:
             missingheads = cl.heads()
-        if not commonheads:
+        if missingroots:
+            discbases = []
+            for n in missingroots:
+                discbases.extend([p for p in cl.parents(n) if p != nullid])
+            # TODO remove call to nodesbetween.
+            # TODO populate attributes on outgoing instance instead of setting
+            # discbases.
+            csets, roots, heads = cl.nodesbetween(missingroots, missingheads)
+            included = set(csets)
+            missingheads = heads
+            commonheads = [n for n in discbases if n not in included]
+        elif not commonheads:
             commonheads = [nullid]
         self.commonheads = commonheads
         self.missingheads = missingheads
@@ -106,27 +120,6 @@
             self._computecommonmissing()
         return self._missing
 
-def outgoingbetween(repo, roots, heads):
-    """create an ``outgoing`` consisting of nodes between roots and heads
-
-    The ``missing`` nodes will be descendants of any of the ``roots`` and
-    ancestors of any of the ``heads``, both are which are defined as a list
-    of binary nodes.
-    """
-    cl = repo.changelog
-    if not roots:
-        roots = [nullid]
-    discbases = []
-    for n in roots:
-        discbases.extend([p for p in cl.parents(n) if p != nullid])
-    # TODO remove call to nodesbetween.
-    # TODO populate attributes on outgoing instance instead of setting
-    # discbases.
-    csets, roots, heads = cl.nodesbetween(roots, heads)
-    included = set(csets)
-    discbases = [n for n in discbases if n not in included]
-    return outgoing(repo, discbases, heads)
-
 def findcommonoutgoing(repo, other, onlyheads=None, force=False,
                        commoninc=None, portable=False):
     '''Return an outgoing instance to identify the nodes present in repo but