# HG changeset patch # User Sean Farley # Date 2017-06-09 20:25:02 # Node ID 34be21aa2b26c251bd5bcb2fdb23eb9a57c04495 # Parent 2d93d2159e30e0a19fb23e13d0120e56dda5e8fb memctx: refactor inline getfilectx into convenience method No actual logic is changing, just moving code so __init__ is easier to read. diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -2041,6 +2041,25 @@ def makecachingfilectxfn(func): 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 @@ class memctx(committablectx): # 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)