util: update lrucachedict order during get()
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 07 Sep 2018 10:18:20 -0700
changeset 39571 8f2c0d1b454c
parent 39570 f296c0b366c8
child 39572 b6b9488aae4c
util: update lrucachedict order during get() get() should have the same semantics as __getitem__ for item retrieval. Differential Revision: https://phab.mercurial-scm.org/D4506
mercurial/util.py
tests/test-lrucachedict.py
--- a/mercurial/util.py	Thu Sep 06 18:04:27 2018 -0700
+++ b/mercurial/util.py	Fri Sep 07 10:18:20 2018 -0700
@@ -1332,7 +1332,7 @@
 
     def get(self, k, default=None):
         try:
-            return self._cache[k].value
+            return self.__getitem__(k)
         except KeyError:
             return default
 
--- a/tests/test-lrucachedict.py	Thu Sep 06 18:04:27 2018 -0700
+++ b/tests/test-lrucachedict.py	Fri Sep 07 10:18:20 2018 -0700
@@ -67,6 +67,18 @@
         for key in ('a', 'b'):
             self.assertIn(key, d)
 
+    def testget(self):
+        d = util.lrucachedict(4)
+        d['a'] = 'va'
+        d['b'] = 'vb'
+        d['c'] = 'vc'
+
+        self.assertIsNone(d.get('missing'))
+        self.assertEqual(list(d), ['c', 'b', 'a'])
+
+        self.assertEqual(d.get('a'), 'va')
+        self.assertEqual(list(d), ['a', 'c', 'b'])
+
     def testcopypartial(self):
         d = util.lrucachedict(4)
         d.insert('a', 'va', cost=4)