annotate tests/test-rename-after-merge.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 f2719b387380
children eb586ed5d8ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12399
4fee1fd3de9a tests: added a short description to issue numbers
Martin Geisler <mg@aragost.com>
parents: 12328
diff changeset
1 Issue746: renaming files brought by the second parent of a merge was
4fee1fd3de9a tests: added a short description to issue numbers
Martin Geisler <mg@aragost.com>
parents: 12328
diff changeset
2 broken.
5318
c6682cdada2f Test renaming files brought by merge second parent (issue 746)
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
3
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
4 Create source repository:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
5
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
6 $ hg init t
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
7 $ cd t
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
8 $ echo a > a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
9 $ hg ci -Am a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
10 adding a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
11 $ cd ..
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
12
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
13 Fork source repository:
5318
c6682cdada2f Test renaming files brought by merge second parent (issue 746)
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
14
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
15 $ hg clone t t2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
16 updating to branch default
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
17 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
18 $ cd t2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
19 $ echo b > b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
20 $ hg ci -Am b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
21 adding b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
22
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
23 Update source repository:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
24
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
25 $ cd ../t
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
26 $ echo a >> a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
27 $ hg ci -m a2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
28
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
29 Merge repositories:
5318
c6682cdada2f Test renaming files brought by merge second parent (issue 746)
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
30
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
31 $ hg pull ../t2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
32 pulling from ../t2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
33 searching for changes
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
34 adding changesets
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
35 adding manifests
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
36 adding file changes
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
37 added 1 changesets with 1 changes to 1 files (+1 heads)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
38 (run 'hg heads' to see heads, 'hg merge' to merge)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
39
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
40 $ hg merge
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
41 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
42 (branch merge, don't forget to commit)
5318
c6682cdada2f Test renaming files brought by merge second parent (issue 746)
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
43
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
44 $ hg st
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
45 M b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
46
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
47 Rename b as c:
5318
c6682cdada2f Test renaming files brought by merge second parent (issue 746)
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
48
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
49 $ hg mv b c
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
50 $ hg st
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
51 A c
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
52 R b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
53
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
54 Rename back c as b:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
55
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
56 $ hg mv c b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
57 $ hg st
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
58 M b
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
59
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
60 $ cd ..
7689
d821ea464465 Fix a corner case when committing a rename after a merge (issue1476)
Patrick Mezard <pmezard@gmail.com>
parents: 5608
diff changeset
61
12399
4fee1fd3de9a tests: added a short description to issue numbers
Martin Geisler <mg@aragost.com>
parents: 12328
diff changeset
62 Issue 1476: renaming a first parent file into another first parent
4fee1fd3de9a tests: added a short description to issue numbers
Martin Geisler <mg@aragost.com>
parents: 12328
diff changeset
63 file while none of them belong to the second parent was broken
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
64
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
65 $ hg init repo1476
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
66 $ cd repo1476
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
67 $ echo a > a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
68 $ hg ci -Am adda
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
69 adding a
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
70 $ echo b1 > b1
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
71 $ echo b2 > b2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
72 $ hg ci -Am changea
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
73 adding b1
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
74 adding b2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
75 $ hg up -C 0
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
76 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
77 $ echo c1 > c1
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
78 $ echo c2 > c2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
79 $ hg ci -Am addcandd
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
80 adding c1
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
81 adding c2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
82 created new head
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
83
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
84 Merge heads:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
85
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
86 $ hg merge
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
87 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
88 (branch merge, don't forget to commit)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
89
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
90 $ hg mv -Af c1 c2
7689
d821ea464465 Fix a corner case when committing a rename after a merge (issue1476)
Patrick Mezard <pmezard@gmail.com>
parents: 5608
diff changeset
91
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
92 Commit issue 1476:
7689
d821ea464465 Fix a corner case when committing a rename after a merge (issue1476)
Patrick Mezard <pmezard@gmail.com>
parents: 5608
diff changeset
93
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
94 $ hg ci -m merge
7689
d821ea464465 Fix a corner case when committing a rename after a merge (issue1476)
Patrick Mezard <pmezard@gmail.com>
parents: 5608
diff changeset
95
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
96 $ hg log -r tip -C -v | grep copies
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
97 copies: c2 (c1)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
98
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
99 $ hg rollback
13446
1e497df514e2 rollback: clarifies the message about the reverted state (issue2628)
Gilles Moris <gilles.moris@free.fr>
parents: 12399
diff changeset
100 repository tip rolled back to revision 2 (undo commit)
13455
053c042118bc rollback, i18n: avoid parameterized message
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 13446
diff changeset
101 working directory now based on revisions 2 and 1
12279
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
102
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
103 $ hg up -C .
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
104 2 files updated, 0 files merged, 2 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
105
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
106 Merge heads again:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
107
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
108 $ hg merge
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
109 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
110 (branch merge, don't forget to commit)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
111
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
112 $ hg mv -Af b1 b2
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
113
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
114 Commit issue 1476 with a rename on the other side:
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
115
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
116 $ hg ci -m merge
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
117
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
118 $ hg log -r tip -C -v | grep copies
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
119 copies: b2 (b1)
28e2e3804f2e combine tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 7689
diff changeset
120
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13455
diff changeset
121 $ cd ..