Mercurial > hg
view tests/test-lrucachedict.py @ 24320:b9f7f3eeb99c
localrepo: extend "changeid in repo" to return True for workingctx revision
This is necessary to implement "wc" symbol for workingctx, that will be used
as follows:
$ hg annotate -r wc FILE
In principle, "rev in repo" should be True if "repo[rev]" can return a context
object. But when it was implemented by ea3acaae25bb, lookup() had a long logic
to map all sorts of changeids to nodes, and "None in repo" did crash because
lookup() could not accept None. So I assume that the case of changeid=None was
not considered.
Now "None in repo" doesn't crash, it should be True for workingctx revision.
Behavior of "changeid in repo":
revision "null" existing rev None (workingctx)
---------- ------ ------------ -----------------
original* True True TypeError
current True True False
this patch True True True
(*original: ea3acaae25bb)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 17 Aug 2014 11:35:31 +0900 |
parents | 887ffa22fd0d |
children | 45d996a566d7 |
line wrap: on
line source
from mercurial import util def printifpresent(d, xs): for x in xs: present = x in d print "'%s' in d: %s" % (x, present) if present: print "d['%s']: %s" % (x, d[x]) def test_lrucachedict(): d = util.lrucachedict(4) d['a'] = 'va' d['b'] = 'vb' d['c'] = 'vc' d['d'] = 'vd' # all of these should be present printifpresent(d, ['a', 'b', 'c', 'd']) # 'a' should be dropped because it was least recently used d['e'] = 've' printifpresent(d, ['a', 'b', 'c', 'd', 'e']) # touch entries in some order (get or set). d['e'] d['c'] = 'vc2' d['d'] d['b'] = 'vb2' # 'e' should be dropped now d['f'] = 'vf' printifpresent(d, ['b', 'c', 'd', 'e', 'f']) d.clear() printifpresent(d, ['b', 'c', 'd', 'e', 'f']) if __name__ == '__main__': test_lrucachedict()