comparison hgext/clonebundles.py @ 26691:23c0da28c034

clonebundles: advertise clone bundles feature to clients Server operators that have enabled clone bundles probably want clients to use it. This patch introduces a feature that will insert a bundle2 "output" part that advertises the existence of the clone bundles feature to clients that aren't using it. The server uses the "cbattempted" argument to "getbundle" to determine whether a client supports clone bundles and to avoid sending the message to clients that failed the clone bundle for whatever reason.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 14 Oct 2015 11:05:53 -0700
parents 2faa7671a4b3
children 26f622859288
comparison
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)