[PATCH 1 of 3] util: properly implement lrucachedict.get()
Gregory Szorc
gregory.szorc at gmail.com
Tue Aug 23 04:50:19 UTC 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1471923037 25200
# Mon Aug 22 20:30:37 2016 -0700
# Node ID 93a0220d9982345a030fe9a5b954beaeded51aad
# Parent 3f9e76e1d75968d5b4e23cf15fcdbe62cb45ad80
util: properly implement lrucachedict.get()
Before, it was returning the raw _lrucachenode instance instead of its
value.
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -646,17 +646,17 @@ class lrucachedict(object):
# this node the oldest item.
self._movetohead(node)
self._head = node.next
# Additional dict methods.
def get(self, k, default=None):
try:
- return self._cache[k]
+ return self._cache[k].value
except KeyError:
return default
def clear(self):
n = self._head
while n.key is not _notset:
n.markempty()
n = n.next
diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py
--- a/tests/test-lrucachedict.py
+++ b/tests/test-lrucachedict.py
@@ -20,16 +20,19 @@ def test_lrucachedict():
# 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'])
+ assert d.get('a') is None
+ assert d.get('e') == 've'
+
# 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'
More information about the Mercurial-devel
mailing list