hgext/clonebundles.py
changeset 26691 23c0da28c034
parent 26645 2faa7671a4b3
child 26762 26f622859288
equal deleted inserted replaced
26690:704818fb170d 26691:23c0da28c034
    62    with the clonebundles facility.
    62    with the clonebundles facility.
    63 
    63 
    64    Value should be "true".
    64    Value should be "true".
    65 """
    65 """
    66 
    66 
       
    67 from mercurial.i18n import _
       
    68 from mercurial.node import nullid
    67 from mercurial import (
    69 from mercurial import (
       
    70     exchange,
    68     extensions,
    71     extensions,
    69     wireproto,
    72     wireproto,
    70 )
    73 )
    71 
    74 
    72 testedwith = 'internal'
    75 testedwith = 'internal'
    92     data depending on the request. e.g. you could advertise URLs for
    95     data depending on the request. e.g. you could advertise URLs for
    93     the closest data center given the client's IP address.
    96     the closest data center given the client's IP address.
    94     """
    97     """
    95     return repo.opener.tryread('clonebundles.manifest')
    98     return repo.opener.tryread('clonebundles.manifest')
    96 
    99 
       
   100 @exchange.getbundle2partsgenerator('clonebundlesadvertise', 0)
       
   101 def advertiseclonebundlespart(bundler, repo, source, bundlecaps=None,
       
   102                               b2caps=None, heads=None, common=None,
       
   103                               cbattempted=None, **kwargs):
       
   104     """Inserts an output part to advertise clone bundles availability."""
       
   105     # Allow server operators to disable this behavior.
       
   106     # # experimental config: ui.clonebundleadvertise
       
   107     if not repo.ui.configbool('ui', 'clonebundleadvertise', True):
       
   108         return
       
   109 
       
   110     # Only advertise if a manifest is present.
       
   111     if not repo.opener.exists('clonebundles.manifest'):
       
   112         return
       
   113 
       
   114     # And when changegroup data is requested.
       
   115     if not kwargs.get('cg', True):
       
   116         return
       
   117 
       
   118     # And when the client supports clone bundles.
       
   119     if cbattempted is None:
       
   120         return
       
   121 
       
   122     # And when the client didn't attempt a clone bundle as part of this pull.
       
   123     if cbattempted:
       
   124         return
       
   125 
       
   126     # And when a full clone is requested.
       
   127     # Note: client should not send "cbattempted" for regular pulls. This check
       
   128     # is defense in depth.
       
   129     if common and common != [nullid]:
       
   130         return
       
   131 
       
   132     msg = _('this server supports the experimental "clone bundles" feature '
       
   133             'that should enable faster and more reliable cloning\n'
       
   134             'help test it by setting the "experimental.clonebundles" config '
       
   135             'flag to "true"')
       
   136 
       
   137     bundler.newpart('output', data=msg)
       
   138 
    97 def extsetup(ui):
   139 def extsetup(ui):
    98     extensions.wrapfunction(wireproto, '_capabilities', capabilities)
   140     extensions.wrapfunction(wireproto, '_capabilities', capabilities)