Mercurial > hg
annotate tests/test-walkrepo.py @ 25757:4d1382fd96ff
context: write dirstate out explicitly at the end of markcommitted
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' N N N
- 'hg status' shows "r1" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
This issue can occur when 'hg transplant' satisfies conditions below:
- multiple revisions to be transplanted change the same file
- those revisions don't change mode and size of the file, and
- the 2nd or later revision of them fails after changing the file
The root cause of this issue is that files are changed without
flushing in-memory dirstate changes via 'repo.commit()' (even though
omitting 'dirstate.normallookup()' on files changed by 'patch.patch()'
for efficiency also causes this issue).
To detect changes of files correctly, this patch writes in-memory
dirstate changes out explicitly after marking files as clean in
'committablectx.markcommitted()', which is invoked via
'repo.commit()'.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
----------------------------------- ---- ----- -----
- 'dirsttate.write()' -1 -1
----------------------------------- ---- ----- -----
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' -1 -1 N
- 'hg status' shows "r1" as "clean" -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- change "f" at N
'patch.patch()' with 'fakepatchtime.py' explicitly changes mtime
of patched files to "2000-01-01 00:00" (= N).
- 'dirstate.write()' via 'repo.commit()' at N
'fakedirstatewritetime.py' forces 'pack_dirstate()' to use
"2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked
via 'committablectx.markcommitted()'.
- 'dirstate.write()' via releasing wlock at N+1 (or "not at N")
'pack_dirstate()' via releasing wlock uses actual timestamp at
runtime as "now", and it should be different from the "2000-01-01
00:00" of "f".
BTW, this patch doesn't test cases below, even though 'patch.patch()'
is used similarly in these cases:
1. failure of 'hg import' or 'hg qpush'
2. success of 'hg import', 'hg qpush' or 'hg transplant'
Case (1) above doesn't cause this kind of issue, because:
- if patching is aborted by conflicts, changed files are committed
changed files are marked as CLEAN, even though they are partially
patched.
- otherwise, dirstate are fully restored by 'dirstateguard'
For example in timetable above, timestamp of "f" in .hg/dirstate
is restored to -1 (or less than N), and subsequent 'hg status' can
detect changes correctly.
Case (2) always causes 'repo.status()' invocation via 'repo.commit()'
just after changing files inside same wlock scope.
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- make file "f" clean N
- execute 'hg foobar'
....
- 'dirstate.normal("f")' N ***
(e.g. via dirty check
or previous 'repo.commit()')
- change "f", but keep size N
- 'repo.status()' (*1)
(via 'repo.commit()')
---- ----------------------------------- ---- ----- -----
At a glance, 'repo.status()' at (*1) seems to cause similar issue (=
"changed files are treated as clean"), but actually doesn't.
'dirstate._lastnormaltime' should be N at (*1) above, because
'dirstate.normal()' via dirty check is finished at N.
Therefore, "f" changed at N (= 'dirstate._lastnormaltime') is forcibly
treated as "unsure" at (*1), and changes are detected as expected (see
'dirstate.status()' for detail).
If 'hg import' is executed with '--no-commit', 'repo.status()' isn't
invoked just after changing files inside same wlock scope.
But preceding 'dirstate.normal()' is invoked inside another wlock
scope via 'cmdutil.bailifchanged()', and in-memory changes should be
flushed at the end of that scope.
Therefore, timestamp N of clean "f" should be replaced by -1, if
'dirstate.write()' is invoked at N. It means that condition of this
issue isn't satisfied.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Wed, 08 Jul 2015 17:01:09 +0900 |
parents | fad896292e7d |
children | a8b2bf520a2a |
rev | line source |
---|---|
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
1 import os |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
2 from mercurial import hg, ui |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
8656
diff
changeset
|
3 from mercurial.scmutil import walkrepos |
16321
e1615a24b73a
tests: make test-walkrepo use hg's symlink test
Matt Mackall <mpm@selenic.com>
parents:
14971
diff
changeset
|
4 from mercurial.util import checklink |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
5 from os import mkdir, chdir |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
6 from os.path import join as pjoin |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
7 |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
8 u = ui.ui() |
16321
e1615a24b73a
tests: make test-walkrepo use hg's symlink test
Matt Mackall <mpm@selenic.com>
parents:
14971
diff
changeset
|
9 sym = checklink('.') |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
10 |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
11 hg.repository(u, 'top1', create=1) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
12 mkdir('subdir') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
13 chdir('subdir') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
14 hg.repository(u, 'sub1', create=1) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
15 mkdir('subsubdir') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
16 chdir('subsubdir') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
17 hg.repository(u, 'subsub1', create=1) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
18 chdir(os.path.pardir) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
19 if sym: |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
20 os.symlink(os.path.pardir, 'circle') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
21 os.symlink(pjoin('subsubdir', 'subsub1'), 'subsub1') |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
22 |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
23 def runtest(): |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
24 reposet = frozenset(walkrepos('.', followsym=True)) |
7494
85dc88630beb
util: disable walkrepo() recursive behaviour
Patrick Mezard <pmezard@gmail.com>
parents:
7201
diff
changeset
|
25 if sym and (len(reposet) != 3): |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
26 print "reposet = %r" % (reposet,) |
16683 | 27 print ("Found %d repositories when I should have found 3" |
28 % (len(reposet),)) | |
7494
85dc88630beb
util: disable walkrepo() recursive behaviour
Patrick Mezard <pmezard@gmail.com>
parents:
7201
diff
changeset
|
29 if (not sym) and (len(reposet) != 2): |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
30 print "reposet = %r" % (reposet,) |
16683 | 31 print ("Found %d repositories when I should have found 2" |
32 % (len(reposet),)) | |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
33 sub1set = frozenset((pjoin('.', 'sub1'), |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
34 pjoin('.', 'circle', 'subdir', 'sub1'))) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
35 if len(sub1set & reposet) != 1: |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
36 print "sub1set = %r" % (sub1set,) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
37 print "reposet = %r" % (reposet,) |
7492
8649b2a3de75
tests: test-walkrepo shouldn't throw SystemExit
Benoit Allard <benoit@aeteurope.nl>
parents:
7201
diff
changeset
|
38 print "sub1set and reposet should have exactly one path in common." |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
39 sub2set = frozenset((pjoin('.', 'subsub1'), |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
40 pjoin('.', 'subsubdir', 'subsub1'))) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
41 if len(sub2set & reposet) != 1: |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
42 print "sub2set = %r" % (sub2set,) |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
43 print "reposet = %r" % (reposet,) |
23532
fad896292e7d
tests: fix a typo in test-walkrepos.py
Enrique A. Tobis <enrique@tobis.com.ar>
parents:
16686
diff
changeset
|
44 print "sub2set and reposet should have exactly one path in common." |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
45 sub3 = pjoin('.', 'circle', 'top1') |
16686
67964cda8701
cleanup: "not x in y" -> "x not in y"
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
46 if sym and sub3 not in reposet: |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
47 print "reposet = %r" % (reposet,) |
7492
8649b2a3de75
tests: test-walkrepo shouldn't throw SystemExit
Benoit Allard <benoit@aeteurope.nl>
parents:
7201
diff
changeset
|
48 print "Symbolic links are supported and %s is not in reposet" % (sub3,) |
6341
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
49 |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
50 runtest() |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
51 if sym: |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
52 # Simulate not having symlinks. |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
53 del os.path.samestat |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
54 sym = False |
63bdfcc3eaaf
test: Add tests for webdir symlinks and walkrepos.
Eric Hopper <hopper@omnifarious.org>
parents:
diff
changeset
|
55 runtest() |