D1243: overlayworkingctx: add `_compact()`

phillco (Phil Cohen) phabricator at mercurial-scm.org
Thu Dec 7 21:23:24 UTC 2017


phillco updated this revision to Diff 4189.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

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

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
@@ -2245,6 +2245,9 @@
 
     def commit(self, text, parents=None, date=None, extra=None, editor=None,
                user=None, branch=None):
+        # We need to discard any keys that are actually clean before the empty
+        # commit check.
+        self._compact()
         allowemptycommit = (len(self._cache) or
                             self._repo.ui.configbool('ui', 'allowemptycommit'))
         if not allowemptycommit:
@@ -2265,6 +2268,29 @@
     def clean(self):
         self._cache = {}
 
+    def _compact(self):
+        """Removes keys from the cache that are actually clean, by comparing
+        them with the underlting 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,



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


More information about the Mercurial-devel mailing list