diff -r 067f7d2c7d60 -r b31b01f93b11 mercurial/util.py --- a/mercurial/util.py Thu Sep 06 11:27:25 2018 -0700 +++ b/mercurial/util.py Thu Sep 06 11:33:40 2018 -0700 @@ -1313,11 +1313,19 @@ def copy(self): result = lrucachedict(self._capacity) + + # We copy entries by iterating in oldest-to-newest order so the copy + # has the correct ordering. + + # Find the first non-empty entry. n = self._head.prev - # Iterate in oldest-to-newest order, so the copy has the right ordering + while n.key is _notset and n is not self._head: + n = n.prev + for i in range(len(self._cache)): result[n.key] = n.value n = n.prev + return result def _movetohead(self, node):