# HG changeset patch # User Sean Farley # Date 1497040753 25200 # Node ID ec302748edd88f989f59021b813eb52a97e83713 # Parent 34be21aa2b26c251bd5bcb2fdb23eb9a57c04495 context: add convenience method for returning a memfilectx from a patch This is mostly a copy of what makememctx does but refactored to make it behave more like our other convenience methods. diff -r 34be21aa2b26 -r ec302748edd8 mercurial/context.py --- 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().