mercurial/util.py
changeset 39565 2dcc68c7d25b
parent 39564 5d75a3c16193
child 39566 bd9d3a89f07b
--- a/mercurial/util.py	Thu Sep 06 11:37:27 2018 -0700
+++ b/mercurial/util.py	Thu Sep 06 11:40:20 2018 -0700
@@ -1311,8 +1311,19 @@
 
         self._cache.clear()
 
-    def copy(self):
-        result = lrucachedict(self.capacity)
+    def copy(self, capacity=None):
+        """Create a new cache as a copy of the current one.
+
+        By default, the new cache has the same capacity as the existing one.
+        But, the cache capacity can be changed as part of performing the
+        copy.
+
+        Items in the copy have an insertion/access order matching this
+        instance.
+        """
+
+        capacity = capacity or self.capacity
+        result = lrucachedict(capacity)
 
         # We copy entries by iterating in oldest-to-newest order so the copy
         # has the correct ordering.
@@ -1322,6 +1333,8 @@
         while n.key is _notset and n is not self._head:
             n = n.prev
 
+        # We could potentially skip the first N items when decreasing capacity.
+        # But let's keep it simple unless it is a performance problem.
         for i in range(len(self._cache)):
             result[n.key] = n.value
             n = n.prev