Debian Codegraph @

tests/test-hardlinks.t

raw
1 #require hardlink
2
3 #testcases fncache fileindex
4
5 #if fileindex
6 $ cat >> $HGRCPATH << EOF
7 > [format]
8 > use-fileindex-v1=yes
9 > EOF
10 #else
11 $ cat >> $HGRCPATH << EOF
12 > [format]
13 > use-fileindex-v1=no
14 > EOF
15 #endif
16
17 #if fileindex no-rust
18 $ cat >> $HGRCPATH << EOF
19 > [storage]
20 > fileindex.slow-path=allow
21 > EOF
22 #endif
23
24 $ cat > nlinks.py <<EOF
25 > import sys
26 > from mercurial import pycompat, util
27 > for f in sorted(sys.stdin.readlines()):
28 > f = f[:-1]
29 > print(util.nlinks(pycompat.fsencode(f)), f)
30 > EOF
31
32 $ nlinksdir()
33 > {
34 > find "$@" -type f | "$PYTHON" $TESTTMP/nlinks.py
35 > }
36
37 Some implementations of cp can't create hardlinks (replaces 'cp -al' on Linux):
38
39 $ cat > linkcp.py <<EOF
40 > import sys
41 > from mercurial import pycompat, util
42 > util.copyfiles(pycompat.fsencode(sys.argv[1]),
43 > pycompat.fsencode(sys.argv[2]), hardlink=True)
44 > EOF
45
46 $ linkcp()
47 > {
48 > "$PYTHON" $TESTTMP/linkcp.py $1 $2
49 > }
50
51 Prepare repo r1:
52
53 $ hg init r1
54 $ cd r1
55
56 $ echo c1 > f1
57 $ hg add f1
58 $ hg ci -m0
59
60 $ mkdir d1
61 $ cd d1
62 $ echo c2 > f2
63 $ hg add f2
64 $ hg ci -m1
65 $ cd ../..
66
67 $ nlinksdir r1/.hg/store
68 1 r1/.hg/store/00changelog-b870a51b.nd (rust !)
69 1 r1/.hg/store/00changelog.d
70 1 r1/.hg/store/00changelog.i
71 1 r1/.hg/store/00changelog.n (rust !)
72 1 r1/.hg/store/00manifest.i
73 1 r1/.hg/store/data/d1/f2.i
74 1 r1/.hg/store/data/f1.i
75 1 r1/.hg/store/fncache (fncache !)
76 1 r1/.hg/store/fileindex (fileindex !)
77 1 r1/.hg/store/fileindex-list.* (glob) (fileindex !)
78 1 r1/.hg/store/fileindex-meta.* (glob) (fileindex !)
79 1 r1/.hg/store/fileindex-tree.* (glob) (fileindex !)
80 1 r1/.hg/store/phaseroots
81 1 r1/.hg/store/requires
82 1 r1/.hg/store/undo
83 1 r1/.hg/store/undo.backup.00changelog.n.bck (rust !)
84 1 r1/.hg/store/undo.backup.fncache.bck (fncache !)
85 1 r1/.hg/store/undo.backup.fileindex.bck (fileindex !)
86 1 r1/.hg/store/undo.backupfiles
87
88
89 Create hardlinked clone r2:
90
91 $ hg clone -U --debug r1 r2 --config progress.debug=true
92 linking: 1/8 files (12.50%) (no-rust !)
93 linking: 2/8 files (25.00%) (no-rust !)
94 linking: 3/8 files (37.50%) (no-rust !)
95 linking: 4/8 files (50.00%) (no-rust !)
96 linking: 5/8 files (62.50%) (no-rust !)
97 linking: 6/8 files (75.00%) (no-rust !)
98 linking: 7/8 files (87.50%) (no-rust !)
99 linking: 8/8 files (100.00%) (no-rust !)
100 linked 8 files (no-rust !)
101 linking: 1/10 files (10.00%) (rust !)
102 linking: 2/10 files (20.00%) (rust !)
103 linking: 3/10 files (30.00%) (rust !)
104 linking: 4/10 files (40.00%) (rust !)
105 linking: 5/10 files (50.00%) (rust !)
106 linking: 6/10 files (60.00%) (rust !)
107 linking: 7/10 files (70.00%) (rust !)
108 linking: 8/10 files (80.00%) (rust !)
109 linking: 9/10 files (90.00%) (rust !)
110 linking: 10/10 files (100.00%) (rust !)
111 linked 10 files (rust !)
112 updating the branch cache
113
114 Create non-hardlinked clone r3:
115
116 $ hg clone --pull r1 r3
117 requesting all changes
118 adding changesets
119 adding manifests
120 adding file changes
121 added 2 changesets with 2 changes to 2 files
122 new changesets 40d85e9847f2:7069c422939c
123 updating to branch default
124 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
125
126
127 Repos r1 and r2 should now contain hardlinked files:
128
129 $ nlinksdir r1/.hg/store
130 1 r1/.hg/store/00changelog-b870a51b.nd (rust !)
131 2 r1/.hg/store/00changelog.d
132 2 r1/.hg/store/00changelog.i
133 1 r1/.hg/store/00changelog.n (rust !)
134 2 r1/.hg/store/00manifest.i
135 2 r1/.hg/store/data/d1/f2.i
136 2 r1/.hg/store/data/f1.i
137 1 r1/.hg/store/fncache (fncache !)
138 1 r1/.hg/store/fileindex (fileindex !)
139 1 r1/.hg/store/fileindex-list.* (glob) (fileindex !)
140 1 r1/.hg/store/fileindex-meta.* (glob) (fileindex !)
141 1 r1/.hg/store/fileindex-tree.* (glob) (fileindex !)
142 1 r1/.hg/store/phaseroots
143 1 r1/.hg/store/requires
144 1 r1/.hg/store/undo
145 1 r1/.hg/store/undo.backup.00changelog.n.bck (rust !)
146 1 r1/.hg/store/undo.backup.fncache.bck (fncache !)
147 1 r1/.hg/store/undo.backup.fileindex.bck (fileindex !)
148 1 r1/.hg/store/undo.backupfiles
149
150 $ nlinksdir r2/.hg/store
151 1 r2/.hg/store/00changelog-b870a51b.nd (rust !)
152 2 r2/.hg/store/00changelog.d
153 2 r2/.hg/store/00changelog.i
154 1 r2/.hg/store/00changelog.n (rust !)
155 2 r2/.hg/store/00manifest.i
156 2 r2/.hg/store/data/d1/f2.i
157 2 r2/.hg/store/data/f1.i
158 1 r2/.hg/store/fncache (fncache !)
159 1 r2/.hg/store/fileindex (fileindex !)
160 1 r2/.hg/store/fileindex-list.* (glob) (fileindex !)
161 1 r2/.hg/store/fileindex-meta.* (glob) (fileindex !)
162 1 r2/.hg/store/fileindex-tree.* (glob) (fileindex !)
163 1 r2/.hg/store/requires
164
165 Repo r3 should not be hardlinked:
166
167 $ nlinksdir r3/.hg/store
168 1 r3/.hg/store/00changelog-88698448.nd (rust !)
169 1 r3/.hg/store/00changelog.d
170 1 r3/.hg/store/00changelog.i
171 1 r3/.hg/store/00changelog.n (rust !)
172 1 r3/.hg/store/00manifest.i
173 1 r3/.hg/store/data/d1/f2.i
174 1 r3/.hg/store/data/f1.i
175 1 r3/.hg/store/fncache (fncache !)
176 1 r3/.hg/store/fileindex (fileindex !)
177 1 r3/.hg/store/fileindex-list.* (glob) (fileindex !)
178 1 r3/.hg/store/fileindex-meta.* (glob) (fileindex !)
179 1 r3/.hg/store/fileindex-tree.* (glob) (fileindex !)
180 1 r3/.hg/store/phaseroots
181 1 r3/.hg/store/requires
182 1 r3/.hg/store/undo
183 1 r3/.hg/store/undo.backupfiles
184
185
186 Create a non-inlined filelog in r3:
187
188 $ cd r3/d1
189 >>> f = open('data1', 'wb')
190 >>> for x in range(10000):
191 ... f.write(b"%d\n" % x) and None
192 >>> f.close()
193 $ for j in 0 1 2 3 4 5 6 7 8 9; do
194 > cat data1 >> f2
195 > hg commit -m$j
196 > done
197 $ cd ../..
198
199 $ nlinksdir r3/.hg/store
200 1 r3/.hg/store/00changelog-ea337809.nd (rust !)
201 1 r3/.hg/store/00changelog.d
202 1 r3/.hg/store/00changelog.i
203 1 r3/.hg/store/00changelog.n (rust !)
204 1 r3/.hg/store/00manifest.i
205 1 r3/.hg/store/data/d1/f2.d
206 1 r3/.hg/store/data/d1/f2.i
207 1 r3/.hg/store/data/f1.i
208 1 r3/.hg/store/fncache (fncache !)
209 1 r3/.hg/store/fileindex (fileindex !)
210 1 r3/.hg/store/fileindex-list.* (glob) (fileindex !)
211 1 r3/.hg/store/fileindex-meta.* (glob) (fileindex !)
212 1 r3/.hg/store/fileindex-tree.* (glob) (fileindex !)
213 1 r3/.hg/store/phaseroots
214 1 r3/.hg/store/requires
215 1 r3/.hg/store/undo
216 1 r3/.hg/store/undo.backup.00changelog.n.bck (rust !)
217 1 r3/.hg/store/undo.backupfiles
218
219 Push to repo r1 should break up most hardlinks in r2:
220
221 $ hg -R r2 verify -q
222
223 $ cd r3
224 $ hg push
225 pushing to $TESTTMP/r1
226 searching for changes
227 adding changesets
228 adding manifests
229 adding file changes
230 added 10 changesets with 10 changes to 1 files
231
232 $ cd ..
233
234 $ nlinksdir r2/.hg/store
235 1 r2/.hg/store/00changelog-b870a51b.nd (rust !)
236 1 r2/.hg/store/00changelog.d
237 1 r2/.hg/store/00changelog.i
238 1 r2/.hg/store/00changelog.n (rust !)
239 1 r2/.hg/store/00manifest.i
240 1 r2/.hg/store/data/d1/f2.i
241 2 r2/.hg/store/data/f1.i
242 1 r2/\.hg/store/fncache (re) (fncache !)
243 1 r2/.hg/store/fileindex (fileindex !)
244 1 r2/.hg/store/fileindex-list.* (glob) (fileindex !)
245 1 r2/.hg/store/fileindex-meta.* (glob) (fileindex !)
246 1 r2/.hg/store/fileindex-tree.* (glob) (fileindex !)
247 1 r2/.hg/store/requires
248
249 $ hg -R r2 verify -q
250
251 $ cd r1
252 $ hg up
253 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
254
255 Committing a change to f1 in r1 must break up hardlink f1.i in r2:
256
257 $ echo c1c1 >> f1
258 $ hg ci -m00
259 $ cd ..
260
261 $ nlinksdir r2/.hg/store
262 1 r2/.hg/store/00changelog-b870a51b.nd (rust !)
263 1 r2/.hg/store/00changelog.d
264 1 r2/.hg/store/00changelog.i
265 1 r2/.hg/store/00changelog.n (rust !)
266 1 r2/.hg/store/00manifest.i
267 1 r2/.hg/store/data/d1/f2.i
268 1 r2/.hg/store/data/f1.i
269 1 r2/.hg/store/fncache (fncache !)
270 1 r2/.hg/store/fileindex (fileindex !)
271 1 r2/.hg/store/fileindex-list.* (glob) (fileindex !)
272 1 r2/.hg/store/fileindex-meta.* (glob) (fileindex !)
273 1 r2/.hg/store/fileindex-tree.* (glob) (fileindex !)
274 1 r2/.hg/store/requires
275
276 Create a file which exec permissions we will change
277 $ cd r3
278 $ echo "echo hello world" > f3
279 $ hg add f3
280 $ hg ci -mf3
281 $ cd ..
282
283 $ cd r3
284 $ hg tip --template '{rev}:{node|short}\n'
285 12:d3b77733a28a
286 $ echo bla > f1
287 $ chmod +x f3
288 $ hg ci -m1
289 $ cd ..
290
291 Create hardlinked copy r4 of r3 (on Linux, we would call 'cp -al'):
292
293 $ linkcp r3 r4
294
295 'checklink' is produced by hardlinking a symlink, which is undefined whether
296 the symlink should be followed or not. It does behave differently on Linux and
297 BSD. Just remove it so the test pass on both platforms.
298
299 $ rm -f r4/.hg/wcache/checklink
300
301 r4 has hardlinks in the working dir (not just inside .hg):
302
303 $ nlinksdir r4
304 2 r4/.hg/00changelog.i
305 [24] r4/.hg/branch (re)
306 2 r4/.hg/cache/branch2-base
307 2 r4/.hg/cache/branch2-served
308 2 r4/.hg/cache/rbc-names-v2
309 2 r4/.hg/cache/rbc-revs-v2
310 2 r4/.hg/cache/tags2
311 2 r4/.hg/cache/tags2-served
312 2 r4/.hg/dirstate
313 2 r4/.hg/fsmonitor.state (fsmonitor !)
314 2 r4/.hg/hgrc
315 2 r4/.hg/last-message.txt
316 2 r4/.hg/requires
317 2 r4/.hg/store/00changelog-7f2eb713.nd (rust !)
318 2 r4/.hg/store/00changelog.d
319 2 r4/.hg/store/00changelog.i
320 2 r4/.hg/store/00changelog.n (rust !)
321 2 r4/.hg/store/00manifest.i
322 2 r4/.hg/store/data/d1/f2.d
323 2 r4/.hg/store/data/d1/f2.i
324 2 r4/.hg/store/data/f1.i
325 2 r4/.hg/store/data/f3.i
326 2 r4/.hg/store/fncache (fncache !)
327 2 r4/.hg/store/fileindex (fileindex !)
328 2 r4/.hg/store/fileindex-list.* (glob) (fileindex !)
329 2 r4/.hg/store/fileindex-meta.* (glob) (fileindex !)
330 2 r4/.hg/store/fileindex-tree.* (glob) (fileindex !)
331 2 r4/.hg/store/phaseroots
332 2 r4/.hg/store/requires
333 2 r4/.hg/store/undo
334 2 r4/.hg/store/undo.backup.00changelog.n.bck (rust !)
335 2 r4/.hg/store/undo.backupfiles
336 [24] r4/.hg/undo.backup.branch.bck (re)
337 2 r4/\.hg/undo\.backup\.dirstate.bck (re)
338 2 r4/.hg/undo.desc
339 2 r4/.hg/wcache/checkisexec (execbit !)
340 2 r4/.hg/wcache/checklink-target (symlink !)
341 2 r4/.hg/wcache/checknoexec (execbit !)
342 2 r4/.hg/wcache/manifestfulltextcache
343 2 r4/d1/data1
344 2 r4/d1/f2
345 2 r4/f1
346 2 r4/f3
347
348 Update back to revision 12 in r4 should break hardlink of file f1 and f3:
349 #if hardlink-whitelisted
350 $ nlinksdir r4/.hg/undo.backup.dirstate.bck r4/.hg/dirstate
351 2 r4/.hg/dirstate
352 2 r4/.hg/undo.backup.dirstate.bck
353 #endif
354
355
356 $ hg -R r4 up 12
357 2 files updated, 0 files merged, 0 files removed, 0 files unresolved (execbit !)
358 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (no-execbit !)
359
360 $ nlinksdir r4
361 2 r4/.hg/00changelog.i
362 1 r4/.hg/branch
363 2 r4/.hg/cache/branch2-base
364 2 r4/.hg/cache/branch2-served
365 2 r4/.hg/cache/rbc-names-v2
366 2 r4/.hg/cache/rbc-revs-v2
367 2 r4/.hg/cache/tags2
368 2 r4/.hg/cache/tags2-served
369 1 r4/.hg/dirstate
370 1 r4/.hg/fsmonitor.state (fsmonitor !)
371 2 r4/.hg/hgrc
372 2 r4/.hg/last-message.txt
373 2 r4/.hg/requires
374 2 r4/.hg/store/00changelog-7f2eb713.nd (rust !)
375 2 r4/.hg/store/00changelog.d
376 2 r4/.hg/store/00changelog.i
377 2 r4/.hg/store/00changelog.n (rust !)
378 2 r4/.hg/store/00manifest.i
379 2 r4/.hg/store/data/d1/f2.d
380 2 r4/.hg/store/data/d1/f2.i
381 2 r4/.hg/store/data/f1.i
382 2 r4/.hg/store/data/f3.i
383 2 r4/.hg/store/fncache (fncache !)
384 2 r4/.hg/store/fileindex (fileindex !)
385 2 r4/.hg/store/fileindex-list.* (glob) (fileindex !)
386 2 r4/.hg/store/fileindex-meta.* (glob) (fileindex !)
387 2 r4/.hg/store/fileindex-tree.* (glob) (fileindex !)
388 2 r4/.hg/store/phaseroots
389 2 r4/.hg/store/requires
390 2 r4/.hg/store/undo
391 2 r4/.hg/store/undo.backup.00changelog.n.bck (rust !)
392 2 r4/.hg/store/undo.backupfiles
393 [23] r4/.hg/undo.backup.branch.bck (re)
394 2 r4/\.hg/undo\.backup\.dirstate.bck (re)
395 2 r4/.hg/undo.desc
396 2 r4/.hg/wcache/checkisexec (execbit !)
397 2 r4/.hg/wcache/checklink-target (symlink !)
398 2 r4/.hg/wcache/checknoexec (execbit !)
399 1 r4/.hg/wcache/manifestfulltextcache
400 2 r4/d1/data1
401 2 r4/d1/f2
402 1 r4/f1
403 1 r4/f3 (execbit !)
404 2 r4/f3 (no-execbit !)
405
406 #if hardlink-whitelisted
407 $ nlinksdir r4/.hg/undo.backup.dirstate.bck r4/.hg/dirstate
408 1 r4/.hg/dirstate
409 2 r4/.hg/undo.backup.dirstate.bck
410 #endif
411
412 Test hardlinking outside hg:
413
414 $ mkdir x
415 $ echo foo > x/a
416
417 $ linkcp x y
418 $ echo bar >> y/a
419
420 No diff if hardlink:
421
422 $ diff x/a y/a
423
424 Test mq hardlinking:
425
426 $ echo "[extensions]" >> $HGRCPATH
427 $ echo "mq=" >> $HGRCPATH
428
429 $ hg init a
430 $ cd a
431
432 $ hg qimport -n foo - << EOF
433 > # HG changeset patch
434 > # Date 1 0
435 > diff -r 2588a8b53d66 a
436 > --- /dev/null Thu Jan 01 00:00:00 1970 +0000
437 > +++ b/a Wed Jul 23 15:54:29 2008 +0200
438 > @@ -0,0 +1,1 @@
439 > +a
440 > EOF
441 adding foo to series file
442
443 $ hg qpush
444 applying foo
445 now at: foo
446
447 $ cd ..
448 $ linkcp a b
449 $ cd b
450
451 $ hg qimport -n bar - << EOF
452 > # HG changeset patch
453 > # Date 2 0
454 > diff -r 2588a8b53d66 a
455 > --- /dev/null Thu Jan 01 00:00:00 1970 +0000
456 > +++ b/b Wed Jul 23 15:54:29 2008 +0200
457 > @@ -0,0 +1,1 @@
458 > +b
459 > EOF
460 adding bar to series file
461
462 $ hg qpush
463 applying bar
464 now at: bar
465
466 $ cat .hg/patches/status
467 430ed4828a74fa4047bc816a25500f7472ab4bfe:foo
468 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c:bar
469
470 $ cat .hg/patches/series
471 foo
472 bar
473
474 $ cat ../a/.hg/patches/status
475 430ed4828a74fa4047bc816a25500f7472ab4bfe:foo
476
477 $ cat ../a/.hg/patches/series
478 foo
479
480 Test tags hardlinking:
481
482 $ hg qdel -r qbase:qtip
483 patch foo finalized without changeset message
484 patch bar finalized without changeset message
485
486 $ hg tag -l lfoo
487 $ hg tag foo
488
489 $ cd ..
490 $ linkcp b c
491 $ cd c
492
493 $ hg tag -l -r 0 lbar
494 $ hg tag -r 0 bar
495
496 $ cat .hgtags
497 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c foo
498 430ed4828a74fa4047bc816a25500f7472ab4bfe bar
499
500 $ cat .hg/localtags
501 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c lfoo
502 430ed4828a74fa4047bc816a25500f7472ab4bfe lbar
503
504 $ cat ../b/.hgtags
505 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c foo
506
507 $ cat ../b/.hg/localtags
508 4e7abb4840c46a910f6d7b4d3c3fc7e5209e684c lfoo
509
510 $ cd ..