# HG changeset patch # User Phil Cohen # Date 1512691626 28800 # Node ID dc9da4f4f363e1c7835b9e3223afdf3382fec7c6 # Parent 71edd38c4bb47ee425652e1985bc9fd7eab998fe overlayworkingctx: add `_compact()` Alas, presence of a key in the cache isn't sufficient evidence that the file is actually dirty. Differential Revision: https://phab.mercurial-scm.org/D1243 diff -r 71edd38c4bb4 -r dc9da4f4f363 mercurial/context.py --- a/mercurial/context.py Thu Dec 07 22:26:07 2017 -0800 +++ b/mercurial/context.py Thu Dec 07 16:07:06 2017 -0800 @@ -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,