Debian Codegraph @

tests/test-dirstate.t

raw
1 #testcases dirstate-v1 dirstate-v2
2
3 #if dirstate-v2
4 $ cat >> $HGRCPATH << EOF
5 > [format]
6 > use-dirstate-v2=1
7 > [storage]
8 > dirstate-v2.slow-path=allow
9 > EOF
10 #endif
11
12 ------ Test dirstate._dirs refcounting
13
14 $ hg init t
15 $ cd t
16 $ mkdir -p a/b/c/d
17 $ touch a/b/c/d/x
18 $ touch a/b/c/d/y
19 $ touch a/b/c/d/z
20 $ hg ci -Am m
21 adding a/b/c/d/x
22 adding a/b/c/d/y
23 adding a/b/c/d/z
24 $ hg mv a z
25 moving a/b/c/d/x to z/b/c/d/x
26 moving a/b/c/d/y to z/b/c/d/y
27 moving a/b/c/d/z to z/b/c/d/z
28
29 Test name collisions
30
31 $ rm z/b/c/d/x
32 $ mkdir z/b/c/d/x
33 $ touch z/b/c/d/x/y
34 $ hg add z/b/c/d/x/y
35 abort: file 'z/b/c/d/x' in dirstate clashes with 'z/b/c/d/x/y'
36 [255]
37 $ rm -rf z/b/c/d
38 $ touch z/b/c/d
39 $ hg add z/b/c/d
40 abort: directory 'z/b/c/d' already in dirstate
41 [255]
42
43 $ cd ..
44
45 Issue1790: dirstate entry locked into unset if file mtime is set into
46 the future
47
48 Prepare test repo:
49
50 $ hg init u
51 $ cd u
52 $ echo a > a
53 $ hg add
54 adding a
55 $ hg ci -m1
56
57 Set mtime of a into the future:
58
59 $ touch -t 203101011200 a
60
61 Status must not set a's entry to unset (issue1790):
62
63 $ hg status
64 $ hg debugstate
65 n 644 2 2031-01-01 12:00:00 a
66
67 Check that .hg/dirstate permissions are correct
68 (there was a bug where rust atomic replace would set permissions 0600,
69 which is not what we want)
70
71 #if unix-permissions
72 $ f --mode .hg/dirstate
73 .hg/dirstate: mode=644
74 #endif
75
76 Test modulo storage/comparison of absurd dates:
77
78 #if no-aix
79 $ touch -t 195001011200 a
80 $ hg st
81 $ hg debugstate
82 n 644 2 2018-01-19 15:14:08 a
83 #endif
84
85 Verify that exceptions during a dirstate change leave the dirstate
86 coherent (issue4353)
87
88 $ hg rm a
89 $ hg commit -m 'rm a'
90 $ hg up 0 --config devel.update.abort-on-dirstate-change=yes
91 abort: simulated error while recording dirstate updates
92 [255]
93 $ hg log -r . -T '{rev}\n'
94 1
95 $ hg status
96 ? a
97
98 #if dirstate-v2
99 Check that folders that are prefixes of others do not throw the packer into an
100 infinite loop.
101
102 $ cd ..
103 $ hg init infinite-loop
104 $ cd infinite-loop
105 $ mkdir hgext3rd hgext
106 $ touch hgext3rd/__init__.py hgext/zeroconf.py
107 $ hg commit -Aqm0
108
109 $ hg st -c
110 C hgext/zeroconf.py
111 C hgext3rd/__init__.py
112
113 $ cd ..
114
115 Check that the old dirstate data file is removed correctly and the new one is
116 valid.
117
118 $ dirstate_data_files () {
119 > find .hg -maxdepth 1 -name "dirstate.*"
120 > }
121
122 $ find_dirstate_uuid () {
123 > hg debugstate --docket | grep uuid | sed 's/.*uuid: \(.*\)/\1/'
124 > }
125
126 $ find_dirstate_data_size () {
127 > hg debugstate --docket | grep 'size of dirstate data' | sed 's/.*size of dirstate data: \(.*\)/\1/'
128 > }
129
130 $ dirstate_uuid_has_not_changed () {
131 > # Non-Rust always rewrites the whole dirstate
132 > if [ $# -eq 1 ] || ([ -n "$HGMODULEPOLICY" ] && [ -z "${HGMODULEPOLICY##*rust*}" ]) || [ -n "$RHG_INSTALLED_AS_HG" ]; then
133 > test $current_uid = $(find_dirstate_uuid)
134 > else
135 > echo "not testing because using Python implementation"
136 > fi
137 > }
138
139 $ cd ..
140 $ hg init append-mostly
141 $ cd append-mostly
142 $ mkdir dir dir2
143 $ touch -t 200001010000 dir/a dir/b dir/c dir/d dir/e dir2/f dir dir2
144 $ hg commit -Aqm initial
145 $ hg st
146 $ dirstate_data_files | wc -l
147 *1 (re)
148 $ current_uid=$(find_dirstate_uuid)
149
150 Nothing changes here
151
152 $ hg st
153 $ dirstate_data_files | wc -l
154 *1 (re)
155 $ dirstate_uuid_has_not_changed
156 not testing because using Python implementation (no-rust no-rhg !)
157
158 Trigger an append with a small change to directory mtime
159
160 $ current_data_size=$(find_dirstate_data_size)
161 $ touch -t 201001010000 dir2
162 $ hg st
163 $ dirstate_data_files | wc -l
164 *1 (re)
165 $ dirstate_uuid_has_not_changed
166 not testing because using Python implementation (no-rust no-rhg !)
167 $ new_data_size=$(find_dirstate_data_size)
168 $ [ "$current_data_size" -eq "$new_data_size" ]; echo $?
169 0 (no-rust no-rhg !)
170 1 (rust !)
171 1 (no-rust rhg !)
172
173 Unused bytes counter is non-0 when appending
174 $ touch file
175 $ hg add file
176 $ current_uid=$(find_dirstate_uuid)
177
178 Trigger a rust/rhg run which updates the unused bytes value
179 $ hg st
180 A file
181 $ dirstate_data_files | wc -l
182 *1 (re)
183 $ dirstate_uuid_has_not_changed
184 not testing because using Python implementation (no-rust no-rhg !)
185
186 $ hg debugstate --docket | grep unused
187 number of unused bytes: 0 (no-rust no-rhg !)
188 number of unused bytes: [1-9]\d* (re) (rhg no-rust !)
189 number of unused bytes: [1-9]\d* (re) (rust no-rhg !)
190 number of unused bytes: [1-9]\d* (re) (rust rhg !)
191
192 Delete most of the dirstate to trigger a non-append
193 $ hg rm dir/a dir/b dir/c dir/d
194 $ dirstate_data_files | wc -l
195 *1 (re)
196 $ dirstate_uuid_has_not_changed also-if-python
197 [1]
198
199 Check that unused bytes counter is reset when creating a new docket
200
201 $ hg debugstate --docket | grep unused
202 number of unused bytes: 0
203
204 #endif
205
206 (non-Rust always rewrites)
207
208 Test the devel option to control write behavior
209 ==============================================
210
211 Sometimes, debugging or testing the dirstate requires making sure that we have
212 done a complete rewrite of the data file and have no unreachable data around,
213 sometimes it requires we ensure we don't.
214
215 We test the option to force this rewrite by creating the situation where an
216 append would happen and check that it doesn't happen.
217
218 $ cd ..
219 $ hg init force-base
220 $ cd force-base
221 $ mkdir -p dir/nested dir2
222 $ touch -t 200001010000 f dir/nested/a dir/b dir/c dir/d dir2/e dir/nested dir dir2
223 $ hg commit -Aqm "recreate a bunch of files to facilitate append"
224 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
225 $ cd ..
226
227 #if dirstate-v2
228 $ hg -R force-base debugstate --docket | grep unused
229 number of unused bytes: 0
230
231 Check with the option in "auto" mode
232 ------------------------------------
233 $ cp -a force-base append-mostly-no-force-rewrite
234 $ cd append-mostly-no-force-rewrite
235 $ current_uid=$(find_dirstate_uuid)
236
237 Change mtime of dir on disk which will be recorded, causing a small enough change
238 to warrant only an append
239
240 $ touch -t 202212010000 dir2
241 $ hg st \
242 > --config rhg.on-unsupported=abort \
243 > --config devel.dirstate.v2.data_update_mode=auto
244
245 UUID hasn't changed and a non-zero number of unused bytes means we've appended
246
247 $ dirstate_uuid_has_not_changed
248 not testing because using Python implementation (no-rust no-rhg !)
249
250 #if no-rust no-rhg
251 The pure python implementation never appends at the time this is written.
252 $ hg debugstate --docket | grep unused
253 number of unused bytes: 0 (known-bad-output !)
254 #else
255 $ hg debugstate --docket | grep unused
256 number of unused bytes: [1-9]\d* (re)
257 #endif
258 $ cd ..
259
260 Check the same scenario with the option set to "force-new"
261 ---------------------------------------------------------
262
263 $ cp -a force-base append-mostly-force-rewrite
264 $ cd append-mostly-force-rewrite
265 $ current_uid=$(find_dirstate_uuid)
266
267 Change mtime of dir on disk which will be recorded, causing a small enough change
268 to warrant only an append, but we force the rewrite
269
270 $ touch -t 202212010000 dir2
271 $ hg st \
272 > --config rhg.on-unsupported=abort \
273 > --config devel.dirstate.v2.data_update_mode=force-new
274
275 UUID has changed and zero unused bytes means a full-rewrite happened
276
277
278 #if no-rust no-rhg
279 $ dirstate_uuid_has_not_changed
280 not testing because using Python implementation
281 #else
282 $ dirstate_uuid_has_not_changed
283 [1]
284 #endif
285 $ hg debugstate --docket | grep unused
286 number of unused bytes: 0
287 $ cd ..
288
289
290 Check the same scenario with the option set to "force-append"
291 -------------------------------------------------------------
292
293 (should behave the same as "auto" here)
294
295 $ cp -a force-base append-mostly-force-append
296 $ cd append-mostly-force-append
297 $ current_uid=$(find_dirstate_uuid)
298
299 Change mtime of dir on disk which will be recorded, causing a small enough change
300 to warrant only an append, which we are forcing here anyway.
301
302 $ touch -t 202212010000 dir2
303 $ hg st \
304 > --config rhg.on-unsupported=abort \
305 > --config devel.dirstate.v2.data_update_mode=force-append
306
307 UUID has not changed and some unused bytes exist in the data file
308
309 $ dirstate_uuid_has_not_changed
310 not testing because using Python implementation (no-rust no-rhg !)
311
312 #if no-rust no-rhg
313 The pure python implementation never appends at the time this is written.
314 $ hg debugstate --docket | grep unused
315 number of unused bytes: 0 (known-bad-output !)
316 #else
317 $ hg debugstate --docket | grep unused
318 number of unused bytes: [1-9]\d* (re)
319 #endif
320 $ cd ..
321
322 Check with the option in "auto" mode
323 ------------------------------------
324 $ cp -a force-base append-mostly-no-force-rewrite
325 $ cd append-mostly-no-force-rewrite
326 $ current_uid=$(find_dirstate_uuid)
327
328 Change mtime of everything on disk causing a full rewrite
329
330 $ touch -t 202212010005 `hg files`
331 $ hg st \
332 > --config rhg.on-unsupported=abort \
333 > --config devel.dirstate.v2.data_update_mode=auto
334
335 UUID has changed and zero unused bytes means we've rewritten.
336
337 #if no-rust no-rhg
338 $ dirstate_uuid_has_not_changed
339 not testing because using Python implementation
340 #else
341 $ dirstate_uuid_has_not_changed
342 [1]
343 #endif
344
345 $ hg debugstate --docket | grep unused
346 number of unused bytes: 0 (known-bad-output !)
347 $ cd ..
348
349 Check the same scenario with the option set to "force-new"
350 ---------------------------------------------------------
351
352 (should be the same as auto)
353
354 $ cp -a force-base append-mostly-force-rewrite
355 $ cd append-mostly-force-rewrite
356 $ current_uid=$(find_dirstate_uuid)
357
358 Change mtime of everything on disk causing a full rewrite
359
360 $ touch -t 202212010005 `hg files`
361 $ hg st \
362 > --config rhg.on-unsupported=abort \
363 > --config devel.dirstate.v2.data_update_mode=force-new
364
365 UUID has changed and a zero number unused bytes means we've rewritten.
366
367
368 #if no-rust no-rhg
369 $ dirstate_uuid_has_not_changed
370 not testing because using Python implementation
371 #else
372 $ dirstate_uuid_has_not_changed
373 [1]
374 #endif
375 $ hg debugstate --docket | grep unused
376 number of unused bytes: 0
377 $ cd ..
378
379
380 Check the same scenario with the option set to "force-append"
381 -------------------------------------------------------------
382
383 Should append even if "auto" did not
384
385 $ cp -a force-base append-mostly-force-append
386 $ cd append-mostly-force-append
387 $ current_uid=$(find_dirstate_uuid)
388
389 Change mtime of everything on disk causing a full rewrite
390
391 $ touch -t 202212010005 `hg files`
392 $ hg st \
393 > --config rhg.on-unsupported=abort \
394 > --config devel.dirstate.v2.data_update_mode=force-append
395
396 UUID has not changed and some unused bytes exist in the data file
397
398 $ dirstate_uuid_has_not_changed
399 not testing because using Python implementation (no-rust no-rhg !)
400
401 #if no-rust no-rhg
402 The pure python implementation is never appending at the time this is written.
403 $ hg debugstate --docket | grep unused
404 number of unused bytes: 0 (known-bad-output !)
405 #else
406 $ hg debugstate --docket | grep unused
407 number of unused bytes: [1-9]\d* (re)
408 #endif
409 $ cd ..
410
411
412
413 Get back into a state suitable for the test of the file.
414
415 $ cd ./append-mostly
416
417 #else
418 $ cd ./u
419 #endif
420
421 Transaction compatibility
422 =========================
423
424 The transaction preserves the dirstate.
425 We should make sure all of it (docket + data) is preserved
426
427 #if dirstate-v2
428 $ hg commit -m 'bli'
429 #endif
430
431 $ hg update --quiet
432 $ hg revert --all --quiet
433 $ rm -f a
434 $ echo foo > foo
435 $ hg add foo
436 $ hg commit -m foo
437
438 #if dirstate-v2
439 $ uid=$(find_dirstate_uuid)
440 $ touch bar
441 $ while [ uid = $(find_dirstate_uuid) ]; do
442 > hg add bar;
443 > hg remove bar;
444 > done;
445 $ rm bar
446 #endif
447 $ hg rollback
448 repository tip rolled back to revision 1 (undo commit)
449 working directory now based on revision 1
450
451 $ hg status
452 A foo
453 $ cd ..
454
455 Check dirstate ordering
456 (e.g. `src/dirstate/` and `src/dirstate.rs` shouldn't cause issues)
457
458 $ hg init repro
459 $ cd repro
460 $ mkdir src
461 $ mkdir src/dirstate
462 $ touch src/dirstate/file1 src/dirstate/file2 src/dirstate.rs
463 $ touch file1 file2
464 $ hg commit -Aqm1
465 $ hg st
466 $ cd ..