D8842: context: re-add `overlayworkingctx._compact()` removed in 6a5dcd754842

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

D8842: context: re-add `overlayworkingctx._compact()` removed in 6a5dcd754842

pulkit (Pulkit Goyal)
mjacob created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This partially backs out 6a5dcd754842 <https://phab.mercurial-scm.org/rHG6a5dcd75484259095abca2c5b3f7ab12421a94ad>. The method was and is unused, but a call
  to it is introduced in the next patch.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -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
     ):



To: mjacob, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel