Show More
@@ -32,7 +32,23 b' The server operator is responsible for g' | |||||
32 |
|
32 | |||
33 | Metadata Attributes: |
|
33 | Metadata Attributes: | |
34 |
|
34 | |||
35 | TBD |
|
35 | BUNDLESPEC | |
|
36 | A "bundle specification" string that describes the type of the bundle. | |||
|
37 | ||||
|
38 | These are string values that are accepted by the "--type" argument of | |||
|
39 | `hg bundle`. | |||
|
40 | ||||
|
41 | The values are parsed in strict mode, which means they must be of the | |||
|
42 | "<compression>-<type>" form. See | |||
|
43 | mercurial.exchange.parsebundlespec() for more details. | |||
|
44 | ||||
|
45 | Clients will automatically filter out specifications that are unknown or | |||
|
46 | unsupported so they won't attempt to download something that likely won't | |||
|
47 | apply. | |||
|
48 | ||||
|
49 | The actual value doesn't impact client behavior beyond filtering: | |||
|
50 | clients will still sniff the bundle type from the header of downloaded | |||
|
51 | files. | |||
36 | """ |
|
52 | """ | |
37 |
|
53 | |||
38 | from mercurial import ( |
|
54 | from mercurial import ( |
@@ -1599,15 +1599,26 b' def _maybeapplyclonebundle(pullop):' | |||||
1599 |
|
1599 | |||
1600 | res = remote._call('clonebundles') |
|
1600 | res = remote._call('clonebundles') | |
1601 | entries = parseclonebundlesmanifest(res) |
|
1601 | entries = parseclonebundlesmanifest(res) | |
1602 |
|
||||
1603 | # TODO filter entries by supported features. |
|
|||
1604 | # TODO sort entries by user preferences. |
|
|||
1605 |
|
||||
1606 | if not entries: |
|
1602 | if not entries: | |
1607 | repo.ui.note(_('no clone bundles available on remote; ' |
|
1603 | repo.ui.note(_('no clone bundles available on remote; ' | |
1608 | 'falling back to regular clone\n')) |
|
1604 | 'falling back to regular clone\n')) | |
1609 | return |
|
1605 | return | |
1610 |
|
1606 | |||
|
1607 | entries = filterclonebundleentries(repo, entries) | |||
|
1608 | if not entries: | |||
|
1609 | # There is a thundering herd concern here. However, if a server | |||
|
1610 | # operator doesn't advertise bundles appropriate for its clients, | |||
|
1611 | # they deserve what's coming. Furthermore, from a client's | |||
|
1612 | # perspective, no automatic fallback would mean not being able to | |||
|
1613 | # clone! | |||
|
1614 | repo.ui.warn(_('no compatible clone bundles available on server; ' | |||
|
1615 | 'falling back to regular clone\n')) | |||
|
1616 | repo.ui.warn(_('(you may want to report this to the server ' | |||
|
1617 | 'operator)\n')) | |||
|
1618 | return | |||
|
1619 | ||||
|
1620 | # TODO sort entries by user preferences. | |||
|
1621 | ||||
1611 | url = entries[0]['URL'] |
|
1622 | url = entries[0]['URL'] | |
1612 | repo.ui.status(_('applying clone bundle from %s\n') % url) |
|
1623 | repo.ui.status(_('applying clone bundle from %s\n') % url) | |
1613 | if trypullbundlefromurl(repo.ui, repo, url): |
|
1624 | if trypullbundlefromurl(repo.ui, repo, url): | |
@@ -1644,6 +1655,25 b' def parseclonebundlesmanifest(s):' | |||||
1644 |
|
1655 | |||
1645 | return m |
|
1656 | return m | |
1646 |
|
1657 | |||
|
1658 | def filterclonebundleentries(repo, entries): | |||
|
1659 | newentries = [] | |||
|
1660 | for entry in entries: | |||
|
1661 | spec = entry.get('BUNDLESPEC') | |||
|
1662 | if spec: | |||
|
1663 | try: | |||
|
1664 | parsebundlespec(repo, spec, strict=True) | |||
|
1665 | except error.InvalidBundleSpecification as e: | |||
|
1666 | repo.ui.debug(str(e) + '\n') | |||
|
1667 | continue | |||
|
1668 | except error.UnsupportedBundleSpecification as e: | |||
|
1669 | repo.ui.debug('filtering %s because unsupported bundle ' | |||
|
1670 | 'spec: %s\n' % (entry['URL'], str(e))) | |||
|
1671 | continue | |||
|
1672 | ||||
|
1673 | newentries.append(entry) | |||
|
1674 | ||||
|
1675 | return newentries | |||
|
1676 | ||||
1647 | def trypullbundlefromurl(ui, repo, url): |
|
1677 | def trypullbundlefromurl(ui, repo, url): | |
1648 | """Attempt to apply a bundle from a URL.""" |
|
1678 | """Attempt to apply a bundle from a URL.""" | |
1649 | lock = repo.lock() |
|
1679 | lock = repo.lock() |
@@ -109,9 +109,28 b' We can override failure to fall back to ' | |||||
109 |
|
109 | |||
110 | Bundle with partial content works |
|
110 | Bundle with partial content works | |
111 |
|
111 | |||
112 | $ hg -R server bundle --type gzip --base null -r 53245c60e682 partial.hg |
|
112 | $ hg -R server bundle --type gzip-v1 --base null -r 53245c60e682 partial.hg | |
113 | 1 changesets found |
|
113 | 1 changesets found | |
114 |
|
114 | |||
|
115 | We verify exact bundle content as an extra check against accidental future | |||
|
116 | changes. If this output changes, we could break old clients. | |||
|
117 | ||||
|
118 | $ f --size --hexdump partial.hg | |||
|
119 | partial.hg: size=208 | |||
|
120 | 0000: 48 47 31 30 47 5a 78 9c 63 60 60 98 17 ac 12 93 |HG10GZx.c``.....| | |||
|
121 | 0010: f0 ac a9 23 45 70 cb bf 0d 5f 59 4e 4a 7f 79 21 |...#Ep..._YNJ.y!| | |||
|
122 | 0020: 9b cc 40 24 20 a0 d7 ce 2c d1 38 25 cd 24 25 d5 |..@$ ...,.8%.$%.| | |||
|
123 | 0030: d8 c2 22 cd 38 d9 24 cd 22 d5 c8 22 cd 24 cd 32 |..".8.$."..".$.2| | |||
|
124 | 0040: d1 c2 d0 c4 c8 d2 32 d1 38 39 29 c9 34 cd d4 80 |......2.89).4...| | |||
|
125 | 0050: ab 24 b5 b8 84 cb 40 c1 80 2b 2d 3f 9f 8b 2b 31 |.$....@..+-?..+1| | |||
|
126 | 0060: 25 45 01 c8 80 9a d2 9b 65 fb e5 9e 45 bf 8d 7f |%E......e...E...| | |||
|
127 | 0070: 9f c6 97 9f 2b 44 34 67 d9 ec 8e 0f a0 92 0b 75 |....+D4g.......u| | |||
|
128 | 0080: 41 d6 24 59 18 a4 a4 9a a6 18 1a 5b 98 9b 5a 98 |A.$Y.......[..Z.| | |||
|
129 | 0090: 9a 18 26 9b a6 19 98 1a 99 99 26 a6 18 9a 98 24 |..&.......&....$| | |||
|
130 | 00a0: 26 59 a6 25 5a 98 a5 18 a6 24 71 41 35 b1 43 dc |&Y.%Z....$qA5.C.| | |||
|
131 | 00b0: 96 b0 83 f7 e9 45 8b d2 56 c7 a3 1f 82 52 d7 8a |.....E..V....R..| | |||
|
132 | 00c0: 78 ed fc d5 76 f1 36 95 dc 05 07 00 ad 39 5e d3 |x...v.6......9^.| | |||
|
133 | ||||
115 |
|
|
134 | $ echo "http://localhost:$HGPORT1/partial.hg" > server/.hg/clonebundles.manifest | |
116 | $ hg clone -U http://localhost:$HGPORT partial-bundle |
|
135 | $ hg clone -U http://localhost:$HGPORT partial-bundle | |
117 | applying clone bundle from http://localhost:$HGPORT1/partial.hg |
|
136 | applying clone bundle from http://localhost:$HGPORT1/partial.hg | |
@@ -131,6 +150,39 b' Bundle with full content works' | |||||
131 | $ hg -R server bundle --type gzip-v2 --base null -r tip full.hg |
|
150 | $ hg -R server bundle --type gzip-v2 --base null -r tip full.hg | |
132 | 2 changesets found |
|
151 | 2 changesets found | |
133 |
|
152 | |||
|
153 | Again, we perform an extra check against bundle content changes. If this content | |||
|
154 | changes, clone bundles produced by new Mercurial versions may not be readable | |||
|
155 | by old clients. | |||
|
156 | ||||
|
157 | $ f --size --hexdump full.hg | |||
|
158 | full.hg: size=408 | |||
|
159 | 0000: 48 47 32 30 00 00 00 0e 43 6f 6d 70 72 65 73 73 |HG20....Compress| | |||
|
160 | 0010: 69 6f 6e 3d 47 5a 78 9c 63 60 60 90 e5 76 f6 70 |ion=GZx.c``..v.p| | |||
|
161 | 0020: f4 73 77 75 0f f2 0f 0d 60 00 02 46 06 76 a6 b2 |.swu....`..F.v..| | |||
|
162 | 0030: d4 a2 e2 cc fc 3c 03 23 06 06 e6 7d 40 b1 4d c1 |.....<.#...}@.M.| | |||
|
163 | 0040: 2a 31 09 cf 9a 3a 52 04 b7 fc db f0 95 e5 a4 f4 |*1...:R.........| | |||
|
164 | 0050: 97 17 b2 c9 0c 14 00 02 e6 d9 99 25 1a a7 a4 99 |...........%....| | |||
|
165 | 0060: a4 a4 1a 5b 58 a4 19 27 9b a4 59 a4 1a 59 a4 99 |...[X..'..Y..Y..| | |||
|
166 | 0070: a4 59 26 5a 18 9a 18 59 5a 26 1a 27 27 25 99 a6 |.Y&Z...YZ&.''%..| | |||
|
167 | 0080: 99 1a 70 95 a4 16 97 70 19 28 18 70 a5 e5 e7 73 |..p....p.(.p...s| | |||
|
168 | 0090: 71 25 a6 a4 28 00 19 40 13 0e ac fa df ab ff 7b |q%..(..@.......{| | |||
|
169 | 00a0: 3f fb 92 dc 8b 1f 62 bb 9e b7 d7 d9 87 3d 5a 44 |?.....b......=ZD| | |||
|
170 | 00b0: ac 2f b0 a9 c3 66 1e 54 b9 26 08 a7 1a 1b 1a a7 |./...f.T.&......| | |||
|
171 | 00c0: 25 1b 9a 1b 99 19 9a 5a 18 9b a6 18 19 00 dd 67 |%......Z.......g| | |||
|
172 | 00d0: 61 61 98 06 f4 80 49 4a 8a 65 52 92 41 9a 81 81 |aa....IJ.eR.A...| | |||
|
173 | 00e0: a5 11 17 50 31 30 58 19 cc 80 98 25 29 b1 08 c4 |...P10X....%)...| | |||
|
174 | 00f0: 37 07 79 19 88 d9 41 ee 07 8a 41 cd 5d 98 65 fb |7.y...A...A.].e.| | |||
|
175 | 0100: e5 9e 45 bf 8d 7f 9f c6 97 9f 2b 44 34 67 d9 ec |..E.......+D4g..| | |||
|
176 | 0110: 8e 0f a0 61 a8 eb 82 82 2e c9 c2 20 25 d5 34 c5 |...a....... %.4.| | |||
|
177 | 0120: d0 d8 c2 dc d4 c2 d4 c4 30 d9 34 cd c0 d4 c8 cc |........0.4.....| | |||
|
178 | 0130: 34 31 c5 d0 c4 24 31 c9 32 2d d1 c2 2c c5 30 25 |41...$1.2-..,.0%| | |||
|
179 | 0140: 09 e4 ee 85 8f 85 ff 88 ab 89 36 c7 2a c4 47 34 |..........6.*.G4| | |||
|
180 | 0150: fe f8 ec 7b 73 37 3f c3 24 62 1d 8d 4d 1d 9e 40 |...{s7?.$b..M..@| | |||
|
181 | 0160: 06 3b 10 14 36 a4 38 10 04 d8 21 01 5a b2 83 f7 |.;..6.8...!.Z...| | |||
|
182 | 0170: e9 45 8b d2 56 c7 a3 1f 82 52 d7 8a 78 ed fc d5 |.E..V....R..x...| | |||
|
183 | 0180: 76 f1 36 25 81 49 c0 ad 30 c0 0e 49 8f 54 b7 9e |v.6%.I..0..I.T..| | |||
|
184 | 0190: d4 1c 09 00 bb 8d f0 bd |........| | |||
|
185 | ||||
134 | $ echo "http://localhost:$HGPORT1/full.hg" > server/.hg/clonebundles.manifest |
|
186 | $ echo "http://localhost:$HGPORT1/full.hg" > server/.hg/clonebundles.manifest | |
135 | $ hg clone -U http://localhost:$HGPORT full-bundle |
|
187 | $ hg clone -U http://localhost:$HGPORT full-bundle | |
136 | applying clone bundle from http://localhost:$HGPORT1/full.hg |
|
188 | applying clone bundle from http://localhost:$HGPORT1/full.hg | |
@@ -141,3 +193,37 b' Bundle with full content works' | |||||
141 | finished applying clone bundle |
|
193 | finished applying clone bundle | |
142 | searching for changes |
|
194 | searching for changes | |
143 | no changes found |
|
195 | no changes found | |
|
196 | ||||
|
197 | Entry with unknown BUNDLESPEC is filtered and not used | |||
|
198 | ||||
|
199 | $ cat > server/.hg/clonebundles.manifest << EOF | |||
|
200 | > http://bad.entry1 BUNDLESPEC=UNKNOWN | |||
|
201 | > http://bad.entry2 BUNDLESPEC=xz-v1 | |||
|
202 | > http://bad.entry3 BUNDLESPEC=none-v100 | |||
|
203 | > http://localhost:$HGPORT1/full.hg BUNDLESPEC=gzip-v2 | |||
|
204 | > EOF | |||
|
205 | ||||
|
206 | $ hg clone -U http://localhost:$HGPORT filter-unknown-type | |||
|
207 | applying clone bundle from http://localhost:$HGPORT1/full.hg | |||
|
208 | adding changesets | |||
|
209 | adding manifests | |||
|
210 | adding file changes | |||
|
211 | added 2 changesets with 2 changes to 2 files | |||
|
212 | finished applying clone bundle | |||
|
213 | searching for changes | |||
|
214 | no changes found | |||
|
215 | ||||
|
216 | Automatic fallback when all entries are filtered | |||
|
217 | ||||
|
218 | $ cat > server/.hg/clonebundles.manifest << EOF | |||
|
219 | > http://bad.entry BUNDLESPEC=UNKNOWN | |||
|
220 | > EOF | |||
|
221 | ||||
|
222 | $ hg clone -U http://localhost:$HGPORT filter-all | |||
|
223 | no compatible clone bundles available on server; falling back to regular clone | |||
|
224 | (you may want to report this to the server operator) | |||
|
225 | requesting all changes | |||
|
226 | adding changesets | |||
|
227 | adding manifests | |||
|
228 | adding file changes | |||
|
229 | added 2 changesets with 2 changes to 2 files |
General Comments 0
You need to be logged in to leave comments.
Login now