Mercurial > hg
view tests/test-rebase-cache.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 | 701df761aa94 |
children | 3b7cb3d17137 |
line wrap: on
line source
$ cat >> $HGRCPATH <<EOF > [extensions] > rebase= > mq= > > [phases] > publish=False > > [alias] > tglog = log -G --template "{rev}: '{desc}' {branches}\n" > theads = heads --template "{rev}: '{desc}' {branches}\n" > EOF $ hg init a $ cd a $ echo a > a $ hg ci -Am A adding a $ hg branch branch1 marked working directory as branch branch1 (branches are permanent and global, did you want a bookmark?) $ hg ci -m 'branch1' $ echo b > b $ hg ci -Am B adding b $ hg up -q 0 $ hg branch branch2 marked working directory as branch branch2 $ hg ci -m 'branch2' $ echo c > C $ hg ci -Am C adding C $ hg up -q 2 $ hg branch -f branch2 marked working directory as branch branch2 $ echo d > d $ hg ci -Am D adding d created new head $ echo e > e $ hg ci -Am E adding e $ hg update default 0 files updated, 0 files merged, 3 files removed, 0 files unresolved $ hg branch branch3 marked working directory as branch branch3 $ hg ci -m 'branch3' $ echo f > f $ hg ci -Am F adding f $ cd .. Rebase part of branch2 (5-6) onto branch3 (8): $ hg clone -q -u . a a1 $ cd a1 $ hg tglog @ 8: 'F' branch3 | o 7: 'branch3' branch3 | | o 6: 'E' branch2 | | | o 5: 'D' branch2 | | | | o 4: 'C' branch2 | | | +---o 3: 'branch2' branch2 | | | o 2: 'B' branch1 | | | o 1: 'branch1' branch1 |/ o 0: 'A' $ hg branches branch3 8:4666b71e8e32 branch2 6:5097051d331d branch1 2:0a03079c47fd (inactive) default 0:1994f17a630e (inactive) $ hg theads 8: 'F' branch3 6: 'E' branch2 4: 'C' branch2 2: 'B' branch1 0: 'A' $ hg rebase -s 5 -d 8 rebasing 5:635859577d0b "D" rebasing 6:5097051d331d "E" saved backup bundle to $TESTTMP/a1/.hg/strip-backup/635859577d0b-89160bff-backup.hg (glob) $ hg branches branch3 8:466cdfb14b62 branch2 4:e4fdb121d036 branch1 2:0a03079c47fd default 0:1994f17a630e (inactive) $ hg theads 8: 'E' branch3 4: 'C' branch2 2: 'B' branch1 0: 'A' $ hg tglog o 8: 'E' branch3 | o 7: 'D' branch3 | @ 6: 'F' branch3 | o 5: 'branch3' branch3 | | o 4: 'C' branch2 | | | o 3: 'branch2' branch2 |/ | o 2: 'B' branch1 | | | o 1: 'branch1' branch1 |/ o 0: 'A' $ cd .. Rebase head of branch3 (8) onto branch2 (6): $ hg clone -q -u . a a2 $ cd a2 $ hg tglog @ 8: 'F' branch3 | o 7: 'branch3' branch3 | | o 6: 'E' branch2 | | | o 5: 'D' branch2 | | | | o 4: 'C' branch2 | | | +---o 3: 'branch2' branch2 | | | o 2: 'B' branch1 | | | o 1: 'branch1' branch1 |/ o 0: 'A' $ hg rebase -s 8 -d 6 rebasing 8:4666b71e8e32 "F" (tip) saved backup bundle to $TESTTMP/a2/.hg/strip-backup/4666b71e8e32-fc1c4e96-backup.hg (glob) $ hg branches branch2 8:6b4bdc1b5ac0 branch3 7:653b9feb4616 branch1 2:0a03079c47fd (inactive) default 0:1994f17a630e (inactive) $ hg theads 8: 'F' branch2 7: 'branch3' branch3 4: 'C' branch2 2: 'B' branch1 0: 'A' $ hg tglog @ 8: 'F' branch2 | | o 7: 'branch3' branch3 | | o | 6: 'E' branch2 | | o | 5: 'D' branch2 | | | | o 4: 'C' branch2 | | | | | o 3: 'branch2' branch2 | |/ o | 2: 'B' branch1 | | o | 1: 'branch1' branch1 |/ o 0: 'A' $ hg verify -q $ cd .. Rebase entire branch3 (7-8) onto branch2 (6): $ hg clone -q -u . a a3 $ cd a3 $ hg tglog @ 8: 'F' branch3 | o 7: 'branch3' branch3 | | o 6: 'E' branch2 | | | o 5: 'D' branch2 | | | | o 4: 'C' branch2 | | | +---o 3: 'branch2' branch2 | | | o 2: 'B' branch1 | | | o 1: 'branch1' branch1 |/ o 0: 'A' $ hg rebase -s 7 -d 6 rebasing 7:653b9feb4616 "branch3" note: rebase of 7:653b9feb4616 created no changes to commit rebasing 8:4666b71e8e32 "F" (tip) saved backup bundle to $TESTTMP/a3/.hg/strip-backup/653b9feb4616-3c88de16-backup.hg (glob) $ hg branches branch2 7:6b4bdc1b5ac0 branch1 2:0a03079c47fd (inactive) default 0:1994f17a630e (inactive) $ hg theads 7: 'F' branch2 4: 'C' branch2 2: 'B' branch1 0: 'A' $ hg tglog @ 7: 'F' branch2 | o 6: 'E' branch2 | o 5: 'D' branch2 | | o 4: 'C' branch2 | | | o 3: 'branch2' branch2 | | o | 2: 'B' branch1 | | o | 1: 'branch1' branch1 |/ o 0: 'A' $ hg verify -q Stripping multiple branches in one go bypasses the fast-case code to update the branch cache. $ hg strip 2 0 files updated, 0 files merged, 4 files removed, 0 files unresolved saved backup bundle to $TESTTMP/a3/.hg/strip-backup/0a03079c47fd-11b7c407-backup.hg (glob) $ hg tglog o 3: 'C' branch2 | o 2: 'branch2' branch2 | | @ 1: 'branch1' branch1 |/ o 0: 'A' $ hg branches branch2 3:e4fdb121d036 branch1 1:63379ac49655 default 0:1994f17a630e (inactive) $ hg theads 3: 'C' branch2 1: 'branch1' branch1 0: 'A' Fast path branchcache code should not be invoked if branches stripped is not the same as branches remaining. $ hg init b $ cd b $ hg branch branch1 marked working directory as branch branch1 (branches are permanent and global, did you want a bookmark?) $ hg ci -m 'branch1' $ hg branch branch2 marked working directory as branch branch2 $ hg ci -m 'branch2' $ hg branch -f branch1 marked working directory as branch branch1 $ echo a > A $ hg ci -Am A adding A created new head $ hg tglog @ 2: 'A' branch1 | o 1: 'branch2' branch2 | o 0: 'branch1' branch1 $ hg theads 2: 'A' branch1 1: 'branch2' branch2 $ hg strip 2 0 files updated, 0 files merged, 1 files removed, 0 files unresolved saved backup bundle to $TESTTMP/a3/b/.hg/strip-backup/a5b4b27ed7b4-a3b6984e-backup.hg (glob) $ hg theads 1: 'branch2' branch2 0: 'branch1' branch1 Make sure requesting to strip a revision already stripped does not confuse things. Try both orders. $ cd .. $ hg init c $ cd c $ echo a > a $ hg ci -Am A adding a $ echo b > b $ hg ci -Am B adding b $ echo c > c $ hg ci -Am C adding c $ echo d > d $ hg ci -Am D adding d $ echo e > e $ hg ci -Am E adding e $ hg tglog @ 4: 'E' | o 3: 'D' | o 2: 'C' | o 1: 'B' | o 0: 'A' $ hg strip 3 4 0 files updated, 0 files merged, 2 files removed, 0 files unresolved saved backup bundle to $TESTTMP/a3/c/.hg/strip-backup/67a385d4e6f2-b9243789-backup.hg (glob) $ hg theads 2: 'C' $ hg strip 2 1 0 files updated, 0 files merged, 2 files removed, 0 files unresolved saved backup bundle to $TESTTMP/a3/c/.hg/strip-backup/6c81ed0049f8-a687065f-backup.hg (glob) $ hg theads 0: 'A' Make sure rebase does not break for phase/filter related reason ---------------------------------------------------------------- (issue3858) $ cd .. $ cat >> $HGRCPATH << EOF > [ui] > logtemplate={rev} {desc} {phase}\n > EOF $ hg init c4 $ cd c4 $ echo a > a $ hg ci -Am A adding a $ echo b > b $ hg ci -Am B adding b $ hg up 0 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ echo c > c $ hg ci -Am C adding c created new head $ hg up 1 1 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg merge 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg ci -m d $ hg up 2 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ echo e > e $ hg ci -Am E adding e created new head $ hg merge 3 1 files updated, 0 files merged, 0 files removed, 0 files unresolved (branch merge, don't forget to commit) $ hg ci -m F $ hg up 3 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ echo g > g $ hg ci -Am G adding g created new head $ echo h > h $ hg ci -Am H adding h $ hg up 5 1 files updated, 0 files merged, 2 files removed, 0 files unresolved $ echo i > i $ hg ci -Am I adding i Turn most changeset public $ hg ph -p 7 $ hg heads 8 I draft 7 H public $ hg log -G @ 8 I draft | | o 7 H public | | | o 6 G public | | o | 5 F draft |\| o | 4 E draft | | | o 3 d public |/| o | 2 C public | | | o 1 B public |/ o 0 A public $ cat > $TESTTMP/checkeditform.sh <<EOF > env | grep HGEDITFORM > true > EOF $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg rebase --dest 7 --source 5 -e rebasing 5:361a99976cc9 "F" HGEDITFORM=rebase.merge rebasing 8:326cfedc031c "I" (tip) HGEDITFORM=rebase.normal saved backup bundle to $TESTTMP/a3/c4/.hg/strip-backup/361a99976cc9-35e980d0-backup.hg (glob)