changeset 29690:5684bc429e6a

discovery: move code to create outgoing from roots and heads changegroup.changegroupsubset() contained somewhat low-level code for constructing an "outgoing" instance from a list of roots and heads nodes. It feels like discovery.py is a more appropriate location for this code. This code can definitely be optimized, as outgoing.missing will recompute the set of changesets we've already discovered from cl.between(). But code shouldn't be refactored during a move, so I've simply inserted a TODO calling attention to that.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 03 Aug 2016 22:07:52 -0700
parents 39537bc64442
children e9a0bcc9314d
files mercurial/changegroup.py mercurial/discovery.py
diffstat 2 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Wed Aug 03 16:23:26 2016 +0200
+++ b/mercurial/changegroup.py	Wed Aug 03 22:07:52 2016 -0700
@@ -946,17 +946,7 @@
     Another wrinkle is doing the reverse, figuring out which changeset in
     the changegroup a particular filenode or manifestnode belongs to.
     """
-    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.
-    csets, roots, heads = cl.nodesbetween(roots, heads)
-    included = set(csets)
-    discbases = [n for n in discbases if n not in included]
-    outgoing = discovery.outgoing(cl, discbases, heads)
+    outgoing = discovery.outgoingbetween(repo, roots, heads)
     bundler = getbundler(version, repo)
     return getsubset(repo, outgoing, bundler, source)
 
--- a/mercurial/discovery.py	Wed Aug 03 16:23:26 2016 +0200
+++ b/mercurial/discovery.py	Wed Aug 03 22:07:52 2016 -0700
@@ -101,6 +101,27 @@
             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(cl, 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