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.
This commit is contained in:
Sean Farley 2017-06-09 13:39:13 -07:00
parent 90b054fc18
commit e67eb8ee09

View File

@ -2060,6 +2060,22 @@ def memfilefromctx(ctx):
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().