D4506: util: update lrucachedict order during get()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Sep 7 17:18:57 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  get() should have the same semantics as __getitem__ for item
  retrieval.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4506

AFFECTED FILES
  mercurial/util.py
  tests/test-lrucachedict.py

CHANGE DETAILS

diff --git a/tests/test-lrucachedict.py b/tests/test-lrucachedict.py
--- a/tests/test-lrucachedict.py
+++ b/tests/test-lrucachedict.py
@@ -63,6 +63,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)
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1332,7 +1332,7 @@
 
     def get(self, k, default=None):
         try:
-            return self._cache[k].value
+            return self.__getitem__(k)
         except KeyError:
             return default
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list