Mercurial > hg
comparison tests/test-transplant.t @ 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 | ce3d4b858420 |
children | 99e88320d665 |
comparison
equal
deleted
inserted
replaced
25756:a4a41525180c | 25757:4d1382fd96ff |
---|---|
789 | 789 |
790 Explicitly kill daemons to let the test exit on Windows | 790 Explicitly kill daemons to let the test exit on Windows |
791 | 791 |
792 $ killdaemons.py | 792 $ killdaemons.py |
793 | 793 |
794 Test that patch-ed files are treated as "modified", when transplant is | |
795 aborted by failure of patching, even if none of mode, size and | |
796 timestamp of them isn't changed on the filesystem (see also issue4583) | |
797 | |
798 $ cd t | |
799 | |
800 $ cat > $TESTTMP/abort.py <<EOF | |
801 > # emulate that patch.patch() is aborted at patching on "abort" file | |
802 > from mercurial import extensions, patch as patchmod | |
803 > def patch(orig, ui, repo, patchname, | |
804 > strip=1, prefix='', files=None, | |
805 > eolmode='strict', similarity=0): | |
806 > if files is None: | |
807 > files = set() | |
808 > r = orig(ui, repo, patchname, | |
809 > strip=strip, prefix=prefix, files=files, | |
810 > eolmode=eolmode, similarity=similarity) | |
811 > if 'abort' in files: | |
812 > raise patchmod.PatchError('intentional error while patching') | |
813 > return r | |
814 > def extsetup(ui): | |
815 > extensions.wrapfunction(patchmod, 'patch', patch) | |
816 > EOF | |
817 | |
818 $ echo X1 > r1 | |
819 $ hg diff --nodates r1 | |
820 diff -r a53251cdf717 r1 | |
821 --- a/r1 | |
822 +++ b/r1 | |
823 @@ -1,1 +1,1 @@ | |
824 -r1 | |
825 +X1 | |
826 $ hg commit -m "X1 as r1" | |
827 | |
828 $ echo 'marking to abort patching' > abort | |
829 $ hg add abort | |
830 $ echo Y1 > r1 | |
831 $ hg diff --nodates r1 | |
832 diff -r 22c515968f13 r1 | |
833 --- a/r1 | |
834 +++ b/r1 | |
835 @@ -1,1 +1,1 @@ | |
836 -X1 | |
837 +Y1 | |
838 $ hg commit -m "Y1 as r1" | |
839 | |
840 $ hg update -q -C d11e3596cc1a | |
841 $ cat r1 | |
842 r1 | |
843 | |
844 $ cat >> .hg/hgrc <<EOF | |
845 > [fakedirstatewritetime] | |
846 > # emulate invoking dirstate.write() via repo.status() or markcommitted() | |
847 > # at 2000-01-01 00:00 | |
848 > fakenow = 200001010000 | |
849 > | |
850 > # emulate invoking patch.internalpatch() at 2000-01-01 00:00 | |
851 > [fakepatchtime] | |
852 > fakenow = 200001010000 | |
853 > | |
854 > [extensions] | |
855 > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py | |
856 > fakepatchtime = $TESTDIR/fakepatchtime.py | |
857 > abort = $TESTTMP/abort.py | |
858 > EOF | |
859 $ hg transplant "22c515968f13::" | |
860 applying 22c515968f13 | |
861 22c515968f13 transplanted to * (glob) | |
862 applying e38700ba9dd3 | |
863 intentional error while patching | |
864 abort: fix up the merge and run hg transplant --continue | |
865 [255] | |
866 $ cat >> .hg/hgrc <<EOF | |
867 > [hooks] | |
868 > fakedirstatewritetime = ! | |
869 > fakepatchtime = ! | |
870 > abort = ! | |
871 > EOF | |
872 | |
873 $ cat r1 | |
874 Y1 | |
875 $ hg debugstate | grep ' r1$' | |
876 n 644 3 unset r1 | |
877 $ hg status -A r1 | |
878 M r1 | |
879 | |
880 $ cd .. |