Mercurial > hg-stable
changeset 32783:34be21aa2b26
memctx: refactor inline getfilectx into convenience method
No actual logic is changing, just moving code so __init__ is easier to
read.
author | Sean Farley <sean@farley.io> |
---|---|
date | Fri, 09 Jun 2017 13:25:02 -0700 |
parents | 2d93d2159e30 |
children | ec302748edd8 |
files | mercurial/context.py |
diffstat | 1 files changed, 20 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/context.py Fri Jun 09 13:55:51 2017 -0700 +++ b/mercurial/context.py Fri Jun 09 13:25:02 2017 -0700 @@ -2041,6 +2041,25 @@ return getfilectx +def memfilefromctx(ctx): + """Given a context return a memfilectx for ctx[path] + + This is a convenience method for building a memctx based on another + context. + """ + def getfilectx(repo, memctx, path): + fctx = ctx[path] + # this is weird but apparently we only keep track of one parent + # (why not only store that instead of a tuple?) + copied = fctx.renamed() + if copied: + copied = copied[0] + return memfilectx(repo, path, fctx.data(), + islink=fctx.islink(), isexec=fctx.isexec(), + copied=copied, memctx=memctx) + + return getfilectx + class memctx(committablectx): """Use memctx to perform in-memory commits via localrepo.commitctx(). @@ -2088,17 +2107,7 @@ # if store is not callable, wrap it in a function if not callable(filectxfn): - def getfilectx(repo, memctx, path): - fctx = filectxfn[path] - # this is weird but apparently we only keep track of one parent - # (why not only store that instead of a tuple?) - copied = fctx.renamed() - if copied: - copied = copied[0] - return memfilectx(repo, path, fctx.data(), - islink=fctx.islink(), isexec=fctx.isexec(), - copied=copied, memctx=memctx) - self._filectxfn = getfilectx + self._filectxfn = memfilefromctx(filectxfn) else: # memoizing increases performance for e.g. vcs convert scenarios. self._filectxfn = makecachingfilectxfn(filectxfn)