changeset 35304:bea46aed1e1b

overlayworkingctx: add `_checkexist(path)` This is in preparation to switch this class to inheriting (and being based off a) `commitctx` instead of a `workingctx`. `filectx` has no `exists` function, so this is how we'll fall back in that case. Differential Revision: https://phab.mercurial-scm.org/D1237
author Phil Cohen <phillco@fb.com>
date Thu, 07 Dec 2017 13:20:47 -0800
parents d4f65050f3c5
children 2cb05e6043be
files mercurial/context.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Thu Dec 07 13:20:47 2017 -0800
+++ b/mercurial/context.py	Thu Dec 07 13:20:47 2017 -0800
@@ -2045,6 +2045,16 @@
         else:
             return self._wrappedctx[path].flags()
 
+    def _existsinparent(self, path):
+        try:
+            # ``commitctx` raises a ``ManifestLookupError`` if a path does not
+            # exist, unlike ``workingctx``, which returns a ``workingfilectx``
+            # with an ``exists()`` function.
+            self._wrappedctx[path]
+            return True
+        except error.ManifestLookupError:
+            return False
+
     def write(self, path, data, flags=''):
         if data is None:
             raise error.ProgrammingError("data must be non-None")
@@ -2070,13 +2080,15 @@
                 return self.exists(self._cache[path]['data'].strip())
             else:
                 return self._cache[path]['exists']
-        return self._wrappedctx[path].exists()
+
+        return self._existsinparent(path)
 
     def lexists(self, path):
         """lexists returns True if the path exists"""
         if self.isdirty(path):
             return self._cache[path]['exists']
-        return self._wrappedctx[path].lexists()
+
+        return self._existsinparent(path)
 
     def size(self, path):
         if self.isdirty(path):