Mercurial > hg > mercurial-source
changeset 33547:ec302748edd8
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.
author | Sean Farley <sean@farley.io> |
---|---|
date | Fri, 09 Jun 2017 13:39:13 -0700 |
parents | 34be21aa2b26 |
children | 041d976b662a |
files | mercurial/context.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/context.py +++ b/mercurial/context.py @@ -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().