hgext/narrow/narrowwirepeer.py
changeset 36079 a2a6e724d61a
child 36101 22ed16caa596
equal deleted inserted replaced
36078:7f68235f23ff 36079:a2a6e724d61a
       
     1 # narrowwirepeer.py - passes narrow spec with unbundle command
       
     2 #
       
     3 # Copyright 2017 Google, Inc.
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 from __future__ import absolute_import
       
     9 
       
    10 from mercurial.i18n import _
       
    11 from mercurial import (
       
    12     error,
       
    13     extensions,
       
    14     hg,
       
    15     node,
       
    16 )
       
    17 
       
    18 from . import narrowspec
       
    19 
       
    20 def uisetup():
       
    21     def peersetup(ui, peer):
       
    22         # We must set up the expansion before reposetup below, since it's used
       
    23         # at clone time before we have a repo.
       
    24         class expandingpeer(peer.__class__):
       
    25             def expandnarrow(self, narrow_include, narrow_exclude, nodes):
       
    26                 ui.status(_("expanding narrowspec\n"))
       
    27                 if not self.capable('expandnarrow'):
       
    28                     raise error.Abort(
       
    29                         'peer does not support expanding narrowspecs')
       
    30 
       
    31                 hex_nodes = (node.hex(n) for n in nodes)
       
    32                 new_narrowspec = self._call(
       
    33                     'expandnarrow',
       
    34                     includepats=','.join(narrow_include),
       
    35                     excludepats=','.join(narrow_exclude),
       
    36                     nodes=','.join(hex_nodes))
       
    37 
       
    38                 return narrowspec.parseserverpatterns(new_narrowspec)
       
    39         peer.__class__ = expandingpeer
       
    40     hg.wirepeersetupfuncs.append(peersetup)
       
    41 
       
    42 def reposetup(repo):
       
    43     def wirereposetup(ui, peer):
       
    44         def wrapped(orig, cmd, *args, **kwargs):
       
    45             if cmd == 'unbundle':
       
    46                 include, exclude = repo.narrowpats
       
    47                 kwargs["includepats"] = ','.join(include)
       
    48                 kwargs["excludepats"] = ','.join(exclude)
       
    49             return orig(cmd, *args, **kwargs)
       
    50         extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
       
    51     hg.wirepeersetupfuncs.append(wirereposetup)