Normal
  C   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ[uçnP¸VDHÓ@þÂ„šŸÁ_ŠI|¥�+Wé3ž¯ÁÀ ?÷     # discovery.py - protocol changeset discovery functions
#
# Copyright 2010 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


import functools

from .i18n import _
from .node import (
    hex,
    short,
)

from . import (
    bookmarks,
    branchmap,
    error,
    obsolete,
    phases,
    pycompat,
    scmutil,
    setdiscovery,
    treediscovery,
    util,
)


def findcommonincoming(repo, remote, heads=None, force=False, ancestorsof=None):
    """Return a tuple (common, anyincoming, heads) used to identify the common
    subset of nodes between repo and remote.

    "common" is a list of (at least) the heads of the common subset.
    "anyincoming" is testable as a boolean indicating if any nodes are missing
      locally. If remote does not support getbundle, this actually is a list of
      roots of the nodes that would be incoming, to be supplied to
      changegroupsubset. No code except for pull should be relying on this fact
      any longer.
    "heads" is either the supplied heads, or else the remote's heads.
    "ancestorsof" if not None, restrict the discovery to a subset defined by
      these nodes. Changeset outside of this set won't be considered (but may
      still appear in "common").

    If you pass heads and they are all known locally, the response lists just
    these heads in "common" and in "heads".

    Please use findcommonoutgoing to compute the set of outgoing nodes to give
    extensions a good hook into outgoing.
    """

    if not remote.capable(b'getbundle'):
        return treediscovery.findcommonincoming(repo, remote, heads, force)

    if heads:
        knownnode = repo.changelog.hasnode  # no nodemap until it is filtered
        if all(knownnode(h) for h in heads):
            return (heads, False, heads)

    res = setdiscovery.findcommonheads(
        repo.ui,
        repo,
        remote,
        abortwhenunrelated=not force,
        ancestorsof=ancestorsof,
    )
    common, anyinc, srvheads = res
    if heads and not anyinc:
        # server could be lying on the advertised heads
        has_node = repo.changelog.hasnode
        anyinc = any(not has_node(n) for n in heads)
    return (list(common), anyinc, heads or list(srvheads))


class outgoing:
    """Represents the result of a findcommonoutgoing() call.

    Members:

      ancestorsof is a list of the nodes whose ancestors are included in the
      outgoing operation.

      missing is a list of those ancestors of ancestorsof that are present in
      local but not in remote.

      common is a set containing revs common between the local and the remote
      repository (at least all of those that are ancestors of ancestorsof).

      commonheads is the list of heads of common.

      excluded is the list of missing changeset that shouldn't be sent
      remotely.

    Some members are computed on demand from the heads, unless provided upfront
    by discovery."""

    def __init__(
        self, repo, commonheads=None, ancestorsof=None, missingroots=None
    ):
        # at least one of them must not be set
        assert None in (commonheads, missingroots)
        cl = repo.changelog
        if ancestorsof is None:
            ancestorsof = cl.heads()
        if missingroots:
            discbases = []
            for n in missingroots:
                discbases.extend([p for p in cl.parents(n) if p != repo.nullid])
            # TODO remove call to nodesbetween.
            # TODO populate attributes on outgoing instance instead of setting
            # discbases.
            csets, roots, heads = cl.nodesbetween(missingroots, ancestorsof)
            included = set(csets)
            ancestorsof = heads
            commonheads = [n for n in discbases if n not in included]
        elif not commonheads:
            commonheads = [repo.nullid]
        self.commonheads = commonheads
        self.ancestorsof =