Patchwork D1243: overlayworkingctx: add `_compact()`

login
register
mail settings
Submitter phabricator
Date Dec. 8, 2017, 8:39 p.m.
Message ID <a9f1e8e7030f5b0e08e4007a74d9d55f@localhost.localdomain>
Download mbox | patch
Permalink /patch/26125/
State Not Applicable
Headers show

Comments

phabricator - Dec. 8, 2017, 8:39 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGdc9da4f4f363: overlayworkingctx: add `_compact()` (authored by phillco, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1243?vs=4249&id=4272

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

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: phillco, #hg-reviewers, durin42
Cc: durin42, mercurial-devel

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2225,6 +2225,29 @@ 
     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 = []
+        for path in self._cache.keys():
+            cache = self._cache[path]
+            try:
+                underlying = self._wrappedctx[path]
+                if (underlying.data() == cache['data'] and
+                            underlying.flags() == cache['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=''):
         self._cache[path] = {
             'exists': exists,