Esempio n. 1
0
def exchangepull(orig,
                 repo,
                 remote,
                 heads=None,
                 force=False,
                 bookmarks=(),
                 **kwargs):
    if isinstance(remote, gitrepo):
        pullop = exchange.pulloperation(repo,
                                        remote,
                                        heads,
                                        force,
                                        bookmarks=bookmarks)
        pullop.trmanager = exchange.transactionmanager(repo, b'pull',
                                                       remote.url())

        with repo.wlock(), repo.lock(), pullop.trmanager:
            pullop.cgresult = repo.githandler.fetch(remote, heads)
            return pullop
    else:
        return orig(
            repo,
            remote,
            heads=heads,
            force=force,
            bookmarks=bookmarks,
            **kwargs,
        )
Esempio n. 2
0
def _widen(
    ui,
    repo,
    remote,
    commoninc,
    oldincludes,
    oldexcludes,
    newincludes,
    newexcludes,
):
    # for now we assume that if a server has ellipses enabled, we will be
    # exchanging ellipses nodes. In future we should add ellipses as a client
    # side requirement (maybe) to distinguish a client is shallow or not and
    # then send that information to server whether we want ellipses or not.
    # Theoretically a non-ellipses repo should be able to use narrow
    # functionality from an ellipses enabled server
    remotecap = remote.capabilities()
    ellipsesremote = any(cap in remotecap
                         for cap in wireprototypes.SUPPORTED_ELLIPSESCAP)

    # check whether we are talking to a server which supports old version of
    # ellipses capabilities
    isoldellipses = (ellipsesremote
                     and wireprototypes.ELLIPSESCAP1 in remotecap
                     and wireprototypes.ELLIPSESCAP not in remotecap)

    def pullbundle2extraprepare_widen(orig, pullop, kwargs):
        orig(pullop, kwargs)
        # The old{in,ex}cludepats have already been set by orig()
        kwargs[b'includepats'] = newincludes
        kwargs[b'excludepats'] = newexcludes

    wrappedextraprepare = extensions.wrappedfunction(
        exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare_widen)

    # define a function that narrowbundle2 can call after creating the
    # backup bundle, but before applying the bundle from the server
    def setnewnarrowpats():
        repo.setnarrowpats(newincludes, newexcludes)

    repo.setnewnarrowpats = setnewnarrowpats
    # silence the devel-warning of applying an empty changegroup
    overrides = {(b'devel', b'all-warnings'): False}

    common = commoninc[0]
    with ui.uninterruptible():
        if ellipsesremote:
            ds = repo.dirstate
            p1, p2 = ds.p1(), ds.p2()
            with ds.parentchange():
                ds.setparents(node.nullid, node.nullid)
        if isoldellipses:
            with wrappedextraprepare:
                exchange.pull(repo, remote, heads=common)
        else:
            known = []
            if ellipsesremote:
                known = [
                    ctx.node() for ctx in repo.set(b'::%ln', common)
                    if ctx.node() != node.nullid
                ]
            with remote.commandexecutor() as e:
                bundle = e.callcommand(
                    b'narrow_widen',
                    {
                        b'oldincludes': oldincludes,
                        b'oldexcludes': oldexcludes,
                        b'newincludes': newincludes,
                        b'newexcludes': newexcludes,
                        b'cgversion': b'03',
                        b'commonheads': common,
                        b'known': known,
                        b'ellipses': ellipsesremote,
                    },
                ).result()

            trmanager = exchange.transactionmanager(repo, b'widen',
                                                    remote.url())
            with trmanager, repo.ui.configoverride(overrides, b'widen'):
                op = bundle2.bundleoperation(repo,
                                             trmanager.transaction,
                                             source=b'widen')
                # TODO: we should catch error.Abort here
                bundle2.processbundle(repo, bundle, op=op)

        if ellipsesremote:
            with ds.parentchange():
                ds.setparents(p1, p2)

        with repo.transaction(b'widening'):
            repo.setnewnarrowpats()
            narrowspec.updateworkingcopy(repo)
            narrowspec.copytoworkingcopy(repo)