comparison mercurial/context.py @ 32784: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
comparison
equal deleted inserted replaced
32783:34be21aa2b26 32784:ec302748edd8
2058 islink=fctx.islink(), isexec=fctx.isexec(), 2058 islink=fctx.islink(), isexec=fctx.isexec(),
2059 copied=copied, memctx=memctx) 2059 copied=copied, memctx=memctx)
2060 2060
2061 return getfilectx 2061 return getfilectx
2062 2062
2063 def memfilefrompatch(patchstore):
2064 """Given a patch (e.g. patchstore object) return a memfilectx
2065
2066 This is a convenience method for building a memctx based on a patchstore.
2067 """
2068 def getfilectx(repo, memctx, path):
2069 data, mode, copied = patchstore.getfile(path)
2070 if data is None:
2071 return None
2072 islink, isexec = mode
2073 return memfilectx(repo, path, data, islink=islink,
2074 isexec=isexec, copied=copied,
2075 memctx=memctx)
2076
2077 return getfilectx
2078
2063 class memctx(committablectx): 2079 class memctx(committablectx):
2064 """Use memctx to perform in-memory commits via localrepo.commitctx(). 2080 """Use memctx to perform in-memory commits via localrepo.commitctx().
2065 2081
2066 Revision information is supplied at initialization time while 2082 Revision information is supplied at initialization time while
2067 related files data and is made available through a callback 2083 related files data and is made available through a callback