view hgext/narrow/narrowwirepeer.py @ 36101:22ed16caa596

narrowwirepeer: rename expandnarrow capability to exp-expandnarrow The expandnarrow functionality lets a client have a shorthand (for Google it's a reference to a checked-in file) for a set of includes and excludes. For testing we should probably implement a simple version of that functionality here. For now, rename the capability so we don't burn the good name in the future if we need to change behavior. It's plausible that this functionality should be dropped from the narrowhg we ship long-term, but I'm dubious as it seems pretty likely other organizations will want similar shorthands for commonly-used subsets of their trees. Differential Revision: https://phab.mercurial-scm.org/D2193
author Augie Fackler <augie@google.com>
date Mon, 12 Feb 2018 14:49:38 -0500
parents a2a6e724d61a
children b60c577b6e03
line wrap: on
line source

# narrowwirepeer.py - passes narrow spec with unbundle command
#
# Copyright 2017 Google, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

from __future__ import absolute_import

from mercurial.i18n import _
from mercurial import (
    error,
    extensions,
    hg,
    node,
)

from . import narrowspec

def uisetup():
    def peersetup(ui, peer):
        # We must set up the expansion before reposetup below, since it's used
        # at clone time before we have a repo.
        class expandingpeer(peer.__class__):
            def expandnarrow(self, narrow_include, narrow_exclude, nodes):
                ui.status(_("expanding narrowspec\n"))
                if not self.capable('exp-expandnarrow'):
                    raise error.Abort(
                        'peer does not support expanding narrowspecs')

                hex_nodes = (node.hex(n) for n in nodes)
                new_narrowspec = self._call(
                    'expandnarrow',
                    includepats=','.join(narrow_include),
                    excludepats=','.join(narrow_exclude),
                    nodes=','.join(hex_nodes))

                return narrowspec.parseserverpatterns(new_narrowspec)
        peer.__class__ = expandingpeer
    hg.wirepeersetupfuncs.append(peersetup)

def reposetup(repo):
    def wirereposetup(ui, peer):
        def wrapped(orig, cmd, *args, **kwargs):
            if cmd == 'unbundle':
                include, exclude = repo.narrowpats
                kwargs["includepats"] = ','.join(include)
                kwargs["excludepats"] = ','.join(exclude)
            return orig(cmd, *args, **kwargs)
        extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
    hg.wirepeersetupfuncs.append(wirereposetup)