hgext/narrow/narrowwirepeer.py
changeset 43076 2372284d9457
parent 42944 c2676b5a9f59
child 43077 687b865b95ad
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    19     wireprotov1server,
    19     wireprotov1server,
    20 )
    20 )
    21 
    21 
    22 from . import narrowbundle2
    22 from . import narrowbundle2
    23 
    23 
       
    24 
    24 def uisetup():
    25 def uisetup():
    25     wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
    26     wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
       
    27 
    26 
    28 
    27 def reposetup(repo):
    29 def reposetup(repo):
    28     def wirereposetup(ui, peer):
    30     def wirereposetup(ui, peer):
    29         def wrapped(orig, cmd, *args, **kwargs):
    31         def wrapped(orig, cmd, *args, **kwargs):
    30             if cmd == 'unbundle':
    32             if cmd == 'unbundle':
    32                 # arguments to unbundle.
    34                 # arguments to unbundle.
    33                 include, exclude = repo.narrowpats
    35                 include, exclude = repo.narrowpats
    34                 kwargs[r"includepats"] = ','.join(include)
    36                 kwargs[r"includepats"] = ','.join(include)
    35                 kwargs[r"excludepats"] = ','.join(exclude)
    37                 kwargs[r"excludepats"] = ','.join(exclude)
    36             return orig(cmd, *args, **kwargs)
    38             return orig(cmd, *args, **kwargs)
       
    39 
    37         extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
    40         extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
       
    41 
    38     hg.wirepeersetupfuncs.append(wirereposetup)
    42     hg.wirepeersetupfuncs.append(wirereposetup)
    39 
    43 
    40 @wireprotov1server.wireprotocommand('narrow_widen', 'oldincludes oldexcludes'
    44 
    41                                                     ' newincludes newexcludes'
    45 @wireprotov1server.wireprotocommand(
    42                                                     ' commonheads cgversion'
    46     'narrow_widen',
    43                                                     ' known ellipses',
    47     'oldincludes oldexcludes'
    44                                     permission='pull')
    48     ' newincludes newexcludes'
    45 def narrow_widen(repo, proto, oldincludes, oldexcludes, newincludes,
    49     ' commonheads cgversion'
    46                  newexcludes, commonheads, cgversion, known, ellipses):
    50     ' known ellipses',
       
    51     permission='pull',
       
    52 )
       
    53 def narrow_widen(
       
    54     repo,
       
    55     proto,
       
    56     oldincludes,
       
    57     oldexcludes,
       
    58     newincludes,
       
    59     newexcludes,
       
    60     commonheads,
       
    61     cgversion,
       
    62     known,
       
    63     ellipses,
       
    64 ):
    47     """wireprotocol command to send data when a narrow clone is widen. We will
    65     """wireprotocol command to send data when a narrow clone is widen. We will
    48     be sending a changegroup here.
    66     be sending a changegroup here.
    49 
    67 
    50     The current set of arguments which are required:
    68     The current set of arguments which are required:
    51     oldincludes: the old includes of the narrow copy
    69     oldincludes: the old includes of the narrow copy
    58     ellipses: whether to send ellipses data or not
    76     ellipses: whether to send ellipses data or not
    59     """
    77     """
    60 
    78 
    61     preferuncompressed = False
    79     preferuncompressed = False
    62     try:
    80     try:
       
    81 
    63         def splitpaths(data):
    82         def splitpaths(data):
    64             # work around ''.split(',') => ['']
    83             # work around ''.split(',') => ['']
    65             return data.split(b',') if data else []
    84             return data.split(b',') if data else []
       
    85 
    66         oldincludes = splitpaths(oldincludes)
    86         oldincludes = splitpaths(oldincludes)
    67         newincludes = splitpaths(newincludes)
    87         newincludes = splitpaths(newincludes)
    68         oldexcludes = splitpaths(oldexcludes)
    88         oldexcludes = splitpaths(oldexcludes)
    69         newexcludes = splitpaths(newexcludes)
    89         newexcludes = splitpaths(newexcludes)
    70         # validate the patterns
    90         # validate the patterns
    81             ellipses = bool(ellipses)
   101             ellipses = bool(ellipses)
    82         cgversion = cgversion
   102         cgversion = cgversion
    83 
   103 
    84         bundler = bundle2.bundle20(repo.ui)
   104         bundler = bundle2.bundle20(repo.ui)
    85         if not ellipses:
   105         if not ellipses:
    86             newmatch = narrowspec.match(repo.root, include=newincludes,
   106             newmatch = narrowspec.match(
    87                                         exclude=newexcludes)
   107                 repo.root, include=newincludes, exclude=newexcludes
    88             oldmatch = narrowspec.match(repo.root, include=oldincludes,
   108             )
    89                                         exclude=oldexcludes)
   109             oldmatch = narrowspec.match(
    90             bundle2.widen_bundle(bundler, repo, oldmatch, newmatch, common,
   110                 repo.root, include=oldincludes, exclude=oldexcludes
    91                                  known, cgversion, ellipses)
   111             )
       
   112             bundle2.widen_bundle(
       
   113                 bundler,
       
   114                 repo,
       
   115                 oldmatch,
       
   116                 newmatch,
       
   117                 common,
       
   118                 known,
       
   119                 cgversion,
       
   120                 ellipses,
       
   121             )
    92         else:
   122         else:
    93             narrowbundle2.generateellipsesbundle2(bundler, repo, oldincludes,
   123             narrowbundle2.generateellipsesbundle2(
    94                     oldexcludes, newincludes, newexcludes, cgversion, common,
   124                 bundler,
    95                     list(common), known, None)
   125                 repo,
       
   126                 oldincludes,
       
   127                 oldexcludes,
       
   128                 newincludes,
       
   129                 newexcludes,
       
   130                 cgversion,
       
   131                 common,
       
   132                 list(common),
       
   133                 known,
       
   134                 None,
       
   135             )
    96     except error.Abort as exc:
   136     except error.Abort as exc:
    97         bundler = bundle2.bundle20(repo.ui)
   137         bundler = bundle2.bundle20(repo.ui)
    98         manargs = [('message', pycompat.bytestr(exc))]
   138         manargs = [('message', pycompat.bytestr(exc))]
    99         advargs = []
   139         advargs = []
   100         if exc.hint is not None:
   140         if exc.hint is not None:
   101             advargs.append(('hint', exc.hint))
   141             advargs.append(('hint', exc.hint))
   102         bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs))
   142         bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs))
   103         preferuncompressed = True
   143         preferuncompressed = True
   104 
   144 
   105     chunks = bundler.getchunks()
   145     chunks = bundler.getchunks()
   106     return wireprototypes.streamres(gen=chunks,
   146     return wireprototypes.streamres(
   107                                     prefer_uncompressed=preferuncompressed)
   147         gen=chunks, prefer_uncompressed=preferuncompressed
       
   148     )
       
   149 
   108 
   150 
   109 def peernarrowwiden(remote, **kwargs):
   151 def peernarrowwiden(remote, **kwargs):
   110     for ch in (r'commonheads', r'known'):
   152     for ch in (r'commonheads', r'known'):
   111         kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
   153         kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
   112 
   154