Debian Codegraph @

tests/test-fncache.t

raw
1 An extension which will set fncache chunksize to 1 byte to make sure that logic
2 does not break
3
4 $ cat > chunksize.py <<EOF
5 > from mercurial import store
6 > store.fncache_chunksize = 1
7 > EOF
8
9 $ cat >> $HGRCPATH <<EOF
10 > [extensions]
11 > chunksize = $TESTTMP/chunksize.py
12 > EOF
13
14 Init repo1:
15
16 $ hg init repo1
17 $ cd repo1
18 $ echo "some text" > a
19 $ hg add
20 adding a
21 $ hg ci -m first
22 $ cat .hg/store/fncache | sort
23 data/a.i
24
25 Testing a.i/b:
26
27 $ mkdir a.i
28 $ echo "some other text" > a.i/b
29 $ hg add
30 adding a.i/b
31 $ hg ci -m second
32 $ cat .hg/store/fncache | sort
33 data/a.i
34 data/a.i.hg/b.i
35
36 Testing a.i.hg/c:
37
38 $ mkdir a.i.hg
39 $ echo "yet another text" > a.i.hg/c
40 $ hg add
41 adding a.i.hg/c
42 $ hg ci -m third
43 $ cat .hg/store/fncache | sort
44 data/a.i
45 data/a.i.hg.hg/c.i
46 data/a.i.hg/b.i
47
48 Testing verify:
49
50 $ hg verify -q
51
52 $ rm .hg/store/fncache
53
54 $ hg verify
55 checking changesets
56 checking manifests
57 crosschecking files in changesets and manifests
58 checking files
59 warning: revlog 'data/a.i' not in fncache!
60 warning: revlog 'data/a.i.hg/c.i' not in fncache!
61 warning: revlog 'data/a.i/b.i' not in fncache!
62 checking dirstate
63 checked 3 changesets with 3 changes to 3 files
64 3 warnings encountered!
65 hint: run "hg debugrebuildfncache" to recover from corrupt fncache
66
67 Follow the hint to make sure it works
68
69 $ hg debugrebuildfncache
70 adding data/a.i
71 adding data/a.i.hg/c.i
72 adding data/a.i/b.i
73 3 items added, 0 removed from fncache
74
75 $ hg verify -q
76
77 $ cd ..
78
79 Non store repo:
80
81 $ hg --config format.usestore=False init foo
82 $ cd foo
83 $ mkdir tst.d
84 $ echo foo > tst.d/foo
85 $ hg ci -Amfoo
86 adding tst.d/foo
87 $ find .hg | sort
88 .hg
89 .hg/00changelog-6b8ab34b.nd (rust !)
90 .hg/00changelog.d
91 .hg/00changelog.i
92 .hg/00changelog.n (rust !)
93 .hg/00manifest.i
94 .hg/branch
95 .hg/cache
96 .hg/cache/branch2-served
97 .hg/cache/rbc-names-v2
98 .hg/cache/rbc-revs-v2
99 .hg/data
100 .hg/data/tst.d.hg
101 .hg/data/tst.d.hg/foo.i
102 .hg/dirstate
103 .hg/fsmonitor.state (fsmonitor !)
104 .hg/last-message.txt
105 .hg/phaseroots
106 .hg/requires
107 .hg/undo
108 .hg/undo.backup.branch.bck
109 .hg/undo.backupfiles
110 .hg/undo.desc
111 .hg/wcache
112 .hg/wcache/checkisexec (execbit !)
113 .hg/wcache/checklink (symlink !)
114 .hg/wcache/checklink-target (symlink !)
115 .hg/wcache/manifestfulltextcache
116 $ cd ..
117
118 Non fncache repo:
119
120 $ hg --config format.usefncache=False init bar
121 $ cd bar
122 $ mkdir tst.d
123 $ echo foo > tst.d/Foo
124 $ hg ci -Amfoo
125 adding tst.d/Foo
126 $ find .hg | sort
127 .hg
128 .hg/00changelog.i
129 .hg/branch
130 .hg/cache
131 .hg/cache/branch2-served
132 .hg/cache/rbc-names-v2
133 .hg/cache/rbc-revs-v2
134 .hg/dirstate
135 .hg/fsmonitor.state (fsmonitor !)
136 .hg/last-message.txt
137 .hg/requires
138 .hg/store
139 .hg/store/00changelog-b875dfc5.nd (rust !)
140 .hg/store/00changelog.d
141 .hg/store/00changelog.i
142 .hg/store/00changelog.n (rust !)
143 .hg/store/00manifest.i
144 .hg/store/data
145 .hg/store/data/tst.d.hg
146 .hg/store/data/tst.d.hg/_foo.i
147 .hg/store/phaseroots
148 .hg/store/requires
149 .hg/store/undo
150 .hg/store/undo.backupfiles
151 .hg/undo.backup.branch.bck
152 .hg/undo.desc
153 .hg/wcache
154 .hg/wcache/checkisexec (execbit !)
155 .hg/wcache/checklink (symlink !)
156 .hg/wcache/checklink-target (symlink !)
157 .hg/wcache/manifestfulltextcache
158 $ cd ..
159
160 Encoding of reserved / long paths in the store
161
162 $ hg init r2
163 $ cd r2
164 $ cat <<EOF > .hg/hgrc
165 > [ui]
166 > portablefilenames = ignore
167 > EOF
168
169 $ hg import -q --bypass - <<EOF
170 > # HG changeset patch
171 > # User test
172 > # Date 0 0
173 > # Node ID 1c7a2f7cb77be1a0def34e4c7cabc562ad98fbd7
174 > # Parent 0000000000000000000000000000000000000000
175 > 1
176 >
177 > diff --git a/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz b/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz
178 > new file mode 100644
179 > --- /dev/null
180 > +++ b/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz
181 > @@ -0,0 +1,1 @@
182 > +foo
183 > diff --git a/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT b/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT
184 > new file mode 100644
185 > --- /dev/null
186 > +++ b/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT
187 > @@ -0,0 +1,1 @@
188 > +foo
189 > diff --git a/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt b/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt
190 > new file mode 100644
191 > --- /dev/null
192 > +++ b/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt
193 > @@ -0,0 +1,1 @@
194 > +foo
195 > diff --git a/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c b/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c
196 > new file mode 100644
197 > --- /dev/null
198 > +++ b/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c
199 > @@ -0,0 +1,1 @@
200 > +foo
201 > diff --git a/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider b/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider
202 > new file mode 100644
203 > --- /dev/null
204 > +++ b/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider
205 > @@ -0,0 +1,1 @@
206 > +foo
207 > EOF
208
209 $ find .hg/store -name *.i | sort
210 .hg/store/00changelog.i
211 .hg/store/00manifest.i
212 .hg/store/data/bla.aux/pr~6e/_p_r_n/lpt/co~6d3/nu~6c/coma/foo._n_u_l/normal.c.i
213 .hg/store/dh/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxx168e07b38e65eff86ab579afaaa8e30bfbe0f35f.i
214 .hg/store/dh/au~78/second/x.prn/fourth/fi~3afth/sixth/seventh/eighth/nineth/tenth/loremia20419e358ddff1bf8751e38288aff1d7c32ec05.i
215 .hg/store/dh/enterpri/openesba/contrib-/corba-bc/netbeans/wsdlexte/src/main/java/org.net7018f27961fdf338a598a40c4683429e7ffb9743.i
216 .hg/store/dh/project_/resource/anotherl/followed/andanoth/andthenanextremelylongfilename0d8e1f4187c650e2f1fdca9fd90f786bc0976b6b.i
217
218 $ cd ..
219
220 Aborting lock does not prevent fncache writes
221
222 $ cat > exceptionext.py <<EOF
223 > import os
224 > from mercurial import commands, error, extensions
225 >
226 > def lockexception(orig, vfs, lockname, wait, releasefn, *args, **kwargs):
227 > def releasewrap():
228 > l.held = False # ensure __del__ is a noop
229 > raise error.Abort(b"forced lock failure")
230 > l = orig(vfs, lockname, wait, releasewrap, *args, **kwargs)
231 > return l
232 >
233 > def reposetup(ui, repo):
234 > extensions.wrapfunction(repo, '_lock', lockexception)
235 >
236 > cmdtable = {}
237 >
238 > # wrap "commit" command to prevent wlock from being '__del__()'-ed
239 > # at the end of dispatching (for intentional "forced lcok failure")
240 > def commitwrap(orig, ui, repo, *pats, **opts):
241 > repo = repo.unfiltered() # to use replaced repo._lock certainly
242 > wlock = repo.wlock()
243 > try:
244 > return orig(ui, repo, *pats, **opts)
245 > finally:
246 > # multiple 'relase()' is needed for complete releasing wlock,
247 > # because "forced" abort at last releasing store lock
248 > # prevents wlock from being released at same 'lockmod.release()'
249 > for i in range(wlock.held):
250 > wlock.release()
251 >
252 > def extsetup(ui):
253 > extensions.wrapcommand(commands.table, b"commit", commitwrap)
254 > EOF
255 $ extpath=`pwd`/exceptionext.py
256 $ hg init fncachetxn
257 $ cd fncachetxn
258 $ touch y
259 $ hg ci -qAm y --config extensions.exceptionext="$extpath"
260 abort: forced lock failure
261 [255]
262 $ cat .hg/store/fncache
263 data/y.i
264
265 $ rm -f "$extpath" "${extpath}c"
266 $ rm -Rf "`dirname $extpath`/__pycache__"
267
268 Aborting transaction prevents fncache change
269
270 $ touch z
271 $ hg ci -qAm z --config devel.debug.abort-transaction=abort-post-finalize
272 transaction abort!
273 rollback completed
274 abort: requested abort-post-finalize
275 [255]
276 $ cat .hg/store/fncache
277 data/y.i
278
279 Aborted transactions can be recovered later
280
281 $ hg up -q 1
282 $ touch z
283 # Cannot rely on the return code value as chg use a different one.
284 # So we use a `|| echo` trick
285 # XXX-CHG fixing chg behavior would be nice here.
286 $ hg ci -qAm z --config devel.debug.abort-transaction=kill-9-post-finalize \
287 > || echo "He's Dead, Jim." 2>/dev/null
288 *Killed* (glob) (?)
289 He's Dead, Jim.
290 $ cat .hg/store/fncache | sort
291 data/y.i
292 data/z.i
293 $ hg recover --verify
294 rolling back interrupted transaction
295 checking changesets
296 checking manifests
297 crosschecking files in changesets and manifests
298 checking files
299 checking dirstate
300 checked 1 changesets with 1 changes to 1 files
301 $ cat .hg/store/fncache
302 data/y.i
303
304 $ cd ..
305
306 debugrebuildfncache does nothing unless repo has fncache requirement
307
308 $ hg --config format.usefncache=false init nofncache
309 $ cd nofncache
310 $ hg debugrebuildfncache
311 (not rebuilding fncache because repository does not support fncache)
312
313 $ cd ..
314
315 debugrebuildfncache works on empty repository
316
317 $ hg init empty
318 $ cd empty
319 $ hg debugrebuildfncache
320 fncache already up to date
321 $ cd ..
322
323 debugrebuildfncache on an up to date repository no-ops
324
325 $ hg init repo
326 $ cd repo
327 $ echo initial > foo
328 $ echo initial > .bar
329 $ hg commit -A -m initial
330 adding .bar
331 adding foo
332
333 $ cat .hg/store/fncache | sort
334 data/.bar.i
335 data/foo.i
336
337 $ hg debugrebuildfncache
338 fncache already up to date
339
340 debugrebuildfncache restores deleted fncache file
341
342 $ rm -f .hg/store/fncache
343 $ hg debugrebuildfncache
344 adding data/.bar.i
345 adding data/foo.i
346 2 items added, 0 removed from fncache
347
348 $ cat .hg/store/fncache | sort
349 data/.bar.i
350 data/foo.i
351
352 Rebuild after rebuild should no-op
353
354 $ hg debugrebuildfncache
355 fncache already up to date
356
357 A single missing file should get restored, an extra file should be removed
358
359 $ cat > .hg/store/fncache << EOF
360 > data/foo.i
361 > data/bad-entry.i
362 > EOF
363
364 $ hg debugrebuildfncache
365 removing data/bad-entry.i
366 adding data/.bar.i
367 1 items added, 1 removed from fncache
368
369 $ cat .hg/store/fncache | sort
370 data/.bar.i
371 data/foo.i
372
373 debugrebuildfncache recovers from truncated line in fncache
374
375 $ printf a > .hg/store/fncache
376 $ hg debugrebuildfncache
377 fncache does not ends with a newline
378 adding data/.bar.i
379 adding data/foo.i
380 2 items added, 0 removed from fncache
381
382 $ cat .hg/store/fncache | sort
383 data/.bar.i
384 data/foo.i
385
386 $ cd ..
387
388 Try a simple variation without dotencode to ensure fncache is ignorant of encoding
389
390 $ hg --config format.dotencode=false init nodotencode
391 $ cd nodotencode
392 $ echo initial > foo
393 $ echo initial > .bar
394 $ hg commit -A -m initial
395 adding .bar
396 adding foo
397
398 $ cat .hg/store/fncache | sort
399 data/.bar.i
400 data/foo.i
401
402 $ rm .hg/store/fncache
403 $ hg debugrebuildfncache
404 adding data/.bar.i
405 adding data/foo.i
406 2 items added, 0 removed from fncache
407
408 $ cat .hg/store/fncache | sort
409 data/.bar.i
410 data/foo.i
411
412 $ cd ..
413
414 In repositories that have accumulated a large number of files over time, the
415 fncache file is going to be large. If we possibly can avoid loading it, so much the better.
416 The cache should not loaded when committing changes to existing files, or when unbundling
417 changesets that only contain changes to existing files:
418
419 $ cat > fncacheloadwarn.py << EOF
420 > from mercurial import extensions, localrepo
421 >
422 > def extsetup(ui):
423 > def wrapstore(orig, ui, requirements, *args, **kwargs):
424 > store = orig(ui, requirements, *args, **kwargs)
425 > if b'store' in requirements and b'fncache' in requirements:
426 > instrumentfncachestore(store, ui)
427 > return store
428 > extensions.wrapfunction(localrepo, 'makestore', wrapstore)
429 >
430 > def instrumentfncachestore(fncachestore, ui):
431 > class instrumentedfncache(type(fncachestore.fncache)):
432 > def _load(self):
433 > ui.warn(b'fncache load triggered!\n')
434 > super(instrumentedfncache, self)._load()
435 > fncachestore.fncache.__class__ = instrumentedfncache
436 > EOF
437
438 $ fncachextpath=`pwd`/fncacheloadwarn.py
439 $ hg init nofncacheload
440 $ cd nofncacheload
441 $ printf "[extensions]\nfncacheloadwarn=$fncachextpath\n" >> .hg/hgrc
442
443 A new file should trigger a load, as we'd want to update the fncache set in that case:
444
445 $ touch foo
446 $ hg ci -qAm foo
447 fncache load triggered!
448
449 But modifying that file should not:
450
451 $ echo bar >> foo
452 $ hg ci -qm foo
453
454 If a transaction has been aborted, the zero-size truncated index file will
455 not prevent the fncache from being loaded; rather than actually abort
456 a transaction, we simulate the situation by creating a zero-size index file:
457
458 $ touch .hg/store/data/bar.i
459 $ touch bar
460 $ hg ci -qAm bar
461 fncache load triggered!
462
463 Unbundling should follow the same rules; existing files should not cause a load:
464
465 (loading during the clone is expected)
466 $ hg clone -q . tobundle
467 fncache load triggered!
468 fncache load triggered!
469 fncache load triggered!
470
471 $ echo 'new line' > tobundle/bar
472 $ hg -R tobundle ci -qm bar
473 $ hg -R tobundle bundle -q barupdated.hg
474 $ hg unbundle -q barupdated.hg
475
476 but adding new files should:
477
478 $ touch tobundle/newfile
479 $ hg -R tobundle ci -qAm newfile
480 $ hg -R tobundle bundle -q newfile.hg
481 $ hg unbundle -q newfile.hg
482 fncache load triggered!
483
484 $ cd ..
485
486 Behavior around strip
487 ---------------------
488
489 $ hg clone nofncacheload strip-test
490 fncache load triggered!
491 fncache load triggered!
492 updating to branch default
493 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
494 fncache load triggered!
495 $ cd strip-test
496
497 We starts with a valid repository
498
499 $ hg verify
500 checking changesets
501 checking manifests
502 crosschecking files in changesets and manifests
503 checking files
504 checking dirstate
505 checked 5 changesets with 5 changes to 3 files
506 $ cat .hg/store/fncache | sort
507 data/bar.i
508 data/foo.i
509 data/newfile.i
510
511 That contains 3 file, the last of which added in the last changeset
512
513 $ hg manifest --all
514 bar
515 foo
516 newfile
517 $ hg status --change 4
518 A newfile
519
520 We strip that change, removing the file
521
522 $ hg debugstrip --rev 4
523 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
524 saved backup bundle to $TESTTMP/strip-test/.hg/strip-backup/dc782f6e0b2d-71d6a2b0-backup.hg
525 $ hg manifest --all
526 bar
527 foo
528
529 The repository should still be valid
530
531 $ hg verify
532 checking changesets
533 checking manifests
534 crosschecking files in changesets and manifests
535 checking files
536 checking dirstate
537 checked 4 changesets with 4 changes to 2 files
538 $ cat .hg/store/fncache | sort
539 data/bar.i
540 data/foo.i
541
542
543 $ cd ..