mercurial/context.py
changeset 32764 ec302748edd8
parent 32763 34be21aa2b26
child 32765 041d976b662a
--- a/mercurial/context.py	Fri Jun 09 13:25:02 2017 -0700
+++ b/mercurial/context.py	Fri Jun 09 13:39:13 2017 -0700
@@ -2060,6 +2060,22 @@
 
     return getfilectx
 
+def memfilefrompatch(patchstore):
+    """Given a patch (e.g. patchstore object) return a memfilectx
+
+    This is a convenience method for building a memctx based on a patchstore.
+    """
+    def getfilectx(repo, memctx, path):
+        data, mode, copied = patchstore.getfile(path)
+        if data is None:
+            return None
+        islink, isexec = mode
+        return memfilectx(repo, path, data, islink=islink,
+                          isexec=isexec, copied=copied,
+                          memctx=memctx)
+
+    return getfilectx
+
 class memctx(committablectx):
     """Use memctx to perform in-memory commits via localrepo.commitctx().