Mercurial > hg
annotate tests/test-lrucachedict.py @ 26631:e077ce385609
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 13 Oct 2015 12:25:43 -0700 |
parents | 887ffa22fd0d |
children | 45d996a566d7 |
rev | line source |
---|---|
18603 | 1 from mercurial import util |
2 | |
3 def printifpresent(d, xs): | |
4 for x in xs: | |
5 present = x in d | |
6 print "'%s' in d: %s" % (x, present) | |
7 if present: | |
8 print "d['%s']: %s" % (x, d[x]) | |
9 | |
10 def test_lrucachedict(): | |
11 d = util.lrucachedict(4) | |
12 d['a'] = 'va' | |
13 d['b'] = 'vb' | |
14 d['c'] = 'vc' | |
15 d['d'] = 'vd' | |
16 | |
17 # all of these should be present | |
18 printifpresent(d, ['a', 'b', 'c', 'd']) | |
19 | |
20 # 'a' should be dropped because it was least recently used | |
21 d['e'] = 've' | |
22 printifpresent(d, ['a', 'b', 'c', 'd', 'e']) | |
23 | |
24 # touch entries in some order (get or set). | |
25 d['e'] | |
26 d['c'] = 'vc2' | |
27 d['d'] | |
28 d['b'] = 'vb2' | |
29 | |
30 # 'e' should be dropped now | |
31 d['f'] = 'vf' | |
32 printifpresent(d, ['b', 'c', 'd', 'e', 'f']) | |
33 | |
19710
887ffa22fd0d
lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents:
18603
diff
changeset
|
34 d.clear() |
887ffa22fd0d
lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents:
18603
diff
changeset
|
35 printifpresent(d, ['b', 'c', 'd', 'e', 'f']) |
887ffa22fd0d
lrucachedict: implement clear()
Siddharth Agarwal <sid0@fb.com>
parents:
18603
diff
changeset
|
36 |
18603 | 37 if __name__ == '__main__': |
38 test_lrucachedict() |