comparison tests/test-merge1.t @ 25753:fe03f522dda9

context: write dirstate out explicitly after marking files as clean 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 ---- ----------------------------------- ---- ----- ----- N -1 *** - make file "f" clean N - execute 'hg foobar' - instantiate 'dirstate' -1 -1 - 'dirstate.normal("f")' N -1 (e.g. via dirty check) - change "f", but keep size N N+1 - release wlock - 'dirstate.write()' N N - 'hg status' shows "f" 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. Occasional test failure for unexpected file status is typical example of this corner case. Batch execution with small working directory is finished in no time, and rarely satisfies condition (2) above. This issue can occur in cases below; - 'hg revert --rev REV' for revisions other than the parent - failure of 'merge.update()' before 'merge.recordupdates()' 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 changed files 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 'workingctx._checklookup()', which is invoked via 'repo.status()'. After this change, timetable is changed as below: ---- ----------------------------------- ---------------- timestamp of "f" ---------------- dirstate file- time action mem file system ---- ----------------------------------- ---- ----- ----- N -1 *** - make file "f" clean N - execute 'hg foobar' - instantiate 'dirstate' -1 -1 - 'dirstate.normal("f")' N -1 (e.g. via dirty check) ----------------------------------- ---- ----- ----- - 'dirsttate.write()' -1 -1 ----------------------------------- ---- ----- ----- - change "f", but keep size N N+1 - release wlock - 'dirstate.write()' -1 -1 - 'hg status' -1 -1 N ---- ----------------------------------- ---- ----- ----- To reproduce this issue in tests certainly, this patch emulates some timing critical actions as below: - timestamp of "f" in '.hg/dirstate' is -1 at the beginning 'hg debugrebuildstate' before command invocation ensures it. - make file "f" clean at N - change "f" at N 'touch -t 200001010000' before and after command invocation changes mtime of "f" to "2000-01-01 00:00" (= N). - invoke 'dirstate.write()' via 'repo.status()' at N 'fakedirstatewritetime.py' forces 'pack_dirstate()' to use "2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked via 'workingctx._checklookup()'. - invoke '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 also changes 'test-largefiles-misc.t', because adding 'dirstate.write()' makes recent dirstate changes visible to external process.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 08 Jul 2015 17:01:09 +0900
parents 6084926366b9
children 56b2bcea2529
comparison
equal deleted inserted replaced
25752:815df73abf12 25753:fe03f522dda9
204 $ hg rm b 204 $ hg rm b
205 $ hg ci -md 205 $ hg ci -md
206 $ hg revert -r -2 b 206 $ hg revert -r -2 b
207 $ hg up -q -- -2 207 $ hg up -q -- -2
208 208
209 Test that updated files are treated as "modified", when
210 'merge.update()' is aborted before 'merge.recordupdates()' (= parents
211 aren't changed), even if none of mode, size and timestamp of them
212 isn't changed on the filesystem (see also issue4583).
213
214 $ cat > $TESTTMP/abort.py <<EOF
215 > # emulate aborting before "recordupdates()". in this case, files
216 > # are changed without updating dirstate
217 > from mercurial import extensions, merge, util
218 > def applyupdates(orig, *args, **kwargs):
219 > orig(*args, **kwargs)
220 > raise util.Abort('intentional aborting')
221 > def extsetup(ui):
222 > extensions.wrapfunction(merge, "applyupdates", applyupdates)
223 > EOF
224
225 $ cat >> .hg/hgrc <<EOF
226 > [fakedirstatewritetime]
227 > # emulate invoking dirstate.write() via repo.status()
228 > # at 2000-01-01 00:00
229 > fakenow = 200001010000
230 > EOF
231
232 (file gotten from other revision)
233
234 $ hg update -q -C 2
235 $ echo 'THIS IS FILE B5' > b
236 $ hg commit -m 'commit #5'
237
238 $ hg update -q -C 3
239 $ cat b
240 This is file b1
241 $ touch -t 200001010000 b
242 $ hg debugrebuildstate
243
244 $ cat >> .hg/hgrc <<EOF
245 > [extensions]
246 > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py
247 > abort = $TESTTMP/abort.py
248 > EOF
249 $ hg merge 5
250 abort: intentional aborting
251 [255]
252 $ cat >> .hg/hgrc <<EOF
253 > [extensions]
254 > fakedirstatewritetime = !
255 > abort = !
256 > EOF
257
258 $ cat b
259 THIS IS FILE B5
260 $ touch -t 200001010000 b
261 $ hg status -A b
262 M b
263
264 (file merged from other revision)
265
266 $ hg update -q -C 3
267 $ echo 'this is file b6' > b
268 $ hg commit -m 'commit #6'
269 created new head
270
271 $ cat b
272 this is file b6
273 $ touch -t 200001010000 b
274 $ hg debugrebuildstate
275
276 $ cat >> .hg/hgrc <<EOF
277 > [extensions]
278 > fakedirstatewritetime = $TESTDIR/fakedirstatewritetime.py
279 > abort = $TESTTMP/abort.py
280 > EOF
281 $ hg merge --tool internal:other 5
282 abort: intentional aborting
283 [255]
284 $ cat >> .hg/hgrc <<EOF
285 > [extensions]
286 > fakedirstatewritetime = !
287 > abort = !
288 > EOF
289
290 $ cat b
291 THIS IS FILE B5
292 $ touch -t 200001010000 b
293 $ hg status -A b
294 M b
295
209 $ cd .. 296 $ cd ..