changeset 45228:1476ec96965f stable

context: re-add `overlayworkingctx._compact()` removed in 6a5dcd754842 This partially backs out 6a5dcd754842. The method was and is unused, but a call to it is introduced in the next patch. Differential Revision: https://phab.mercurial-scm.org/D8842
author Manuel Jacob <me@manueljacob.de>
date Tue, 28 Jul 2020 20:07:05 +0200
parents 559ebfb5a58e
children 0ea08126a2af
files mercurial/context.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Thu Jul 23 16:30:30 2020 +0200
+++ b/mercurial/context.py	Tue Jul 28 20:07:05 2020 +0200
@@ -2530,6 +2530,43 @@
     def clean(self):
         self._cache = {}
 
+    def _compact(self):
+        """Removes keys from the cache that are actually clean, by comparing
+        them with the underlying context.
+
+        This can occur during the merge process, e.g. by passing --tool :local
+        to resolve a conflict.
+        """
+        keys = []
+        # This won't be perfect, but can help performance significantly when
+        # using things like remotefilelog.
+        scmutil.prefetchfiles(
+            self.repo(),
+            [
+                (
+                    self.p1().rev(),
+                    scmutil.matchfiles(self.repo(), self._cache.keys()),
+                )
+            ],
+        )
+
+        for path in self._cache.keys():
+            cache = self._cache[path]
+            try:
+                underlying = self._wrappedctx[path]
+                if (
+                    underlying.data() == cache[b'data']
+                    and underlying.flags() == cache[b'flags']
+                ):
+                    keys.append(path)
+            except error.ManifestLookupError:
+                # Path not in the underlying manifest (created).
+                continue
+
+        for path in keys:
+            del self._cache[path]
+        return keys
+
     def _markdirty(
         self, path, exists, data=None, date=None, flags=b'', copied=None
     ):