Debian Codegraph @

tests/test-file-index.t

raw
1 #if no-rust
2 $ cat << EOF >> $HGRCPATH
3 > [storage]
4 > fileindex.slow-path=allow
5 > EOF
6 #endif
7
8 Test the basics
9 ---------------
10
11 Create a new repo with the file index
12 $ hg init repo1 --config format.use-fileindex-v1=1
13 $ cd repo1
14 $ hg debugrequirements | grep -E 'fncache|dotencode|fileindex'
15 fileindex-v1
16 $ hg debugformat --verbose fncache dotencode fileindex
17 format-variant repo config default
18 fncache: no yes yes
19 fileindex-v1: yes no no
20 dotencode: no yes yes
21 $ hg debug::file-index
22 $ hg debug::file-index --docket
23 marker: fileindex-v1
24 list_file_size: 0
25 meta_file_size: 0
26 tree_file_size: 0
27 list_file_id: 00000000
28 meta_file_id: 00000000
29 tree_file_id: 00000000
30 tree_root_pointer: 0
31 tree_unused_bytes: 0
32 reserved_flags: 0
33 garbage_entries: 0
34 $ hg debug::file-index --tree
35 00000000: "" (0)
36 Add a file
37 $ touch file
38 $ hg add file
39 $ hg commit -m 0
40
41 Confirm it's in the file index, not the fncache
42 $ test -f .hg/store/fncache
43 [1]
44 $ ls .hg/store/fileindex*
45 .hg/store/fileindex
46 .hg/store/fileindex-list.* (glob)
47 .hg/store/fileindex-meta.* (glob)
48 .hg/store/fileindex-tree.* (glob)
49 $ hg debug::file-index
50 1: file
51
52 Look up by path and by token
53 $ hg debug::file-index --path file
54 1: file
55 $ hg debug::file-index --token 1
56 1: file
57 $ hg debug::file-index --path nonexistent
58 abort: path nonexistent is not in the file index
59 [10]
60 $ hg debug::file-index --token 0
61 abort: token 0 is not in the file index
62 [10]
63 $ hg debug::file-index --token 2
64 abort: token 2 is not in the file index
65 [10]
66
67 Examine the file index structure
68 $ hg debug::file-index --docket
69 marker: fileindex-v1
70 list_file_size: 5
71 meta_file_size: 16
72 tree_file_size: 11
73 list_file_id: * (glob)
74 meta_file_id: * (glob)
75 tree_file_id: * (glob)
76 tree_root_pointer: 0
77 tree_unused_bytes: 0
78 reserved_flags: 0
79 garbage_entries: 0
80 $ hg debug::file-index --tree
81 00000000: "" (0)
82 "f" -> "file" (1)
83
84 Add more files
85 $ touch fi filename other
86 $ hg add
87 adding fi
88 adding filename
89 adding other
90 $ hg commit -m 1
91 $ hg debug::file-index
92 1: file
93 2: fi
94 3: filename
95 4: other
96 $ hg debug::file-index --path filename
97 3: filename
98 $ hg debug::file-index --token 3
99 3: filename
100 $ hg debug::file-index --tree
101 0000000b: "" (0)
102 "f" -> 0000001b
103 "o" -> "other" (4)
104 0000001b: "fi" (2)
105 "l" -> 00000026
106 00000026: "le" (1)
107 "n" -> "name" (3)
108
109 Test debug-revlog-stats to exercise walking the store.
110 $ hg debug-revlog-stats --filelog
111 rev-count data-size inl type target
112 1 0 yes file fi
113 1 0 yes file file
114 1 0 yes file filename
115 1 0 yes file other
116
117 Test formatting
118 ---------------
119
120 We can format the docket as JSON
121 $ hg debug::file-index --docket -Tjson
122 [
123 {
124 "garbage_entries": [],
125 "list_file_id": "*", (glob)
126 "list_file_size": 23,
127 "marker": "fileindex-v1",
128 "meta_file_id": "*", (glob)
129 "meta_file_size": 40,
130 "reserved_flags": 0,
131 "tree_file_id": "*", (glob)
132 "tree_file_size": 49,
133 "tree_root_pointer": 11,
134 "tree_unused_bytes": 11
135 }
136 ]
137
138 Test vacuuming the tree file
139 ----------------------------
140
141 Manually vacuum tree
142 $ old_id=$(hg debug::file-index --docket -T '{tree_file_id}')
143 $ hg debug::file-index --vacuum
144 vacuumed tree: 49 bytes => 38 bytes (saved 22.4%)
145 $ new_id=$(hg debug::file-index --docket -T '{tree_file_id}')
146 $ f --size ".hg/store/fileindex-tree.$old_id"
147 .hg/store/fileindex-tree.*: size=49 (glob)
148 $ f --size ".hg/store/fileindex-tree.$new_id"
149 .hg/store/fileindex-tree.*: size=38 (glob)
150 $ hg debug::file-index --vacuum
151 vacuumed tree: 38 bytes => 38 bytes (saved 0.0%)
152
153 Force vacuuming tree during commit
154 $ touch anotherfile
155 $ hg add
156 adding anotherfile
157 $ hg --config devel.fileindex.vacuum-mode=always commit -m 2
158 $ hg debug::file-index --docket -T '{tree_unused_bytes}\n'
159 0
160
161 Test race where vacuuming happens between reading tree ID and opening file.
162 It should successfully read the old tree file (vacuuming shouldn't delete it
163 immediately). Use --path because it causes a lookup in the tree file.
164 $ hg debug::file-index --path anotherfile > $TESTTMP/race-lock.out 2>&1 \
165 > --config devel.sync.fileindex.pre-read-data-files=$TESTTMP/race-lock \
166 > &
167 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/race-lock.waiting
168 $ hg debug::file-index --vacuum
169 vacuumed tree: 43 bytes => 43 bytes (saved 0.0%)
170 $ touch $TESTTMP/race-lock
171 $ wait
172 $ cat $TESTTMP/race-lock.out
173 5: anotherfile
174
175 Vacuum empty tree (no data files)
176 $ hg init $TESTTMP/repoempty --config format.use-fileindex-v1=1
177 $ hg -R $TESTTMP/repoempty debug::file-index --vacuum
178 vacuumed tree: 0 bytes => 0 bytes (saved 0.0%)
179 Vacuum empty tree again (data files exist)
180 $ hg -R $TESTTMP/repoempty debug::file-index --vacuum
181 vacuumed tree: 0 bytes => 0 bytes (saved 0.0%)
182
183 Test cleaning up old files
184 --------------------------
185
186 There should be multiple tree files now
187 $ ls .hg/store/fileindex-tree.*
188 .hg/store/fileindex-tree.* (glob)
189 .hg/store/fileindex-tree.* (glob)
190 .hg/store/fileindex-tree.* (glob)
191 .hg/store/fileindex-tree.* (glob)
192 .hg/store/fileindex-tree.* (glob)
193
194 All except one are garbage
195 $ hg debug::file-index --docket -T '{garbage_entries % "{path}\n"}'
196 fileindex-tree.* (glob)
197 fileindex-tree.* (glob)
198 fileindex-tree.* (glob)
199 fileindex-tree.* (glob)
200
201 Force garbage collection
202 $ hg debug::file-index --gc
203 $ ls .hg/store/fileindex-tree.*
204 .hg/store/fileindex-tree.* (glob)
205 $ hg debug::file-index --docket -T '{garbage_entries % "{path}\n"}'
206
207 Make another tree
208 $ hg debug::file-index --vacuum
209 vacuumed tree: 43 bytes => 43 bytes (saved 0.0%)
210 $ ls .hg/store/fileindex-tree*
211 .hg/store/fileindex-tree.* (glob)
212 .hg/store/fileindex-tree.* (glob)
213 $ hg debug::file-index --docket -T '{garbage_entries % "{path} ttl={ttl}\n"}'
214 fileindex-tree.* ttl=2 (glob)
215 Delete the old tree via automatic gc during after 2 transactions.
216 $ hg ci -qAm "empty" --config ui.allowemptycommit=True --config storage.fileindex.gc-retention-seconds=0
217 $ hg debug::file-index --docket -T '{garbage_entries % "{path} ttl={ttl}\n"}'
218 fileindex-tree.* ttl=1 (glob)
219 $ hg ci -qAm "empty" --config ui.allowemptycommit=True --config storage.fileindex.gc-retention-seconds=0
220 $ hg debug::file-index --docket -T '{garbage_entries % "{path} ttl={ttl}\n"}'
221 $ ls .hg/store/fileindex-tree*
222 .hg/store/fileindex-tree.* (glob)
223
224 Produce garbage entries with fake timestamps
225 Avoid GC while doing so, since we want to test GC once at the end
226 $ max_uint32=4294967295
227 $ disable_gc="--config storage.fileindex.gc-retention-seconds=$max_uint32"
228 Override the first entry's timestamp to zero (Jan 1970)
229 $ hg debug::file-index --vacuum --config devel.fileindex.garbage-timestamp=0 $disable_gc
230 vacuumed tree: 43 bytes => 43 bytes (saved 0.0%)
231 Leave the second entry's timestamp at the current time
232 $ hg debug::file-index --vacuum $disable_gc
233 vacuumed tree: 43 bytes => 43 bytes (saved 0.0%)
234 Override the third entry's timestamp to the max uint32 (Feb 2106)
235 $ hg debug::file-index --vacuum --config devel.fileindex.garbage-timestamp=$max_uint32 $disable_gc
236 vacuumed tree: 43 bytes => 43 bytes (saved 0.0%)
237 $ ls .hg/store/fileindex-tree*
238 .hg/store/fileindex-tree.* (glob)
239 .hg/store/fileindex-tree.* (glob)
240 .hg/store/fileindex-tree.* (glob)
241 .hg/store/fileindex-tree.* (glob)
242 $ hg debug::file-index --docket -T '{garbage_entries % "{path} timestamp={timestamp}\n"}'
243 fileindex-tree.* timestamp=0 (glob)
244 fileindex-tree.* timestamp=* (glob)
245 fileindex-tree.* timestamp=4294967295 (glob)
246 Trigger gc again with a day long retention period
247 $ hg ci -qAm "empty" --config ui.allowemptycommit=True --config storage.fileindex.gc-retention-seconds=86400
248 It only deleted the first entry
249 $ ls .hg/store/fileindex-tree*
250 .hg/store/fileindex-tree.* (glob)
251 .hg/store/fileindex-tree.* (glob)
252 .hg/store/fileindex-tree.* (glob)
253 $ hg debug::file-index --docket -T '{garbage_entries % "{path} timestamp={timestamp}\n"}'
254 fileindex-tree.* timestamp=* (glob)
255 fileindex-tree.* timestamp=4294967295 (glob)
256
257 $ cd ..
258
259 Test removing paths with debugstrip
260 -----------------------------------
261
262 $ hg init repostrip --config format.use-fileindex-v1=1
263 $ cd repostrip
264
265 Start with one file
266 $ touch file0
267 $ hg ci -qAm 0
268 $ hg debug::file-index
269 1: file0
270
271 Strip to remove the file
272 $ hg debugstrip -q -r 0
273 $ hg debug::file-index
274
275 Add the file back
276 $ touch file0
277 $ hg ci -qAm 0
278 $ hg debug::file-index
279 1: file0
280
281 Add another file
282 $ touch file1
283 $ hg ci -qAm 1
284 $ hg debug::file-index
285 1: file0
286 2: file1
287
288 Strip to remove only the second file
289 $ hg debugstrip -q -r 1
290 $ hg debug::file-index
291 1: file0
292
293 Add two more files
294 $ touch file1
295 $ hg ci -qAm 1
296 $ hg up -q 0
297 $ touch file2
298 $ hg ci -qAm 2
299 $ hg debug::file-index
300 1: file0
301 2: file1
302 3: file2
303
304 Strip to remove the middle file
305 $ hg debugstrip -q -r 1
306 $ hg debug::file-index
307 1: file0
308 2: file2
309
310 Strip to remove the remaining files
311 $ hg debugstrip -q -r 0
312 $ hg debug::file-index
313 $ hg debug::file-index --docket -T 'size={tree_file_size}, root={tree_root_pointer}\n'
314 size=0, root=0
315
316 $ cd ..
317
318 Test removing paths with tracked
319 --------------------------------
320
321 $ cp $HGRCPATH hgrc.backup
322 $ . "$TESTDIR/narrow-library.sh"
323
324 Create source repository
325 $ hg init repofull --config format.exp-use-fileindex-v1=enable-unstable-format-and-corrupt-my-data
326 $ cd repofull
327 $ touch file0 file1
328 $ hg ci -qAm 0
329 $ cd ..
330
331 Set up a narrow clone
332 $ hg clone -q repofull repotracked --narrow --include "" --config format.use-fileindex-v1=1
333 $ cd repotracked
334 $ hg debug::file-index
335 1: file0
336 2: file1
337
338 Test excluding file0
339 $ hg tracked -q --addexclude file0
340 $ hg debug::file-index
341 1: file1
342
343 Test excluding file1 too
344 $ hg tracked -q --addexclude file1
345 $ hg debug::file-index
346
347 Test stripping revision that touched excluded files
348 $ hg debugstrip -q -r 0
349 $ hg debug::file-index
350
351 $ cd ..
352 $ mv hgrc.backup $HGRCPATH
353
354 Test interaction with hooks
355 ---------------------------
356
357 Access file index in pretxnclose hook
358 $ hg init repohook --config format.use-fileindex-v1=1
359 $ cd repohook
360 $ cat > .hg/hgrc <<EOF
361 > [hooks]
362 > pretxnclose = hg debug::file-index
363 > EOF
364 $ touch file
365 $ hg add file
366 $ hg commit -m 0 --verbose
367 committing files:
368 file
369 committing manifest
370 committing changelog
371 running hook pretxnclose: hg debug::file-index
372 1: file
373 committed changeset 0:* (glob)
374
375 $ cd ..
376
377 Test transaction failure and rollback
378 -------------------------------------
379
380 We test all combinations of these cases:
381
382 Rollback
383 - manual via hg rollback
384 - automatic when transaction fails
385 - with hg recover when transaction is abandoned
386 Vacuuming
387 - no (same tree file)
388 - yes (new tree file)
389
390 There are a few important things here:
391 1. Delete old files at some point (see "Test cleaning up old files" above).
392 2. But leave them around long enough so we can rollback after a vacuum.
393 3. And in that case, also clean up the file we rolled back from.
394
395 $ hg init repotxn --config format.use-fileindex-v1=1
396 $ cd repotxn
397
398 Retention is based on time and TTL (a transaction countdown). Disable the
399 time-based retention to show that TTL alone is sufficient for rollback/recovery.
400 $ cat > .hg/hgrc <<EOF
401 > [storage]
402 > fileindex.gc-retention-seconds=0
403 > EOF
404
405 Manul rollback, new file index (initial commit)
406 $ touch file
407 $ hg commit -qAm 0
408 $ hg rollback
409 repository tip rolled back to revision -1 (undo commit)
410 working directory now based on revision -1
411 $ hg debug::file-index
412 Rolling back removes the file index files.
413 $ ls .hg/store | grep fileindex
414 [1]
415
416 Set up the following tests so we are adding to a nonempty file index
417 $ hg commit -qAm 0 --config devel.fileindex.vacuum-mode=never
418 $ touch file2
419 $ original_id=$(hg debug::file-index --docket -T '{tree_file_id}')
420 $ hg debug::file-index
421 1: file
422
423 Manual rollback, same file
424 $ hg commit -qAm 1 --config devel.fileindex.vacuum-mode=never
425 $ hg rollback
426 repository tip rolled back to revision 0 (undo commit)
427 working directory now based on revision 0
428 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
429 $ hg debug::file-index
430 1: file
431 $ ls .hg/store/fileindex-*
432 .hg/store/fileindex-list.* (glob)
433 .hg/store/fileindex-meta.* (glob)
434 .hg/store/fileindex-tree.* (glob)
435
436 Manual rollback, new file
437 $ hg commit -qAm 1 --config devel.fileindex.vacuum-mode=always
438 $ hg rollback
439 repository tip rolled back to revision 0 (undo commit)
440 working directory now based on revision 0
441 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
442 $ hg debug::file-index
443 1: file
444 $ ls .hg/store/fileindex-*
445 .hg/store/fileindex-list.* (glob)
446 .hg/store/fileindex-meta.* (glob)
447 .hg/store/fileindex-tree.* (glob)
448
449 Abort transaction, same file
450 $ hg commit -qAm 1 --config devel.debug.abort-transaction=abort-post-finalize --config devel.fileindex.vacuum-mode=never
451 transaction abort!
452 rollback completed
453 abort: requested abort-post-finalize
454 [255]
455 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
456 $ hg debug::file-index
457 1: file
458 $ ls .hg/store/fileindex-*
459 .hg/store/fileindex-list.* (glob)
460 .hg/store/fileindex-meta.* (glob)
461 .hg/store/fileindex-tree.* (glob)
462
463 Abort transaction, new file
464 $ hg commit -qAm 1 --config devel.debug.abort-transaction=abort-post-finalize --config devel.fileindex.vacuum-mode=always
465 transaction abort!
466 rollback completed
467 abort: requested abort-post-finalize
468 [255]
469 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
470 $ hg debug::file-index
471 1: file
472 $ ls .hg/store/fileindex-*
473 .hg/store/fileindex-list.* (glob)
474 .hg/store/fileindex-meta.* (glob)
475 .hg/store/fileindex-tree.* (glob)
476
477 Recover transaction, same file
478 $ hg commit -qAm 1 --config devel.debug.abort-transaction=kill-9-post-finalize --config devel.fileindex.vacuum-mode=never || echo exit=$?
479 *Killed* (glob) (no-chg !)
480 exit=137 (no-chg !)
481 exit=255 (chg !)
482 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
483 $ hg debug::file-index
484 1: file
485 2: file2
486 $ hg recover
487 rolling back interrupted transaction
488 (verify step skipped, run `hg verify` to check your repository content)
489 $ test "$original_id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
490 $ hg debug::file-index
491 1: file
492 $ ls .hg/store/fileindex-*
493 .hg/store/fileindex-list.* (glob)
494 .hg/store/fileindex-meta.* (glob)
495 .hg/store/fileindex-tree.* (glob)
496
497 Recover transaction, new file
498 $ id=$(hg debug::file-index --docket -T '{tree_file_id}')
499 $ hg commit -qAm 1 --config devel.debug.abort-transaction=kill-9-post-finalize --config devel.fileindex.vacuum-mode=always || echo exit=$?
500 *Killed* (glob) (no-chg !)
501 exit=137 (no-chg !)
502 exit=255 (chg !)
503 $ test "$id" != "$(hg debug::file-index --docket -T '{tree_file_id}')"
504 $ hg debug::file-index
505 1: file
506 2: file2
507 $ hg recover
508 rolling back interrupted transaction
509 (verify step skipped, run `hg verify` to check your repository content)
510 $ test "$id" = "$(hg debug::file-index --docket -T '{tree_file_id}')"
511 $ hg debug::file-index
512 1: file
513 $ ls .hg/store/fileindex-*
514 .hg/store/fileindex-list.* (glob)
515 .hg/store/fileindex-meta.* (glob)
516 .hg/store/fileindex-tree.* (glob)
517
518 $ cd ..
519
520 Test upgrading from fncache to fileindex and back
521 -------------------------------------------------
522
523 Create an empty repo with fncache
524 $ hg init repoupgrade --config format.use-fileindex-v1=0
525 $ cd repoupgrade
526 $ hg debugformat fileindex
527 format-variant repo
528 fileindex-v1: no
529 $ hg debug::file-index
530 abort: this repository does not have a file index
531 [20]
532
533 Removing fncache is not allowed if you aren't upgrading to file index
534 $ hg debugupgrade --config format.usefncache=0 --config format.use-fileindex-v1=0 --run
535 abort: cannot upgrade repository; requirement would be removed: fncache
536 [255]
537
538 Upgrade empty repo from fncache to fileindex
539 $ hg debugupgrade --config format.use-fileindex-v1=1 --run
540 note: selecting all-filelogs for processing to change: dotencode
541 note: selecting all-manifestlogs for processing to change: fncache
542 note: selecting changelog for processing to change: fncache
543
544 upgrade will perform the following actions:
545
546 requirements
547 preserved: * (glob)
548 removed: dotencode, fncache
549 added: fileindex-v1
550
551 fileindex-v1
552 transactions that add files will be faster in large repos
553
554 processed revlogs:
555 - all-filelogs
556 - changelog
557 - manifest
558
559 beginning upgrade...
560 repository locked and read-only
561 creating temporary repository to stage upgraded data: $TESTTMP/repoupgrade/.hg/upgrade.* (glob)
562 (it is safe to interrupt this process any time before data migration completes)
563 upgrading from fncache to fileindex-v1
564 replaced files will be backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
565 removing temporary repository $TESTTMP/repoupgrade/.hg/upgrade.* (glob)
566 $ hg debug::file-index
567
568 You can't roll back the fast path upgrade
569 $ hg rollback
570 no rollback information available
571 [1]
572
573 Removing file index is not allowed if you aren't downgrading to fncache
574 $ hg debugupgrade --config format.usefncache=0 --config format.use-fileindex-v1=0 --run
575 abort: cannot upgrade repository; requirement would be removed: fileindex-v1
576 [255]
577
578 Downgrade empty repo to fncache
579 $ hg debugupgrade --config format.use-fileindex-v1=0 --run
580 note: selecting all-filelogs for processing to change: dotencode
581 note: selecting all-manifestlogs for processing to change: fncache
582 note: selecting changelog for processing to change: fncache
583
584 upgrade will perform the following actions:
585
586 requirements
587 preserved: * (glob)
588 removed: fileindex-v1
589 added: dotencode, fncache
590
591 fncache
592 repository will be more resilient to storing certain paths and performance of certain operations should be improved
593
594 dotencode
595 repository will be better able to store files beginning with a space or period
596
597 processed revlogs:
598 - all-filelogs
599 - changelog
600 - manifest
601
602 beginning upgrade...
603 repository locked and read-only
604 creating temporary repository to stage upgraded data: $TESTTMP/repoupgrade/.hg/upgrade.* (glob)
605 (it is safe to interrupt this process any time before data migration completes)
606 copying requires
607 data fully upgraded in a temporary repository
608 marking source repository as being upgraded; clients will be unable to read from repository
609 starting in-place swap of repository data
610 replaced files will be backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
611 replacing store...
612 store replacement complete; repository was inconsistent for *s (glob)
613 finalizing requirements file and making repository readable again
614 removing temporary repository $TESTTMP/repoupgrade/.hg/upgrade.* (glob)
615 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
616 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
617 $ hg debug::file-index
618 abort: this repository does not have a file index
619 [20]
620
621 Add a file, then upgrade to fileindex
622 $ touch f1
623 $ hg add f1
624 $ hg ci -m 0
625 $ cat .hg/store/fncache | sort
626 data/f1.i
627 $ hg debugupgrade --config format.use-fileindex-v1=1 --run > /dev/null
628 $ test -f .hg/store/fncache
629 [1]
630 $ hg debug::file-index
631 1: f1
632
633 Add another file, then downgrade to fncache
634 $ touch f2
635 $ hg add f2
636 $ hg ci -m 1
637 $ hg debugupgrade --config format.use-fileindex-v1=0 --run > /dev/null
638 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
639 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
640 $ cat .hg/store/fncache | sort
641 data/f1.i
642 data/f2.i
643 $ hg debug::file-index
644 abort: this repository does not have a file index
645 [20]
646
647 Finally, upgrade back to fileindex
648 $ hg debugupgrade --config format.use-fileindex-v1=1 --run > /dev/null
649 $ hg debug::file-index
650 1: f1
651 2: f2
652
653 Test an upgrade, preserving fileindex, that touches filelogs (plain encoding)
654 $ hg debugupgrade --config format.use-fileindex-v1=1 --config format.exp-use-very-fragile-and-unsafe-plain-store-encoding=1 --run > /dev/null
655 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
656 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
657 $ hg debugupgrade --config format.use-fileindex-v1=1 --run > /dev/null
658 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
659 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
660
661 Test an upgrade, preserving fileindex, that does not touch filelogs (exp-changelog-v2)
662 $ hg debugupgrade --config format.use-fileindex-v1=1 --config format.exp-use-changelog-v2=enable-unstable-format-and-corrupt-my-data --run > /dev/null
663 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
664 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
665 $ hg debugupgrade --config format.use-fileindex-v1=1 --run > /dev/null
666 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
667 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
668
669 Downgrade to fncache with plain encoding
670 $ hg debugupgrade --config format.use-fileindex-v1=0 --config format.dotencode=0 --config format.exp-use-very-fragile-and-unsafe-plain-store-encoding=1 --run > /dev/null
671 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
672 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
673
674 Upgrade to file index, preserving plain encoding
675 $ hg debugupgrade --config format.use-fileindex-v1=1 --config format.exp-use-very-fragile-and-unsafe-plain-store-encoding=1 --run > /dev/null
676
677 Downgrade to fncache with neither dotencode nor plain encoding
678 $ hg debugupgrade --config format.use-fileindex-v1=0 --config format.dotencode=0 --config format.exp-use-very-fragile-and-unsafe-plain-store-encoding=0 --run > /dev/null
679 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
680 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
681
682 Upgrade directly from non-dotencode fncache to file index (uses slow path)
683 $ hg debugupgrade --config format.use-fileindex-v1=1 --config format.exp-use-very-fragile-and-unsafe-plain-store-encoding=0 --run > /dev/null
684 copy of old repository backed up at $TESTTMP/repoupgrade/.hg/upgradebackup.* (glob)
685 the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
686
687 $ cd ..
688
689 Test compatiblity of Python and Rust implementations
690 ----------------------------------------------------
691
692 #if rust
693
694 $ hg init repocompat --config format.use-fileindex-v1=1
695 $ cd repocompat
696 $ cat << EOF >> .hg/hgrc
697 > [storage]
698 > fileindex.slow-path=allow
699 > EOF
700
701 Add files with Python, read with Rust
702 $ touch file0
703 $ HGMODULEPOLICY=py hg commit -qAm 0
704 $ hg debug::file-index
705 1: file0
706 $ hg debug::file-index --docket
707 marker: fileindex-v1
708 list_file_size: 6
709 meta_file_size: 16
710 tree_file_size: 11
711 list_file_id: * (glob)
712 meta_file_id: * (glob)
713 tree_file_id: * (glob)
714 tree_root_pointer: 0
715 tree_unused_bytes: 0
716 reserved_flags: 0
717 garbage_entries: 0
718 $ hg debug::file-index --tree
719 00000000: "" (0)
720 "f" -> "file0" (1)
721
722 Vacuum with Python, GC with Rust
723 $ HGMODULEPOLICY=py hg debug::file-index --vacuum
724 vacuumed tree: 11 bytes => 11 bytes (saved 0.0%)
725 $ hg debug::file-index --docket -T '{garbage_entries % "{path}\n"}'
726 fileindex-tree.* (glob)
727 $ ls .hg/store/fileindex-tree.*
728 .hg/store/fileindex-tree.* (glob)
729 .hg/store/fileindex-tree.* (glob)
730 $ hg debug::file-index --gc
731 $ ls .hg/store/fileindex-tree.*
732 .hg/store/fileindex-tree.* (glob)
733
734 Add files with Rust, read with Python
735 $ touch file1
736 $ hg commit -qAm 1
737 $ HGMODULEPOLICY=py hg debug::file-index
738 1: file0
739 2: file1
740 $ HGMODULEPOLICY=py hg debug::file-index --docket
741 marker: fileindex-v1
742 list_file_size: 12
743 meta_file_size: 24
744 tree_file_size: 38
745 list_file_id: * (glob)
746 meta_file_id: * (glob)
747 tree_file_id: * (glob)
748 tree_root_pointer: 11
749 tree_unused_bytes: 11
750 reserved_flags: 0
751 garbage_entries: 0
752 $ HGMODULEPOLICY=py hg debug::file-index --tree
753 0000000b: "" (0)
754 "f" -> 00000016
755 00000016: "file" (2)
756 "0" -> "0" (1)
757 "1" -> "1" (2)
758
759 Vacuum with Rust, GC with Python
760 $ hg debug::file-index --vacuum
761 vacuumed tree: 38 bytes => 27 bytes (saved 28.9%)
762 $ HGMODULEPOLICY=py hg debug::file-index --docket -T '{garbage_entries % "{path}\n"}'
763 fileindex-tree.* (glob)
764 $ ls .hg/store/fileindex-tree.*
765 .hg/store/fileindex-tree.* (glob)
766 .hg/store/fileindex-tree.* (glob)
767 $ HGMODULEPOLICY=py hg debug::file-index --gc
768 $ ls .hg/store/fileindex-tree.*
769 .hg/store/fileindex-tree.* (glob)
770
771 $ cd ..
772
773 #endif
774
775 Test various prefix tree structures
776 -----------------------------------
777
778 $ hg init repotree --config format.use-fileindex-v1=1
779 $ cd repotree
780
781 Paths with distinct prefix
782 $ touch foo bar
783 $ hg commit -qAm 0
784 $ hg debug::file-index --tree
785 00000000: "" (0)
786 "b" -> "bar" (1)
787 "f" -> "foo" (2)
788 $ hg debug::file-index --path foo
789 2: foo
790 $ hg debug::file-index --path bar
791 1: bar
792 $ hg debug::file-index --path baz
793 abort: path baz is not in the file index
794 [10]
795
796 Paths with a common prefix
797 $ touch fun
798 $ hg commit -qAm 1
799 $ hg debug::file-index --tree
800 00000010: "" (0)
801 "b" -> "bar" (1)
802 "f" -> 00000020
803 00000020: "f" (3)
804 "o" -> "oo" (2)
805 "u" -> "un" (3)
806 $ hg debug::file-index --path foo
807 2: foo
808 $ hg debug::file-index --path fun
809 3: fun
810 $ hg debug::file-index --path f
811 abort: path f is not in the file index
812 [10]
813
814 Paths where one is a prefix of the other
815 $ touch food
816 $ hg commit -qAm 2
817 $ hg debug::file-index --tree
818 00000030: "" (0)
819 "b" -> "bar" (1)
820 "f" -> 00000040
821 00000040: "f" (3)
822 "o" -> 00000050
823 "u" -> "un" (3)
824 00000050: "oo" (2)
825 "d" -> "d" (4)
826 $ hg debug::file-index --path foo
827 2: foo
828 $ hg debug::file-index --path food
829 4: food
830 $ hg debug::file-index --path fo
831 abort: path fo is not in the file index
832 [10]
833 $ hg debug::file-index --path foods
834 abort: path foods is not in the file index
835 [10]
836
837 $ cd ..
838
839 Test long paths
840 ---------------
841
842 $ hg init repolong --config format.use-fileindex-v1=1
843 $ cd repolong
844 $ path=$("$PYTHON" -c 'print("long/" * 99 + "f.txt")')
845 $ echo ${#path}
846 500
847 >>> import os
848 >>> os.makedirs(os.path.dirname("$path"))
849 >>> open("$path", 'wb').close()
850 $ hg commit -qAm 0
851 $ hg debug::file-index --path $path | sed "s|$path|\$path|"
852 1: $path
853
854 $ cd ..