Debian Codegraph @

tests/test-bundle-shape.t

raw
1 #require rust
2
3 TODO test streamv3 once that gains shapes support
4
5 Setup
6 =====
7
8 $ cat >> $HGRCPATH << EOF
9 > [extensions]
10 > clonebundles=
11 > narrow=
12 >
13 > [experimental]
14 > server.stream-narrow-clones=yes
15 > EOF
16
17 Generate a source repo with a bunch of files and folders, some with a few edits
18 $ hg init source
19 $ cd source
20 $ mkdir -p dir1/excluded/nested dir2 excluded
21 $ touch \
22 > a \
23 > b \
24 > dir1/a \
25 > dir1/b \
26 > dir1/excluded/a \
27 > dir1/excluded/b \
28 > dir1/excluded/nested/a \
29 > dir1/excluded/nested/b \
30 > dir2/a \
31 > dir2/b \
32 > excluded/a \
33 > excluded/b
34 $ hg commit -Aqm0
35 $ echo "foo" > a
36 $ echo "foo" > dir1/a
37 $ echo "foobar" > dir1/b
38 $ echo "foobar" > dir2/b
39 $ echo "foo" > dir2/a
40 $ echo "foo" > dir1/excluded/a
41 $ echo "foo" > excluded/a
42 $ echo "foobar" > excluded/b
43 $ hg commit -qm1
44 $ echo "bar" > dir1/excluded/a
45 $ hg commit -qm2
46 $ cd ..
47
48 Test errors
49 ===========
50
51 Make sure we complain if not using Rust when generating a shape bundle
52 $ HGMODULEPOLICY=c hg bundle -R source -a -t"none-v2;stream=v2;shape=foo" --config storage.all-slow-path=allow outfile.hg
53 abort: shape bundlespec option is only available with the Rust extensions
54 [10]
55
56 Make sure we complain if not using stream bundles when generating a shape bundle
57 $ hg bundle -R source -a -t"none-v2;shape=foo" outfile.hg
58 abort: shape bundlespec option is only implemented for stream bundles
59 [10]
60
61 Test without any shaping (sanity check)
62 $ hg bundle -R source -a -t"none-v2;stream=v2" outfile-no-shape.hg
63
64 $ hg debugbundle outfile-no-shape.hg
65 Stream params: {}
66 stream2 -- {bytecount: *, filecount: 20, requirements: *} (mandatory: True) (glob)
67
68 Create shapes config
69
70 $ cat >> source/.hg/store/server-shapes << EOF
71 > version = 0
72 > [[shards]]
73 > name = "default"
74 > requires = ["base"]
75 > shape = true
76 > [[shards]]
77 > name = "excluded1"
78 > paths = ["excluded"]
79 > [[shards]]
80 > name = "excluded2"
81 > paths = ["dir1/excluded"]
82 > [[shards]]
83 > name = "foobar"
84 > paths = ["dir2"]
85 > shape = true
86 > [[shards]]
87 > name = "foobaz"
88 > shape = true
89 > requires = ["excluded1", "foobar"]
90 > EOF
91
92 Test with an unknown shape
93 $ hg -R source bundle -a --type="none-v2;stream=v2;shape=foo" outfile-shaped.hg
94 abort: unknown shape: 'foo'
95 [10]
96
97 Test with the default shape
98 $ hg -R source bundle -a --type="none-v2;stream=v2;shape=default" outfile-shape-default.hg
99
100 $ hg debugbundle outfile-shape-default.hg | grep -E 'store-fingerprint: [0-9a-f]{64}'
101 stream2 -- {bytecount: *, filecount: 12, requirements: *, store-fingerprint: 961e3d6d14621106b59a576aa6d8907d3f4734ea3f04c01d0bdff031b5572b19} (mandatory: True) (glob)
102
103 Add a full non-fingerprinted streaming clone for reference and fallback testing
104 $ hg -R source bundle -a --type="none-v2;stream=v2" outfile-shape-full.hg
105
106 $ hg debugbundle outfile-shape-full.hg
107 Stream params: {}
108 stream2 -- {bytecount: 2637, filecount: 20, requirements: generaldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog} (mandatory: True)
109
110
111 Test with a known shape
112 $ hg -R source bundle -a --type="none-v2;stream=v2;shape=foobar" outfile-shape-foobar.hg
113
114 $ hg debugbundle outfile-shape-foobar.hg | grep -E 'store-fingerprint: [0-9a-f]{64}'
115 stream2 -- {bytecount: *, filecount: 10, requirements: *, store-fingerprint: feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726} (mandatory: True) (glob)
116
117 $ hg -R source bundle -a --type="none-v2;stream=v2;shape=foobaz" outfile-shape-foobaz.hg
118
119 $ hg debugbundle outfile-shape-foobaz.hg | grep -E 'store-fingerprint: [0-9a-f]{64}'
120 stream2 -- {bytecount: *, filecount: 12, requirements: *, store-fingerprint: bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e} (mandatory: True) (glob)
121
122 Test cloning
123 ============
124
125 Start hg server
126 ---------------
127
128 $ cd source
129 $ hg serve -d -p $HGPORT --pid-file hg.pid --errorlog error.log --accesslog access.log
130 $ cat hg.pid >> $DAEMON_PIDS
131 $ cd ..
132
133 Prepare inline bundles
134 ----------------------
135
136 $ bundlespec="$(hg debugbundle --spec outfile-shape-foobar.hg)"
137 $ echo $bundlespec
138 none-v2;stream=v2;requirements*;store-fingerprint=feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726 (glob)
139 $ bundlespec2="$(hg debugbundle --spec outfile-shape-foobaz.hg)"
140 $ echo $bundlespec2
141 none-v2;stream=v2;requirements*;store-fingerprint=bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e (glob)
142
143 $ bundlespecfull="$(hg debugbundle --spec outfile-shape-full.hg)"
144 $ echo $bundlespecfull
145 none-v2;stream=v2;requirements%3Dgeneraldelta%2Crevlog-compression-zstd%2Crevlogv1%2Csparserevlog
146
147 $ mkdir source/.hg/bundle-cache
148 $ mv outfile-shape-*.hg source/.hg/bundle-cache/
149
150 $ cat > source/.hg/clonebundles.manifest << EOF
151 > peer-bundle-cache://outfile-shape-foobar.hg BUNDLESPEC=$bundlespec
152 > peer-bundle-cache://outfile-shape-foobaz.hg BUNDLESPEC=$bundlespec2
153 > EOF
154
155 Check the resulting manifest
156 ----------------------------
157
158 Define the special set of files included in all shapes.
159 $ hgfiles="--include=.hgignore --include=.hgtags --include=.hgsub --include=.hgsubstate"
160
161
162 The raw manifest looks OK
163 $ hg debug::clonebundle-manifest ssh://user@dummy/source --raw
164 peer-bundle-cache://outfile-shape-foobar.hg BUNDLESPEC=none-v2;stream=v2;requirements*;store-fingerprint=feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726 (glob)
165 peer-bundle-cache://outfile-shape-foobaz.hg BUNDLESPEC=none-v2;stream=v2;requirements*;store-fingerprint=bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e (glob)
166
167 Passing in no includes or excludes shows that all entries are filtered out due to their fingerprints
168 $ hg debug::clonebundle-manifest ssh://user@dummy/source --debug | grep 'correct store fingerprint'
169 filtering peer-bundle-cache://outfile-shape-foobar.hg because not the correct store fingerprint (expected feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726)
170 filtering peer-bundle-cache://outfile-shape-foobaz.hg because not the correct store fingerprint (expected bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e)
171
172 Passing a pattern that matches nothing filters all entries
173 $ hg debug::clonebundle-manifest ssh://user@dummy/source --include=no_match
174
175 Passing a matching pattern works
176 $ hg debug::clonebundle-manifest ssh://user@dummy/source --include=dir2 $hgfiles
177 URL: peer-bundle-cache://outfile-shape-foobar.hg
178 BUNDLESPEC: none-v2;stream=v2;requirements=*;store-fingerprint=feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726 (glob)
179 COMPRESSION: none
180 VERSION: v2
181 STORE-FINGERPRINT: feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726
182
183 Non-streaming, non-narrow cloning
184 ---------------------------------
185
186 Passing no includes should fall back to regular clone
187
188 $ hg clone ssh://user@dummy/source plain-clone 2>&1 --narrow | grep "falling back"
189 no compatible clone bundles available on server; falling back to regular clone
190 $ rm -rf plain-clone
191
192 Test a pure Python client
193 $ HGMODULEPOLICY=py hg clone ssh://user@dummy/source --narrow plain-clone 2>&1 | grep "falling back"
194 no compatible clone bundles available on server; falling back to regular clone
195
196 $ cat source/error.log
197 $ cat source/access.log
198
199
200 Non-narrow streaming cloning
201 ----------------------------
202
203 Passing no includes should fall back to full (non-fingerprinted) streaming clone if available
204
205 $ echo "peer-bundle-cache://outfile-shape-full.hg BUNDLESPEC=$bundlespecfull" >> source/.hg/clonebundles.manifest
206 $ hg clone ssh://user@dummy/source full-clone | grep "bundle from"
207 applying clone bundle from peer-bundle-cache://outfile-shape-full.hg
208
209 Test a pure Python client
210 $ rm -rf full-clone
211 $ HGMODULEPOLICY=py hg clone ssh://user@dummy/source --narrow full-clone | grep "bundle from"
212 applying clone bundle from peer-bundle-cache://outfile-shape-full.hg
213
214
215 $ cat source/error.log
216 $ cat source/access.log
217
218 Narrow + stream cloning
219 -----------------------
220
221 The right fingerprint should be derived from the narrow patterns, selecting
222 the correct narrow stream clone bundle
223
224 Test that if no fingerprints match, we don't clone anything
225
226 $ hg debug::clonebundle-manifest ssh://user@dummy/source --include=notexist
227
228 $ hg clone ssh://user@dummy/source clone-shaped --narrow --include=notexist 2>&1 | grep "falling back"
229 no compatible clone bundles available on server; falling back to regular clone
230 $ rm -rf clone-shaped
231
232 Test matching fingerprints
233
234 First with a Python client
235 $ HGMODULEPOLICY=py hg clone ssh://user@dummy/source clone-shaped --narrow $hgfiles --include=dir2 | grep "bundle from"
236 applying clone bundle from peer-bundle-cache://outfile-shape-foobar.hg
237 $ hg admin::narrow-client -R clone-shaped --store-fingerprint
238 feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726
239 $ rm -rf clone-shaped
240
241 Then with the Rust client
242
243 $ hg clone ssh://user@dummy/source clone-shaped --narrow $hgfiles --include=dir2 | grep "bundle from"
244 applying clone bundle from peer-bundle-cache://outfile-shape-foobar.hg
245 $ cd clone-shaped
246 $ hg debug-revlog-stats --filelogs -T'{revlog_target}\n'
247 dir2/a
248 dir2/b
249
250 We make sure that the client has the same fingerprint than the streamclone
251
252 $ hg admin::narrow-client --store-fingerprint
253 feb09be59c639f9f80726b5cd0204cf05cda6ea875fa7fd7c1dea98f9a28e726
254
255 We make sure that the client has the expected narrowspec
256
257 $ hg tracked
258 I path:.hgignore
259 I path:.hgsub
260 I path:.hgsubstate
261 I path:.hgtags
262 I path:dir2
263
264 Accessing a file outside of the shape is not possible
265
266 $ hg cat a
267 [1]
268 $ hg cat excluded/a
269 [1]
270
271 The rest works correctly
272
273 $ hg cat dir2/a
274 foo
275 $ hg cat dir2/b
276 foobar
277 $ cd ..
278
279 Testing another shape
280 ---------------------
281
282 First with a pure Python client
283
284 $ HGMODULEPOLICY=py hg clone ssh://user@dummy/source clone-shaped2 --narrow $hgfiles --include=dir2 --include=excluded | grep "bundle from"
285 applying clone bundle from peer-bundle-cache://outfile-shape-foobaz.hg
286 $ hg -R clone-shaped2 admin::narrow-client --store-fingerprint
287 bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e
288 $ rm -rf clone-shaped2
289
290 Then with the Rust client
291
292 $ hg clone ssh://user@dummy/source clone-shaped2 --narrow --include=dir2 $hgfiles --include=excluded | grep "bundle from"
293 applying clone bundle from peer-bundle-cache://outfile-shape-foobaz.hg
294 $ cd clone-shaped2
295 $ hg debug-revlog-stats --filelogs -T'{revlog_target}\n'
296 dir2/a
297 dir2/b
298 excluded/a
299 excluded/b
300
301 The client has the same fingerprint than the streamclone
302
303 $ hg admin::narrow-client --store-fingerprint
304 bda77439a4ee183aaa533e68680cdbc2fae13fb0c0e20210a598fe8889ef640e
305
306 The client has the expected narrowspec
307
308 $ hg tracked
309 I path:.hgignore
310 I path:.hgsub
311 I path:.hgsubstate
312 I path:.hgtags
313 I path:dir2
314 I path:excluded
315
316 Accessing a file outside of the shape is not possible
317
318 $ hg cat a
319 [1]
320 $ hg cat excluded/a
321 foo
322
323 The rest works correctly
324 $ hg cat excluded/a
325 foo
326 $ hg cat dir2/a
327 foo
328 $ hg cat dir2/b
329 foobar