Mercurial > hg
view tests/test-rebase-detach.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 | aa4a1672583e |
children | ef1eb6df7071 |
line wrap: on
line source
$ cat >> $HGRCPATH <<EOF > [extensions] > rebase= > > [phases] > publish=False > > [alias] > tglog = log -G --template "{rev}: '{desc}' {branches}\n" > EOF $ hg init a $ cd a $ hg unbundle "$TESTDIR/bundles/rebase.hg" adding changesets adding manifests adding file changes added 8 changesets with 7 changes to 7 files (+2 heads) (run 'hg heads' to see heads, 'hg merge' to merge) $ hg up tip 3 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd .. Rebasing D onto H detaching from C: $ hg clone -q -u . a a1 $ cd a1 $ hg tglog @ 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg phase --force --secret 3 $ hg rebase -s 3 -d 7 rebasing 3:32af7686d403 "D" saved backup bundle to $TESTTMP/a1/.hg/strip-backup/32af7686d403-6f7dface-backup.hg (glob) $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n" o 7:secret 'D' | @ 6:draft 'H' | | o 5:draft 'G' |/| o | 4:draft 'F' | | | o 3:draft 'E' |/ | o 2:draft 'C' | | | o 1:draft 'B' |/ o 0:draft 'A' $ hg manifest --rev tip A D F H $ cd .. Rebasing C onto H detaching from B: $ hg clone -q -u . a a2 $ cd a2 $ hg tglog @ 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg rebase -s 2 -d 7 rebasing 2:5fddd98957c8 "C" rebasing 3:32af7686d403 "D" saved backup bundle to $TESTTMP/a2/.hg/strip-backup/5fddd98957c8-f9244fa1-backup.hg (glob) $ hg tglog o 7: 'D' | o 6: 'C' | @ 5: 'H' | | o 4: 'G' |/| o | 3: 'F' | | | o 2: 'E' |/ | o 1: 'B' |/ o 0: 'A' $ hg manifest --rev tip A C D F H $ cd .. Rebasing B onto H using detach (same as not using it): $ hg clone -q -u . a a3 $ cd a3 $ hg tglog @ 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg rebase -s 1 -d 7 rebasing 1:42ccdea3bb16 "B" rebasing 2:5fddd98957c8 "C" rebasing 3:32af7686d403 "D" saved backup bundle to $TESTTMP/a3/.hg/strip-backup/42ccdea3bb16-3cb021d3-backup.hg (glob) $ hg tglog o 7: 'D' | o 6: 'C' | o 5: 'B' | @ 4: 'H' | | o 3: 'G' |/| o | 2: 'F' | | | o 1: 'E' |/ o 0: 'A' $ hg manifest --rev tip A B C D F H $ cd .. Rebasing C onto H detaching from B and collapsing: $ hg clone -q -u . a a4 $ cd a4 $ hg phase --force --secret 3 $ hg tglog @ 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg rebase --collapse -s 2 -d 7 rebasing 2:5fddd98957c8 "C" note: rebase of 2:5fddd98957c8 created no changes to commit rebasing 3:32af7686d403 "D" note: rebase of 3:32af7686d403 created no changes to commit saved backup bundle to $TESTTMP/a4/.hg/strip-backup/5fddd98957c8-f9244fa1-backup.hg (glob) $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n" o 6:secret 'Collapsed revision | * C | * D' @ 5:draft 'H' | | o 4:draft 'G' |/| o | 3:draft 'F' | | | o 2:draft 'E' |/ | o 1:draft 'B' |/ o 0:draft 'A' $ hg manifest --rev tip A C D F H $ cd .. Rebasing across null as ancestor $ hg clone -q -U a a5 $ cd a5 $ echo x > x $ hg add x $ hg ci -m "extra branch" created new head $ hg tglog @ 8: 'extra branch' o 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg rebase -s 1 -d tip rebasing 1:42ccdea3bb16 "B" rebasing 2:5fddd98957c8 "C" rebasing 3:32af7686d403 "D" saved backup bundle to $TESTTMP/a5/.hg/strip-backup/42ccdea3bb16-3cb021d3-backup.hg (glob) $ hg tglog o 8: 'D' | o 7: 'C' | o 6: 'B' | @ 5: 'extra branch' o 4: 'H' | | o 3: 'G' |/| o | 2: 'F' | | | o 1: 'E' |/ o 0: 'A' $ hg rebase -d 5 -s 7 rebasing 7:13547172c9c0 "C" rebasing 8:4e27a76c371a "D" (tip) saved backup bundle to $TESTTMP/a5/.hg/strip-backup/13547172c9c0-35685ded-backup.hg (glob) $ hg tglog o 8: 'D' | o 7: 'C' | | o 6: 'B' |/ @ 5: 'extra branch' o 4: 'H' | | o 3: 'G' |/| o | 2: 'F' | | | o 1: 'E' |/ o 0: 'A' $ cd .. Verify that target is not selected as external rev (issue3085) $ hg clone -q -U a a6 $ cd a6 $ hg up -q 6 $ echo "I" >> E $ hg ci -m "I" $ hg merge 7 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg ci -m "Merge" $ echo "J" >> F $ hg ci -m "J" $ hg rebase -s 8 -d 7 --collapse --config ui.merge=internal:other rebasing 8:9790e768172d "I" note: rebase of 8:9790e768172d created no changes to commit rebasing 9:5d7b11f5fb97 "Merge" note: rebase of 9:5d7b11f5fb97 created no changes to commit rebasing 10:9427d4d5af81 "J" (tip) note: rebase of 10:9427d4d5af81 created no changes to commit saved backup bundle to $TESTTMP/a6/.hg/strip-backup/9790e768172d-c2111e9d-backup.hg (glob) $ hg tglog @ 8: 'Collapsed revision | * I | * Merge | * J' o 7: 'H' | | o 6: 'G' |/| o | 5: 'F' | | | o 4: 'E' |/ | o 3: 'D' | | | o 2: 'C' | | | o 1: 'B' |/ o 0: 'A' $ hg log --rev tip changeset: 8:9472f4b1d736 tag: tip user: test date: Thu Jan 01 00:00:00 1970 +0000 summary: Collapsed revision $ cd .. Ensure --continue restores a correct state (issue3046) and phase: $ hg clone -q a a7 $ cd a7 $ hg up -q 3 $ echo 'H2' > H $ hg ci -A -m 'H2' adding H $ hg phase --force --secret 8 $ hg rebase -s 8 -d 7 --config ui.merge=internal:fail rebasing 8:6215fafa5447 "H2" (tip) merging H warning: conflicts during merge. merging H incomplete! (edit conflicts, then use 'hg resolve --mark') unresolved conflicts (see hg resolve, then hg rebase --continue) [1] $ hg resolve --all -t internal:local (no more unresolved files) $ hg rebase -c rebasing 8:6215fafa5447 "H2" (tip) note: rebase of 8:6215fafa5447 created no changes to commit saved backup bundle to $TESTTMP/a7/.hg/strip-backup/6215fafa5447-5804ebd5-backup.hg (glob) $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n" @ 7:draft 'H' | | o 6:draft 'G' |/| o | 5:draft 'F' | | | o 4:draft 'E' |/ | o 3:draft 'D' | | | o 2:draft 'C' | | | o 1:draft 'B' |/ o 0:draft 'A' $ cd ..